From 817e502ff5d3bb74f890a896ec017b091dcc7efd Mon Sep 17 00:00:00 2001 From: Steve Huston Date: Tue, 18 Dec 2001 23:48:05 +0000 Subject: ChangeLogTag:Tue Dec 18 17:47:44 2001 Steve Huston --- tests/INET_Addr_Test.cpp | 128 ++++++++++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 47 deletions(-) (limited to 'tests/INET_Addr_Test.cpp') diff --git a/tests/INET_Addr_Test.cpp b/tests/INET_Addr_Test.cpp index b2e248ab038..587d3a01a5b 100644 --- a/tests/INET_Addr_Test.cpp +++ b/tests/INET_Addr_Test.cpp @@ -18,13 +18,17 @@ // // ============================================================================ -#include +#include "ace/OS.h" #include "ace/INET_Addr.h" +#include "ace/Log_Msg.h" -int main(int argc, char *argv[]) + +int main (int argc, char *argv[]) { - ACE_UNUSED_ARG(argc); - ACE_UNUSED_ARG(argv); + ACE_UNUSED_ARG (argc); + ACE_UNUSED_ARG (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 @@ -32,62 +36,92 @@ int main(int argc, char *argv[]) ACE_INET_Addr addr; - for(int i=0; ipv4_addresses[i] != 0; i++) { + for (int i=0; ipv4_addresses[i] != 0; i++) { struct in_addr addrv4; ACE_UINT32 addr32; - ACE_OS::inet_pton(AF_INET,ipv4_addresses[i],(void*)&addrv4); - - memcpy((void*)&addr32,(void*)&addrv4,sizeof(addr32)); - - addr.set(80,ipv4_addresses[i]); - - /* Now check to make sure get_ip_address matches and get_host_addr - matches. */ - - if(addr.get_ip_address() != htonl(addr32)) { - printf("Error: Address %s failed get_ip_address() check\n",ipv4_addresses[i]); - printf("0x%x != 0x%x\n",addr.get_ip_address(), addr32); - } - if(0 != ACE_OS::strcmp(addr.get_host_addr(),ipv4_addresses[i])) { - printf("Error: Address %s failed get_host_addr() check\n",ipv4_addresses[i]); - printf("%s != %s\n",addr.get_host_addr(),ipv4_addresses[i]); - } + ACE_OS::inet_pton (AF_INET, ipv4_addresses[i], &addrv4); + + ACE_OS::memcpy (&addr32, &addrv4, sizeof (addr32)); + + addr.set (80, ipv4_addresses[i]); + + /* + ** Now check to make sure get_ip_address matches and get_host_addr + ** matches. + */ + if (addr.get_ip_address () != ACE_HTONL (addr32)) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Error: %s failed get_ip_address() check\n") + ACE_TEXT ("0x%x != 0x%x\n"), + ipv4_addresses[i], + addr.get_ip_address (), + addr32)); + status = 1; + } + + if (0 != ACE_OS::strcmp (addr.get_host_addr(), ipv4_addresses[i])) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%s failed get_host_addr() check\n") + ACE_TEXT ("%s != %s\n"), + ipv4_addresses[i], + addr.get_host_addr (), + ipv4_addresses[i])); + status = 1; + } // Clear out the address by setting it to 1 and check - addr.set((u_short)0,(ACE_UINT32)1,1); - if(addr.get_ip_address() != 1) { - printf("Error: failed to set address to 1\n"); - } + addr.set (0, ACE_UINT32 (1), 1); + if (addr.get_ip_address () != 1) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Failed to set address to 1\n"))); + status = 1; + } // Now set the address using a 32 bit number and check that we get // the right string out of get_host_addr(). - addr.set(80,addr32,0); // addr32 is already in network byte order - if(0 != ACE_OS::strcmp(addr.get_host_addr(),ipv4_addresses[i])) { - printf("Error: Address %s failed second get_host_addr() check\n",ipv4_addresses[i]); - printf("%s != %s\n",addr.get_host_addr(),ipv4_addresses[i]); - } + addr.set (80, addr32, 0); // addr32 is already in network byte order + if (0 != ACE_OS::strcmp (addr.get_host_addr (), ipv4_addresses[i])) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%s failed second get_host_addr() check\n") + ACE_TEXT ("%s != %s\n"), + ipv4_addresses[i], + addr.get_host_addr (), + ipv4_addresses[i])); + status = 1; + } } #if defined (ACE_HAS_IPV6) - if(ACE_Sock_Connect::ipv6_enabled()) { - char *ipv6_addresses[] = { - "1080::8:800:200c:417a", // unicast address - "ff01::101", // multicast address - "::1", // loopback address - "::", // unspecified addresses - 0 - }; - for(int i=0; ipv6_addresses[i] != 0; i++) { - ACE_INET_Addr addr(80,ipv6_addresses[i]); - - if(0 != ACE_OS::strcmp(addr.get_host_addr(),ipv6_addresses[i])) { - printf("IPv6 get_host_addr failed: %s != %s\n",addr.get_host_addr(),ipv6_addresses[i]); + if (ACE_Sock_Connect::ipv6_enabled ()) + { + const char *ipv6_addresses[] = { + "1080::8:800:200c:417a", // unicast address + "ff01::101", // multicast address + "::1", // loopback address + "::", // unspecified addresses + 0 + }; + + for (int i=0; ipv6_addresses[i] != 0; i++) + { + ACE_INET_Addr addr (80, ipv6_addresses[i]); + + if (0 != ACE_OS::strcmp (addr.get_host_addr (), ipv6_addresses[i])) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("IPv6 get_host_addr failed: %s != %s\n"), + addr.get_host_addr (), + ipv6_addresses[i])); + status = 1; + } + } } - } - } #endif - return 0; + return status; } -- cgit v1.2.1