summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-28 17:08:44 +0100
committerAndreas Baumann <abaumann@yahoo.com>2009-03-28 17:08:44 +0100
commitc0a5133d89a1eb83d8754a760306ade6022b57dc (patch)
treeb71a6ac13eb1e802704b81bc96e61e5b57681687 /tests
parent7373b4bf797355d67651e0d4ecc59c7cf5a433f3 (diff)
downloadwolfbones-c0a5133d89a1eb83d8754a760306ade6022b57dc.tar.gz
wolfbones-c0a5133d89a1eb83d8754a760306ade6022b57dc.tar.bz2
added simple wikipedia test for getaddrinfo/getnameinfo
Diffstat (limited to 'tests')
-rw-r--r--tests/port/test_getaddrinfo.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/tests/port/test_getaddrinfo.c b/tests/port/test_getaddrinfo.c
index 66dc639..f7abfc0 100644
--- a/tests/port/test_getaddrinfo.c
+++ b/tests/port/test_getaddrinfo.c
@@ -4,11 +4,36 @@
#include "port/netdb.c" /* for getaddrinfo */
#include <stdlib.h> /* for exit, EXIT_SUCCESS, free */
+#include <stdio.h>
int main( void ) {
- wolf_port_getaddrinfo( );
-
- if( 0 ) return EXIT_FAILURE;
+ struct addrinfo *result;
+ struct addrinfo *res;
+ int error;
+
+ /* resolve the domain name into a list of addresses */
+ error = getaddrinfo( "www.andreasbaumann.cc", NULL, NULL, &result );
+ if( error != 0 ) {
+ fprintf( stderr, "getaddrinfo failed: %s (%d)\n",
+ gai_strerror( error ), error );
+ return EXIT_FAILURE;
+ }
+
+ /* loop over all returned results and do inverse lookup */
+ for( res = result; res != NULL; res = res->ai_next ) {
+ char hostname[NI_MAXHOST] = "";
+
+ error = getnameinfo( res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0 );
+ if( error != 0 ) {
+ fprintf( stderr, "getnameinfo failed: %s (%d)\n",
+ gai_strerror( error ), error );
+ return EXIT_FAILURE;
+ }
+ printf( "hostname: %s\n", hostname );
+ }
+
+ freeaddrinfo( result );
+
return EXIT_SUCCESS;
}