]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9594: Fixed hostname resolving for IPv6 addreses.
authorSergey Safarov <s.safarov@gmail.com>
Fri, 7 Oct 2016 09:38:35 +0000 (05:38 -0400)
committerSergey Safarov <s.safarov@gmail.com>
Sat, 8 Oct 2016 14:27:48 +0000 (10:27 -0400)
aa

src/mod/event_handlers/mod_kazoo/kazoo_utils.c
src/mod/event_handlers/mod_kazoo/mod_kazoo.h

index 962e87f6f1c980a46a3d4879c2f8e40e579052c4..5f6e4bf78c5afbf4e426246f4a15d747e243eb01 100644 (file)
@@ -157,6 +157,8 @@ switch_socket_t *create_socket_with_port(switch_memory_pool_t *pool, switch_port
                return NULL;
        }
 
+       switch_getnameinfo(&globals.hostname, sa, 0);
+
        //      if (globals.nat_map && switch_nat_get_type()) {
        //              switch_nat_add_mapping(port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE);
        //      }
@@ -170,7 +172,6 @@ switch_socket_t *create_socket(switch_memory_pool_t *pool) {
 }
 
 switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei_cnode_s *ei_cnode) {
-    struct hostent *nodehost;
     char hostname[EI_MAXHOSTNAMELEN + 1] = "";
     char nodename[MAXNODELEN + 1];
     char cnodename[EI_MAXALIVELEN + 1];
@@ -186,12 +187,10 @@ switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei
         /* truncate the alivename at the @ */
         *atsign = '\0';
     } else {
-        if ((nodehost = gethostbyaddr(ip_addr, sizeof (ip_addr), AF_INET))) {
-            memcpy(hostname, nodehost->h_name, EI_MAXHOSTNAMELEN);
-        }
-
-        if (zstr_buf(hostname) || !strncasecmp(globals.ip, "0.0.0.0", 7)) {
-            gethostname(hostname, EI_MAXHOSTNAMELEN);
+        if (zstr(globals.hostname) || !strncasecmp(globals.ip, "0.0.0.0", 7) || !strncasecmp(globals.ip, "::", 2)) {
+            memcpy(hostname, switch_core_get_hostname(), EI_MAXHOSTNAMELEN);
+        } else {
+            memcpy(hostname, globals.hostname, EI_MAXHOSTNAMELEN);
         }
 
         snprintf(nodename, MAXNODELEN + 1, "%s@%s", globals.ei_nodename, hostname);
index a1e105ccc960a4402a3e18cb4dcac188ec537974..e2a23134ba95a771509fe272c984b0b5d00cafbc 100644 (file)
@@ -103,6 +103,7 @@ struct globals_s {
        switch_bool_t ei_shortname;
        int ei_compat_rel;
        char *ip;
+       char *hostname;
        char *ei_cookie;
        char *ei_nodename;
        char *kazoo_var_prefix;