diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-29 11:14:51 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-29 11:14:51 +0200 |
commit | 74a0d59fe3cddd3cfb94aacb3863ed3a02aa0153 (patch) | |
tree | 2df4a110f1c50439c5429074656f3d899c4dc77b /tests | |
parent | a06ccccc63df831f4a7bdf38a0000ba36edbcb15 (diff) | |
download | wolfbones-74a0d59fe3cddd3cfb94aacb3863ed3a02aa0153.tar.gz wolfbones-74a0d59fe3cddd3cfb94aacb3863ed3a02aa0153.tar.bz2 |
corrected inet_ntop usage
Diffstat (limited to 'tests')
-rw-r--r-- | tests/port/test_getaddrinfo.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/port/test_getaddrinfo.c b/tests/port/test_getaddrinfo.c index 5226b20..1608ee0 100644 --- a/tests/port/test_getaddrinfo.c +++ b/tests/port/test_getaddrinfo.c @@ -23,7 +23,7 @@ int main( void ) { /* resolve the domain name into a list of addresses */ itoa( 80, port_or_service, 10 ); - error = getaddrinfo( "www.andreasbaumann.cc", port_or_service, &hints, &result ); + error = getaddrinfo( "localhost", port_or_service, &hints, &result ); if( error != 0 ) { fprintf( stderr, "getaddrinfo failed: %s (%d)\n", gai_strerror( error ), error ); @@ -33,9 +33,21 @@ int main( void ) { /* loop over all returned results and do inverse lookup */ for( res = result; res != NULL; res = res->ai_next ) { char s[100]; + const struct sockaddr_in *addr_ipv4; + const struct sockaddr_in6 *addr_ipv6; memset( s, 0, 100 ); - inet_ntop( res->ai_family, &res->ai_addr, s, 100 ); + switch( res->ai_family ) { + case AF_INET: + addr_ipv4 = (const struct sockaddr_in *)res->ai_addr; + inet_ntop( res->ai_family, &addr_ipv4->sin_addr, s, 100 ); + break; + + case AF_INET6: + addr_ipv6 = (const struct sockaddr_in6 *)res->ai_addr; + inet_ntop( res->ai_family, &addr_ipv6->sin6_addr, s, 100 ); + break; + } printf( "%d %d %s\n", res->ai_family, res->ai_socktype, s ); } |