diff options
Diffstat (limited to 'ACE/tests/INET_Addr_Test.cpp')
-rw-r--r-- | ACE/tests/INET_Addr_Test.cpp | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/ACE/tests/INET_Addr_Test.cpp b/ACE/tests/INET_Addr_Test.cpp index 5a25bd54fba..4f1e27bad96 100644 --- a/ACE/tests/INET_Addr_Test.cpp +++ b/ACE/tests/INET_Addr_Test.cpp @@ -55,6 +55,10 @@ int check_type_consistency (const ACE_INET_Addr &addr) return 0; } +struct Address { + const char* name; + bool loopback; +}; int run_main (int argc, ACE_TCHAR *argv[]) { @@ -66,9 +70,9 @@ int run_main (int argc, ACE_TCHAR *argv[]) int status = 0; // Innocent until proven guilty const char *ipv4_addresses[] = - { - "127.0.0.1", "138.38.180.251", "64.219.54.121", "192.0.0.1", "10.0.0.1", 0 - }; + { + "127.0.0.1", "138.38.180.251", "64.219.54.121", "192.0.0.1", "10.0.0.1", 0 + }; ACE_INET_Addr addr; status |= check_type_consistency (addr); @@ -101,7 +105,8 @@ int run_main (int argc, ACE_TCHAR *argv[]) status = 1; } - if (0 != ACE_OS::strcmp (addr.get_host_addr(), ipv4_addresses[i])) + if (addr.get_host_addr () != 0 && + ACE_OS::strcmp (addr.get_host_addr(), ipv4_addresses[i]) != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%s failed get_host_addr() check\n") @@ -114,7 +119,8 @@ int run_main (int argc, ACE_TCHAR *argv[]) // Now we check the operation of get_host_addr(char*,int) const char* haddr = addr.get_host_addr (&hostaddr[0], sizeof(hostaddr)); - if (0 != ACE_OS::strcmp (&hostaddr[0], haddr)) + if (haddr != 0 && + ACE_OS::strcmp (&hostaddr[0], haddr) != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%s failed get_host_addr(char* buf,int) check\n") @@ -124,7 +130,7 @@ int run_main (int argc, ACE_TCHAR *argv[]) haddr)); status = 1; } - if (0 != ACE_OS::strcmp (&hostaddr[0], ipv4_addresses[i])) + if (ACE_OS::strcmp (&hostaddr[0], ipv4_addresses[i]) != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%s failed get_host_addr(char*,int) check\n") @@ -149,7 +155,8 @@ int run_main (int argc, ACE_TCHAR *argv[]) addr.set (80, addr32, 0); // addr32 is already in network byte order status |= check_type_consistency(addr); - if (0 != ACE_OS::strcmp (addr.get_host_addr (), ipv4_addresses[i])) + if (addr.get_host_addr () != 0 && + ACE_OS::strcmp (addr.get_host_addr (), ipv4_addresses[i]) != 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%s failed second get_host_addr() check\n") @@ -217,6 +224,33 @@ int run_main (int argc, ACE_TCHAR *argv[]) #endif + struct Address loopback_addresses[] = + { {"127.0.0.1", true}, {"127.1.2.3", true} + , {"127.0.0.0", true}, {"127.255.255.255", true} + , {"126.255.255.255", false}, {"128.0.0.0", false}, {0, true} + }; + + for (int i=0; loopback_addresses[i].name != 0; i++) + { + struct in_addr addrv4; + ACE_UINT32 addr32 = 0; + + ACE_OS::inet_pton (AF_INET, loopback_addresses[i].name, &addrv4); + + ACE_OS::memcpy (&addr32, &addrv4, sizeof (addr32)); + + addr.set (80, loopback_addresses[i].name); + + if (addr.is_loopback() != loopback_addresses[i].loopback) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("ACE_INET_Addr::is_loopback() ") + ACE_TEXT ("failed to distinguish loopback address. %s\n") + , loopback_addresses[i].name)); + status = 1; + } + } + ACE_END_TEST; return status; |