Fix log entry in last change.
[glibc.git] / inet / tst-gethnm.c
blob8af44d66a1b6c1b048fbdd0301902b0006052d26
1 /* Based on a test case by grd@algonet.se. */
3 #include <netdb.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/param.h>
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <arpa/inet.h>
13 int
14 main (void)
16 struct hostent *ent;
17 struct in_addr hostaddr;
18 int result = 0;
20 inet_aton ("127.0.0.1", (struct in_addr *) &hostaddr.s_addr);
21 ent = gethostbyaddr (&hostaddr, sizeof (hostaddr), AF_INET);
22 if (ent == NULL)
23 puts ("gethostbyaddr (...) == NULL");
24 else
26 puts ("Using gethostbyaddr(..):");
27 printf ("h_name: %s\n", ent->h_name);
29 if (ent->h_aliases == NULL)
30 puts ("ent->h_aliases == NULL");
31 else
32 printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
35 ent = gethostbyname ("127.0.0.1");
36 if (ent == NULL)
38 puts ("gethostbyname (\"127.0.0.1\") == NULL");
39 result = 1;
41 else
43 printf ("\nNow using gethostbyname(..):\n");
44 printf ("h_name: %s\n", ent->h_name);
45 if (strcmp (ent->h_name, "127.0.0.1") != 0)
47 puts ("ent->h_name != \"127.0.0.1\"");
48 result = 1;
51 if (ent->h_aliases == NULL)
53 puts ("ent->h_aliases == NULL");
54 result = 1;
56 else
58 printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
59 result |= ent->h_aliases[0] != NULL;
63 return result;