* pthreadP.h (PTHREAD_RWLOCK_PREFER_READER_P): Define.
[glibc/pb-stable.git] / resolv / tst-inet_ntop.c
bloba042c74c912d628c9b625a8937491562b554d55b
1 #include <arpa/inet.h>
2 #include <errno.h>
3 #include <netinet/in.h>
4 #include <stdio.h>
5 #include <string.h>
7 int
8 main (void)
10 struct in_addr addr4;
11 struct in6_addr addr6;
12 char buf[64];
13 int result = 0;
15 addr4.s_addr = 0xe0e0e0e0;
16 addr6.s6_addr16[0] = 0;
17 addr6.s6_addr16[1] = 0;
18 addr6.s6_addr16[2] = 0;
19 addr6.s6_addr16[3] = 0;
20 addr6.s6_addr16[4] = 0;
21 addr6.s6_addr16[5] = 0xffff;
22 addr6.s6_addr32[3] = 0xe0e0e0e0;
23 memset (buf, 'x', sizeof buf);
25 if (inet_ntop (AF_INET, &addr4, buf, 15) != NULL)
27 puts ("1st inet_ntop returned non-NULL");
28 result++;
30 else if (errno != ENOSPC)
32 puts ("1st inet_ntop didn't fail with ENOSPC");
33 result++;
35 if (buf[15] != 'x')
37 puts ("1st inet_ntop wrote past the end of buffer");
38 result++;
41 if (inet_ntop (AF_INET, &addr4, buf, 16) != buf)
43 puts ("2nd inet_ntop did not return buf");
44 result++;
46 if (memcmp (buf, "224.224.224.224\0" "xxxxxxxx", 24) != 0)
48 puts ("2nd inet_ntop wrote past the end of buffer");
49 result++;
52 if (inet_ntop (AF_INET6, &addr6, buf, 22) != NULL)
54 puts ("3rd inet_ntop returned non-NULL");
55 result++;
57 else if (errno != ENOSPC)
59 puts ("3rd inet_ntop didn't fail with ENOSPC");
60 result++;
62 if (buf[22] != 'x')
64 puts ("3rd inet_ntop wrote past the end of buffer");
65 result++;
68 if (inet_ntop (AF_INET6, &addr6, buf, 23) != buf)
70 puts ("4th inet_ntop did not return buf");
71 result++;
73 if (memcmp (buf, "::ffff:224.224.224.224\0" "xxxxxxxx", 31) != 0)
75 puts ("4th inet_ntop wrote past the end of buffer");
76 result++;
79 memset (&addr6.s6_addr, 0xe0, sizeof (addr6.s6_addr));
81 if (inet_ntop (AF_INET6, &addr6, buf, 39) != NULL)
83 puts ("5th inet_ntop returned non-NULL");
84 result++;
86 else if (errno != ENOSPC)
88 puts ("5th inet_ntop didn't fail with ENOSPC");
89 result++;
91 if (buf[39] != 'x')
93 puts ("5th inet_ntop wrote past the end of buffer");
94 result++;
97 if (inet_ntop (AF_INET6, &addr6, buf, 40) != buf)
99 puts ("6th inet_ntop did not return buf");
100 result++;
102 if (memcmp (buf, "e0e0:e0e0:e0e0:e0e0:e0e0:e0e0:e0e0:e0e0\0"
103 "xxxxxxxx", 48) != 0)
105 puts ("6th inet_ntop wrote past the end of buffer");
106 result++;
110 return result;