3 #include <netinet/in.h>
11 struct in6_addr addr6
;
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");
30 else if (errno
!= ENOSPC
)
32 puts ("1st inet_ntop didn't fail with ENOSPC");
37 puts ("1st inet_ntop wrote past the end of buffer");
41 if (inet_ntop (AF_INET
, &addr4
, buf
, 16) != buf
)
43 puts ("2nd inet_ntop did not return buf");
46 if (memcmp (buf
, "224.224.224.224\0" "xxxxxxxx", 24) != 0)
48 puts ("2nd inet_ntop wrote past the end of buffer");
52 if (inet_ntop (AF_INET6
, &addr6
, buf
, 22) != NULL
)
54 puts ("3rd inet_ntop returned non-NULL");
57 else if (errno
!= ENOSPC
)
59 puts ("3rd inet_ntop didn't fail with ENOSPC");
64 puts ("3rd inet_ntop wrote past the end of buffer");
68 if (inet_ntop (AF_INET6
, &addr6
, buf
, 23) != buf
)
70 puts ("4th inet_ntop did not return buf");
73 if (memcmp (buf
, "::ffff:224.224.224.224\0" "xxxxxxxx", 31) != 0)
75 puts ("4th inet_ntop wrote past the end of buffer");
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");
86 else if (errno
!= ENOSPC
)
88 puts ("5th inet_ntop didn't fail with ENOSPC");
93 puts ("5th inet_ntop wrote past the end of buffer");
97 if (inet_ntop (AF_INET6
, &addr6
, buf
, 40) != buf
)
99 puts ("6th inet_ntop did not return buf");
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");