1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
int
main (void)
{
struct in_addr addr4;
struct in6_addr addr6;
char buf[64];
int result = 0;
addr4.s_addr = 0xe0e0e0e0;
addr6.s6_addr16[0] = 0;
addr6.s6_addr16[1] = 0;
addr6.s6_addr16[2] = 0;
addr6.s6_addr16[3] = 0;
addr6.s6_addr16[4] = 0;
addr6.s6_addr16[5] = 0xffff;
addr6.s6_addr32[3] = 0xe0e0e0e0;
memset (buf, 'x', sizeof buf);
if (inet_ntop (AF_INET, &addr4, buf, 15) != NULL)
{
puts ("1st inet_ntop returned non-NULL");
result++;
}
else if (errno != ENOSPC)
{
puts ("1st inet_ntop didn't fail with ENOSPC");
result++;
}
if (buf[15] != 'x')
{
puts ("1st inet_ntop wrote past the end of buffer");
result++;
}
if (inet_ntop (AF_INET, &addr4, buf, 16) != buf)
{
puts ("2nd inet_ntop did not return buf");
result++;
}
if (memcmp (buf, "224.224.224.224\0" "xxxxxxxx", 24) != 0)
{
puts ("2nd inet_ntop wrote past the end of buffer");
result++;
}
if (inet_ntop (AF_INET6, &addr6, buf, 22) != NULL)
{
puts ("3rd inet_ntop returned non-NULL");
result++;
}
else if (errno != ENOSPC)
{
puts ("3rd inet_ntop didn't fail with ENOSPC");
result++;
}
if (buf[22] != 'x')
{
puts ("3rd inet_ntop wrote past the end of buffer");
result++;
}
if (inet_ntop (AF_INET6, &addr6, buf, 23) != buf)
{
puts ("4th inet_ntop did not return buf");
result++;
}
if (memcmp (buf, "::ffff:224.224.224.224\0" "xxxxxxxx", 31) != 0)
{
puts ("4th inet_ntop wrote past the end of buffer");
result++;
}
memset (&addr6.s6_addr, 0xe0, sizeof (addr6.s6_addr));
if (inet_ntop (AF_INET6, &addr6, buf, 39) != NULL)
{
puts ("5th inet_ntop returned non-NULL");
result++;
}
else if (errno != ENOSPC)
{
puts ("5th inet_ntop didn't fail with ENOSPC");
result++;
}
if (buf[39] != 'x')
{
puts ("5th inet_ntop wrote past the end of buffer");
result++;
}
if (inet_ntop (AF_INET6, &addr6, buf, 40) != buf)
{
puts ("6th inet_ntop did not return buf");
result++;
}
if (memcmp (buf, "e0e0:e0e0:e0e0:e0e0:e0e0:e0e0:e0e0:e0e0\0"
"xxxxxxxx", 48) != 0)
{
puts ("6th inet_ntop wrote past the end of buffer");
result++;
}
return result;
}
|