25 unsigned int temp, temp0;
26 unsigned int compressing;
27 unsigned int compressed;
34 for (j = 0; j < 16; j += 2) {
40 temp = ((
unsigned long) (
unsigned char) ip[j] << 8) +
41 (
unsigned long) (
unsigned char) ip[j+1];
44 if (!compressing && j < 16)
45 temp0 = ((
unsigned long) (
unsigned char) ip[j+2] << 8) +
46 (
unsigned long) (
unsigned char) ip[j+3];
48 if (temp == 0 && temp0 == 0 && !compressed) {
72 if (compressing) { *s++ =
':'; ++len; }
87 for (i = 0; i < 16; i++) {
88 *s++ =
tohex((
unsigned char)ip[i] >> 4);
89 *s++ =
tohex((
unsigned char)ip[i] & 15);
108 static char data[] =
"0123456789abcdef";
111 for (j = 15; j >= 0; j--) {
112 i =
fmt_str(s,&data[ip[j] & 0x0f]); len += i;
if (s) s += i;
113 i =
fmt_str(s,
"."); len += i;
if (s) s += i;
114 i =
fmt_str(s,&data[ip[j] >> 4 & 0x0f]); len += i;
if (s) s += i;
115 i =
fmt_str(s,
"."); len += i;
if (s) s += i;
117 i =
fmt_str(s,
"ip6.arpa."); len += i;
if (s) s += i;
133 for (i = 0; i < 16; i++) {
135 if (tmp < 0)
return 0;
138 if (tmp < 0)
return 0;
154 unsigned int len = 0;
163 for (len = 0; len < 12; ++len)
185 if (prefixlen == 12 && s[i] ==
'.') {
194 ip[prefixlen++] = (u >> 8);
195 ip[prefixlen++] = (u & 255);
197 if (prefixlen == 16)
return len;
203 if (suffixlen == 0)
break;
206 }
else if (suffixlen != 0)
break;
214 if (suffixlen + prefixlen <= 12 && s[i] ==
'.') {
221 prefixlen = 12 - suffixlen;
224 suffix[suffixlen++] = (u >> 8);
225 suffix[suffixlen++] = (u & 255);
227 if (prefixlen + suffixlen == 16)
break;
230 for (i = 0; i < suffixlen; i++)
231 ip[16 - suffixlen + i] = suffix[i];
247 if (*s !=
'[')
return 0;
250 if (s[len + 1] !=
']')
return 0;
270 if ((i =
str_chr(s+j+1,
' '))) k = i;
271 else if ((i =
str_chr(s+j+1,
'\n'))) k = i;
272 else if ((i =
str_chr(s+j+1,
'\t'))) k = i;
273 if (k) s[j+k+1] =
'\0';
290unsigned int ip6_cidr(
char *s,
char ip[16],
unsigned long *plen)
300 return ip6_scan((
const char *)s,ip);
313 unsigned char lowbyte, highbyte;
318 for (i = 0; i < 16; i++) {
319 lowbyte = (
unsigned char) (ip[i]) & 0x0f;
320 highbyte = (
unsigned char) (ip[i] >> 4) & 0x0f;
322 for (j = 3; j >= 0; j--) {
323 if (highbyte & (1 << j)) {
331 if (!prefix)
goto DONE;
333 for (j = 3; j >= 0; j--) {
334 if (lowbyte & (1 << j)) {
342 if (!prefix)
goto DONE;
const unsigned char V4localnet[4]
const unsigned char V4mappedprefix[12]
const unsigned char V6localnet[16]
unsigned int ip6_fmt_flat(char *s, char ip[16])
ip6_fmt_flat convert IPv6 address to IPv6 address string
unsigned int ia6_fmt(char *s, char ip[16])
ia6_fmt convert IPv6 address to inverse DNS nibble format 1.2.3.4.5.6.7.8.9.a.b.c....
unsigned int ip6_cidr(char *s, char ip[16], unsigned long *plen)
ip6_cidr parse compactified IPv6 address string concatinated with the prefix length: fe80::1/64
unsigned int ip6_scan_flat(const char *s, char ip[16])
ip6_scan_flat convert IPv6 address string to IPv6 address array
unsigned int ip6_fmt(char *s, char ip[16])
ip6_fmt convert IPv6 address to compactified IPv6 address string
unsigned int ip6_ifscan(char *s, char ip[16], stralloc *ifname)
ip6_ifscan parse compactified IPv6 address string concatinated with the interface name: fe80::1eth0
unsigned int ip6_scanbracket(const char *s, char ip[16])
ip6_scanbracket parse IPv6 string address enclosed in brackets
unsigned int ip6_bytestring(stralloc *ipstring, char ip[16], int prefix)
ip6_bytestring parse IPv6 address and represent as char string with length prefix
unsigned int ip6_scan(const char *s, char ip[16])
ip6_scan parse compactified IPv6 address string and convert to IPv6 address array
unsigned int ip4_fmt(char *, char[4])
ip4_fmt converts IPv4 address to dotted decimal string format
#define ip6_isv4mapped(ip)
unsigned int ip4_scan(const char *, char[4])
ip4_scan parse IPv4 address string and convert to IP address array
unsigned int scan_xlong(const char *, unsigned long *)
unsigned int scan_ulong(const char *, unsigned long *)
conversion function declarations
unsigned int fmt_xlong(char *, unsigned long)
unsigned int fmt_str(char *, const char *)
int fromhex(unsigned char)
void byte_copy(void *, unsigned int, const void *)
#define byte_equal(s, n, t)
void byte_zero(void *, unsigned int)
unsigned int str_chr(const char *, int)
int stralloc_cats(stralloc *, const char *)
int stralloc_readyplus(stralloc *sa, size_t len)
int stralloc_copys(stralloc *, const char *)