initial commit
[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 <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>
12
13 static int
14 do_test (void)
15 {
16 struct hostent *ent;
17 struct in_addr hostaddr;
18 int result = 0;
19
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
25 {
26 puts ("Using gethostbyaddr(..):");
27 printf ("h_name: %s\n", ent->h_name);
28
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]);
33 }
34
35 ent = gethostbyname ("127.0.0.1");
36 if (ent == NULL)
37 {
38 puts ("gethostbyname (\"127.0.0.1\") == NULL");
39 result = 1;
40 }
41 else
42 {
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)
46 {
47 puts ("ent->h_name != \"127.0.0.1\"");
48 result = 1;
49 }
50
51 if (ent->h_aliases == NULL)
52 {
53 puts ("ent->h_aliases == NULL");
54 result = 1;
55 }
56 else
57 {
58 printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
59 result |= ent->h_aliases[0] != NULL;
60 }
61 }
62
63 return result;
64 }
65
66 #define TEST_FUNCTION do_test ()
67 #include "../test-skeleton.c"