summaryrefslogtreecommitdiff
path: root/tests/port
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-29 10:51:26 +0200
committerAndreas Baumann <abaumann@yahoo.com>2009-03-29 10:51:26 +0200
commita06ccccc63df831f4a7bdf38a0000ba36edbcb15 (patch)
treede11ba6b9ee0b2ea01c06e69a083245be43e036c /tests/port
parentc0a5133d89a1eb83d8754a760306ade6022b57dc (diff)
downloadwolfbones-a06ccccc63df831f4a7bdf38a0000ba36edbcb15.tar.gz
wolfbones-a06ccccc63df831f4a7bdf38a0000ba36edbcb15.tar.bz2
added a simple getaddrinfo test
Diffstat (limited to 'tests/port')
-rw-r--r--tests/port/test_getaddrinfo.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/tests/port/test_getaddrinfo.c b/tests/port/test_getaddrinfo.c
index f7abfc0..5226b20 100644
--- a/tests/port/test_getaddrinfo.c
+++ b/tests/port/test_getaddrinfo.c
@@ -1,18 +1,29 @@
#include "port/sys.h"
#define TEST_GETADDRINFO
-#include "port/netdb.c" /* for getaddrinfo */
+#include "port/netdb.c" /* for getaddrinfo, NI_MAXHOST */
-#include <stdlib.h> /* for exit, EXIT_SUCCESS, free */
-#include <stdio.h>
+#include "port/stdlib.h" /* for exit, EXIT_SUCCESS, itoa */
+#include <stdio.h> /* for fprintf */
+#include <string.h> /* for memset */
int main( void ) {
+ struct addrinfo hints;
struct addrinfo *result;
struct addrinfo *res;
int error;
+ char port_or_service[10];
+
+ /* tell getaddrinfo what we want */
+ memset( &hints, 0, sizeof( struct addrinfo ) );
+ hints.ai_flags = AI_PASSIVE;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
/* resolve the domain name into a list of addresses */
- error = getaddrinfo( "www.andreasbaumann.cc", NULL, NULL, &result );
+ itoa( 80, port_or_service, 10 );
+ error = getaddrinfo( "www.andreasbaumann.cc", port_or_service, &hints, &result );
if( error != 0 ) {
fprintf( stderr, "getaddrinfo failed: %s (%d)\n",
gai_strerror( error ), error );
@@ -21,16 +32,12 @@ int main( void ) {
/* 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;
- }
+ char s[100];
+
+ memset( s, 0, 100 );
+ inet_ntop( res->ai_family, &res->ai_addr, s, 100 );
- printf( "hostname: %s\n", hostname );
+ printf( "%d %d %s\n", res->ai_family, res->ai_socktype, s );
}
freeaddrinfo( result );