Back to index

glibc  2.9
tst-ntoa.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <arpa/inet.h>
00004 #include <netinet/in.h>
00005 
00006 
00007 static int
00008 test (unsigned int inaddr, const char *expected)
00009 {
00010   struct in_addr addr;
00011   char *res;
00012   int fail;
00013 
00014   addr.s_addr = htonl (inaddr);
00015   res = inet_ntoa (addr);
00016   fail = strcmp (res, expected);
00017 
00018   printf ("%#010x -> \"%s\" -> %s%s\n", inaddr, res,
00019          fail ? "fail, expected" : "ok", fail ? expected : "");
00020 
00021   return fail;
00022 }
00023 
00024 
00025 int
00026 main (void)
00027 {
00028   int result = 0;
00029 
00030   result |= test (INADDR_LOOPBACK, "127.0.0.1");
00031   result |= test (INADDR_BROADCAST, "255.255.255.255");
00032   result |= test (INADDR_ANY, "0.0.0.0");
00033   result |= test (0xc0060746, "192.6.7.70");
00034 
00035   return result;
00036 }