|
Szabolcs Nagy |
2113a3 |
// zero compression for the last field in an ipv6 address is (probably) allowed
|
|
Szabolcs Nagy |
2113a3 |
// https://tools.ietf.org/html/rfc4291#section-2.2
|
|
Szabolcs Nagy |
2113a3 |
// but further fields shouldnt buffer overflow
|
|
Szabolcs Nagy |
2113a3 |
#include <stdio.h>
|
|
Szabolcs Nagy |
d031c0 |
#include <string.h>
|
|
Szabolcs Nagy |
d031c0 |
#include <arpa/inet.h>
|
|
Szabolcs Nagy |
d031c0 |
#include "test.h"
|
|
Szabolcs Nagy |
d031c0 |
|
|
Szabolcs Nagy |
2113a3 |
static void txt(char *s, unsigned char *buf)
|
|
Szabolcs Nagy |
2113a3 |
{
|
|
Szabolcs Nagy |
2113a3 |
int i;
|
|
Szabolcs Nagy |
2113a3 |
sprintf(s, "%04x", buf[0]<<8 | buf[1]);
|
|
Szabolcs Nagy |
2113a3 |
for (i=1; i<8; i++)
|
|
Szabolcs Nagy |
2113a3 |
sprintf(s+5*i, ":%04x", buf[2*i]<<8 | buf[2*i+1]);
|
|
Szabolcs Nagy |
2113a3 |
}
|
|
Szabolcs Nagy |
2113a3 |
|
|
Szabolcs Nagy |
d031c0 |
int main(void)
|
|
Szabolcs Nagy |
d031c0 |
{
|
|
Szabolcs Nagy |
2113a3 |
char s[50], sw[50];
|
|
Szabolcs Nagy |
d031c0 |
unsigned char buf[16];
|
|
Szabolcs Nagy |
2113a3 |
unsigned char want[16] = {0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,0};
|
|
Szabolcs Nagy |
2113a3 |
char *addr;
|
|
Szabolcs Nagy |
2113a3 |
|
|
Szabolcs Nagy |
2113a3 |
addr = "1:2:3:4:5:6:7::";
|
|
Szabolcs Nagy |
2113a3 |
if (inet_pton(AF_INET6, addr, buf)!=1 || memcmp(buf, want, 16)!=0) {
|
|
Szabolcs Nagy |
2113a3 |
txt(s, buf);
|
|
Szabolcs Nagy |
2113a3 |
txt(sw, want);
|
|
Szabolcs Nagy |
2113a3 |
t_error("inet_pton(%s) returned %s, wanted %s\n",
|
|
Szabolcs Nagy |
2113a3 |
addr, s, sw);
|
|
Szabolcs Nagy |
2113a3 |
}
|
|
Szabolcs Nagy |
d031c0 |
|
|
Szabolcs Nagy |
2113a3 |
addr = "1:2:3:4:5:6:7::9:10:11:12:13:14:15:16:17:18:19:20";
|
|
Szabolcs Nagy |
2113a3 |
if (inet_pton(AF_INET6, addr, buf)!=0) {
|
|
Szabolcs Nagy |
2113a3 |
txt(s, buf);
|
|
Szabolcs Nagy |
2113a3 |
t_error("inet_pton(%s) returned %s, wanted a failure\n",
|
|
Szabolcs Nagy |
2113a3 |
addr, s);
|
|
Szabolcs Nagy |
d031c0 |
}
|
|
Szabolcs Nagy |
d031c0 |
return t_status;
|
|
Szabolcs Nagy |
d031c0 |
}
|