[Pkg-voip-commits] [janus] 17/282: Aligned SIPre plugin to IP utils
Jonas Smedegaard
dr at jones.dk
Wed Dec 20 21:53:24 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/0.2.6-1
in repository janus.
commit f0c374b524c514d175496040bc7017ffebb25333
Author: Lorenzo Miniero <lminiero at gmail.com>
Date: Fri Mar 17 18:05:20 2017 +0100
Aligned SIPre plugin to IP utils
---
plugins/janus_sipre.c | 86 +++++++++++++--------------------------------------
1 file changed, 21 insertions(+), 65 deletions(-)
diff --git a/plugins/janus_sipre.c b/plugins/janus_sipre.c
index 4499def..1125748 100644
--- a/plugins/janus_sipre.c
+++ b/plugins/janus_sipre.c
@@ -67,6 +67,7 @@
#include "../rtcp.h"
#include "../sdp-utils.h"
#include "../utils.h"
+#include "../ip-utils.h"
/* Plugin information */
@@ -170,7 +171,7 @@ static volatile gint initialized = 0, stopping = 0;
static gboolean notify_events = TRUE;
static janus_callbacks *gateway = NULL;
-static char local_ip[INET6_ADDRSTRLEN];
+static char *local_ip = NULL;
static int keepalive_interval = 120;
static gboolean behind_nat = FALSE;
static char *user_agent;
@@ -639,37 +640,6 @@ static void *janus_sipre_watchdog(void *data) {
}
-static void janus_sipre_detect_local_ip(char *buf, size_t buflen) {
- JANUS_LOG(LOG_VERB, "Autodetecting local IP...\n");
-
- struct sockaddr_in addr;
- socklen_t len;
- int fd = socket(AF_INET, SOCK_DGRAM, 0);
- if(fd == -1)
- goto error;
- addr.sin_family = AF_INET;
- addr.sin_port = htons(1);
- inet_pton(AF_INET, "1.2.3.4", &addr.sin_addr.s_addr);
- if(connect(fd, (const struct sockaddr*) &addr, sizeof(addr)) < 0)
- goto error;
- len = sizeof(addr);
- if(getsockname(fd, (struct sockaddr*) &addr, &len) < 0)
- goto error;
- if(getnameinfo((const struct sockaddr*) &addr, sizeof(addr),
- buf, buflen,
- NULL, 0, NI_NUMERICHOST) != 0)
- goto error;
- close(fd);
- return;
-
-error:
- if(fd != -1)
- close(fd);
- JANUS_LOG(LOG_VERB, "Couldn't find any address! using 127.0.0.1 as the local IP... (which is NOT going to work out of your machine)\n");
- g_strlcpy(buf, "127.0.0.1", buflen);
-}
-
-
/* Random string helper (for call-ids) */
static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static void janus_sipre_random_string(int length, char *buffer) {
@@ -701,45 +671,25 @@ int janus_sipre_init(janus_callbacks *callback, const char *config_path) {
g_snprintf(filename, 255, "%s/%s.cfg", config_path, JANUS_SIPRE_PACKAGE);
JANUS_LOG(LOG_VERB, "Configuration file: %s\n", filename);
janus_config *config = janus_config_parse(filename);
- gboolean local_ip_set = FALSE;
if(config != NULL) {
janus_config_print(config);
janus_config_item *item = janus_config_get_item_drilldown(config, "general", "local_ip");
if(item && item->value) {
- int family;
- if(!janus_is_ip_valid(item->value, &family)) {
- JANUS_LOG(LOG_WARN, "Invalid local IP specified: %s, guessing the default...\n", item->value);
+ /* Verify that the address is valid */
+ struct ifaddrs *ifas = NULL;
+ janus_network_address iface;
+ janus_network_address_string_buffer ibuf;
+ if(getifaddrs(&ifas) || ifas == NULL) {
+ JANUS_LOG(LOG_ERR, "Unable to acquire list of network devices/interfaces; some configurations may not work as expected...\n");
} else {
- /* Verify that we can actually bind to that address */
- int fd = socket(family, SOCK_DGRAM, 0);
- if(fd == -1) {
- JANUS_LOG(LOG_WARN, "Error creating test socket, falling back to detecting IP address...\n");
+ if(janus_network_lookup_interface(ifas, item->value, &iface) != 0) {
+ JANUS_LOG(LOG_WARN, "Error setting local IP address to %s, falling back to detecting IP address...\n", item->value);
} else {
- int r;
- struct sockaddr_storage ss;
- socklen_t addrlen;
- memset(&ss, 0, sizeof(ss));
- if(family == AF_INET) {
- struct sockaddr_in *addr4 = (struct sockaddr_in*)&ss;
- addr4->sin_family = AF_INET;
- addr4->sin_port = 0;
- inet_pton(AF_INET, item->value, &(addr4->sin_addr.s_addr));
- addrlen = sizeof(struct sockaddr_in);
- } else {
- struct sockaddr_in6 *addr6 = (struct sockaddr_in6*)&ss;
- addr6->sin6_family = AF_INET6;
- addr6->sin6_port = 0;
- inet_pton(AF_INET6, item->value, &(addr6->sin6_addr.s6_addr));
- addrlen = sizeof(struct sockaddr_in6);
- }
- r = bind(fd, (const struct sockaddr*)&ss, addrlen);
- close(fd);
- if(r < 0) {
- JANUS_LOG(LOG_WARN, "Error setting local IP address to %s, falling back to detecting IP address...\n", item->value);
+ if(janus_network_address_to_string_buffer(&iface, &ibuf) != 0 || janus_network_address_string_buffer_is_null(&ibuf)) {
+ JANUS_LOG(LOG_WARN, "Error getting local IP address from %s, falling back to detecting IP address...\n", item->value);
} else {
- g_strlcpy(local_ip, item->value, sizeof(local_ip));
- local_ip_set = TRUE;
+ local_ip = g_strdup(janus_network_address_string_from_buffer(&ibuf));
}
}
}
@@ -782,8 +732,12 @@ int janus_sipre_init(janus_callbacks *callback, const char *config_path) {
}
config = NULL;
- if(!local_ip_set) {
- janus_sipre_detect_local_ip(local_ip, sizeof(local_ip));
+ if(local_ip == NULL) {
+ local_ip = janus_network_detect_local_ip_as_string(janus_network_query_options_any_ip);
+ if(local_ip == NULL) {
+ JANUS_LOG(LOG_WARN, "Couldn't find any address! using 127.0.0.1 as the local IP... (which is NOT going to work out of your machine)\n");
+ local_ip = g_strdup("127.0.0.1");
+ }
}
JANUS_LOG(LOG_VERB, "Local IP set to %s\n", local_ip);
@@ -898,6 +852,8 @@ void janus_sipre_destroy(void) {
tmr_debug();
mem_debug();
+ g_free(local_ip);
+
JANUS_LOG(LOG_INFO, "%s destroyed!\n", JANUS_SIPRE_NAME);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git
More information about the Pkg-voip-commits
mailing list