Update.
[platform/upstream/linaro-glibc.git] / inet / tst-gethnm.c
1 /* Based on a test case by grd@algonet.se.  */
2
3 #include <netdb.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <sys/param.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
11
12 int
13 main (void)
14 {
15   struct hostent *ent;
16   struct in_addr hostaddr;
17   int result = 0;
18
19   inet_aton ("127.0.0.1", (struct in_addr *) &hostaddr.s_addr);
20   ent = gethostbyaddr (&hostaddr, sizeof (hostaddr), AF_INET);
21   if (ent == NULL)
22     puts ("gethostbyaddr (...) == NULL");
23   else
24     {
25       puts ("Using gethostbyaddr(..):");
26       printf ("h_name: %s\n", ent->h_name);
27
28       if (ent->h_aliases == NULL)
29         puts ("ent->h_aliases == NULL");
30       else
31         printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
32     }
33
34   ent = gethostbyname ("127.0.0.1");
35   if (ent == NULL)
36     {
37       puts ("gethostbyname (\"127.0.0.1\") == NULL");
38       result = 1;
39     }
40   else
41     {
42       printf ("\nNow using gethostbyname(..):\n");
43       printf ("h_name: %s\n", ent->h_name);
44       if (strcmp (ent->h_name, "127.0.0.1") != 0)
45         {
46           puts ("ent->h_name != \"127.0.0.1\"");
47           result = 1;
48         }
49
50       if (ent->h_aliases == NULL)
51         {
52           puts ("ent->h_aliases == NULL");
53           result = 1;
54         }
55       else
56         {
57           printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
58           result |= ent->h_aliases[0] != NULL;
59         }
60     }
61
62   return result;
63 }