|
Packit |
6c4009 |
#include <arpa/inet.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <netinet/in.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct in_addr addr4;
|
|
Packit |
6c4009 |
struct in6_addr addr6;
|
|
Packit |
6c4009 |
char buf[64];
|
|
Packit |
6c4009 |
int result = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
addr4.s_addr = 0xe0e0e0e0;
|
|
Packit |
6c4009 |
addr6.s6_addr16[0] = 0;
|
|
Packit |
6c4009 |
addr6.s6_addr16[1] = 0;
|
|
Packit |
6c4009 |
addr6.s6_addr16[2] = 0;
|
|
Packit |
6c4009 |
addr6.s6_addr16[3] = 0;
|
|
Packit |
6c4009 |
addr6.s6_addr16[4] = 0;
|
|
Packit |
6c4009 |
addr6.s6_addr16[5] = 0xffff;
|
|
Packit |
6c4009 |
addr6.s6_addr32[3] = 0xe0e0e0e0;
|
|
Packit |
6c4009 |
memset (buf, 'x', sizeof buf);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (inet_ntop (AF_INET, &addr4, buf, 15) != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("1st inet_ntop returned non-NULL");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (errno != ENOSPC)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("1st inet_ntop didn't fail with ENOSPC");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (buf[15] != 'x')
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("1st inet_ntop wrote past the end of buffer");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (inet_ntop (AF_INET, &addr4, buf, 16) != buf)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("2nd inet_ntop did not return buf");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (memcmp (buf, "224.224.224.224\0" "xxxxxxxx", 24) != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("2nd inet_ntop wrote past the end of buffer");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (inet_ntop (AF_INET6, &addr6, buf, 22) != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("3rd inet_ntop returned non-NULL");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (errno != ENOSPC)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("3rd inet_ntop didn't fail with ENOSPC");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (buf[22] != 'x')
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("3rd inet_ntop wrote past the end of buffer");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (inet_ntop (AF_INET6, &addr6, buf, 23) != buf)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("4th inet_ntop did not return buf");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (memcmp (buf, "::ffff:224.224.224.224\0" "xxxxxxxx", 31) != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("4th inet_ntop wrote past the end of buffer");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
memset (&addr6.s6_addr, 0xe0, sizeof (addr6.s6_addr));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (inet_ntop (AF_INET6, &addr6, buf, 39) != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("5th inet_ntop returned non-NULL");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (errno != ENOSPC)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("5th inet_ntop didn't fail with ENOSPC");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (buf[39] != 'x')
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("5th inet_ntop wrote past the end of buffer");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (inet_ntop (AF_INET6, &addr6, buf, 40) != buf)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("6th inet_ntop did not return buf");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (memcmp (buf, "e0e0:e0e0:e0e0:e0e0:e0e0:e0e0:e0e0:e0e0\0"
|
|
Packit |
6c4009 |
"xxxxxxxx", 48) != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("6th inet_ntop wrote past the end of buffer");
|
|
Packit |
6c4009 |
result++;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TEST_FUNCTION do_test ()
|
|
Packit |
6c4009 |
#include "../test-skeleton.c"
|