From 163fadb68e0ac4ce1ade31aae6502377f65e566a Mon Sep 17 00:00:00 2001 From: Steve Huston Date: Fri, 5 Nov 2010 14:22:34 +0000 Subject: ChangeLogTag:Thu Nov 4 15:17:51 UTC 2010 Steve Huston --- ChangeLog | 11 +++++++++++ ace/INET_Addr.cpp | 23 ++++++++++++++++------- tests/INET_Addr_Test.cpp | 25 ++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1ab07c8fcc..82d314e1967 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Thu Nov 4 15:17:51 UTC 2010 Steve Huston + + * ace/INET_Addr.cpp (set): For platforms that have the GNU-extended + gethostbyname2_r() function, use it instead of getaddrinfo() for + a IPv6 hostname lookup. Customer reports that it getaddrinfo() is + hugely slower than gethostbyname2 on large vlans. The alternate + code is used if ACE_HAS_GETHOSTBYNAME2 is set in config.h. + (This is a revised fix from Tue Nov 2 00:18:34 UTC 2010) + + * tests/INET_Addr_Test.cpp: Add some IPv6 address and name lookups. + Tue Nov 2 00:18:34 UTC 2010 Steve Huston * ace/INET_Addr.cpp (set): For platforms that have the GNU-extended diff --git a/ace/INET_Addr.cpp b/ace/INET_Addr.cpp index 54bc4f74dd9..dd1dc25ea75 100644 --- a/ace/INET_Addr.cpp +++ b/ace/INET_Addr.cpp @@ -350,17 +350,26 @@ ACE_INET_Addr::set (u_short port_number, { # if defined (ACE_HAS_GETHOSTBYNAME2) hostent hentry; + hostent *hp; ACE_HOSTENT_DATA buf; int h_error = 0; // Not the same as errno! - hostent *hp = ::gethostbyname2_r (host_name, AF_INET6, &hentry, - buf, &h_error); - if (hp != 0) + if (0 == ::gethostbyname2_r (host_name, AF_INET6, &hentry, + buf, sizeof(buf), &hp, &h_error)) { - this->set_type (hp->h_addrtype); - this->set_addr (hp->h_addr, hp->h_length); - this->set_port_number (port_number, encode); - return 0; + if (hp != 0) + { + struct sockaddr_in6 v6; + ACE_OS::memset (&v6, 0, sizeof (v6)); + v6.sin6_family = AF_INET6; + (void) ACE_OS::memcpy ((void *) &v6.sin6_addr, + hp->h_addr, + hp->h_length); + this->set_type (hp->h_addrtype); + this->set_addr (&v6, hp->h_length); + this->set_port_number (port_number, encode); + return 0; + } } errno = h_error; if (address_family == AF_INET6) diff --git a/tests/INET_Addr_Test.cpp b/tests/INET_Addr_Test.cpp index 36e2e4c27a5..5a31f9314fa 100644 --- a/tests/INET_Addr_Test.cpp +++ b/tests/INET_Addr_Test.cpp @@ -217,8 +217,31 @@ int run_main (int, ACE_TCHAR *[]) status = 1; } } - } + const char *ipv6_names[] = { + "naboo.dre.vanderbilt.edu", + "v6.ipv6-test.com", + 0 + }; + for (int i=0; ipv6_names[i] != 0; i++) + { + ACE_INET_Addr addr (80, ipv6_names[i]); + status |= check_type_consistency (addr); + + if (0 != ACE_OS::strcmp (addr.get_host_name (), ipv6_names[i])) + { + ACE_ERROR ((LM_WARNING, + ACE_TEXT ("IPv6 name mismatch: %s (%s) != %s\n"), + addr.get_host_name (), + addr.get_host_addr (), + ipv6_names[i])); + status = 1; + } + } + } + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("IPv6 tests done\n"))); +#else + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_HAS_IPV6 not set; no IPv6 tests run\n"))); #endif struct Address loopback_addresses[] = -- cgit v1.2.1