29 i =
fmt_ulong(s,(
unsigned long) ip->
d[0]); len +=
i;
if (s) s +=
i;
30 i =
fmt_str(s,
"."); len +=
i;
if (s) s +=
i;
31 i =
fmt_ulong(s,(
unsigned long) ip->
d[1]); len +=
i;
if (s) s +=
i;
32 i =
fmt_str(s,
"."); len +=
i;
if (s) s +=
i;
33 i =
fmt_ulong(s,(
unsigned long) ip->
d[2]); len +=
i;
if (s) s +=
i;
34 i =
fmt_str(s,
"."); len +=
i;
if (s) s +=
i;
35 i =
fmt_ulong(s,(
unsigned long) ip->
d[3]); len +=
i;
if (s) s +=
i;
54 i =
scan_ulong(s,&u);
if (!i)
return 0;
if (u > 255)
return 0; ip->
d[0] =
u; s +=
i; len +=
i;
55 if (*s !=
'.')
return 0; ++s; ++
len;
56 i =
scan_ulong(s,&u);
if (!i)
return 0;
if (u > 255)
return 0; ip->
d[1] =
u; s +=
i; len +=
i;
57 if (*s !=
'.')
return 0; ++s; ++
len;
58 i =
scan_ulong(s,&u);
if (!i)
return 0;
if (u > 255)
return 0; ip->
d[2] =
u; s +=
i; len +=
i;
59 if (*s !=
'.')
return 0; ++s; ++
len;
60 i =
scan_ulong(s,&u);
if (!i)
return 0;
if (u > 255)
return 0; ip->
d[3] =
u; s +=
i; len +=
i;
76 if (*s !=
'[')
return 0;
79 if (s[len + 1] !=
']')
return 0;
95 unsigned int temp, temp0;
96 unsigned int compressing;
97 unsigned int compressed;
105 for (j = 0; j < 16; j += 2) {
106 if (j == 12 &&
byte_equal(ip,12,V4mappedprefix)) {
107 for (i = 0; i < 4; i++) {
108 ip4.
d[
i] = ip->
d[i+12];
114 temp = ((
unsigned long) (
unsigned char) ip->
d[
j] << 8) +
115 (
unsigned long) (
unsigned char) ip->
d[j+1];
118 if (!compressing && j < 16)
119 temp0 = ((
unsigned long) (
unsigned char) ip->
d[j+2] << 8) +
120 (
unsigned long) (
unsigned char) ip->
d[j+3];
122 if (temp == 0 && temp0 == 0 && !compressed) {
146 if (compressing) { *s++ =
':'; ++
len; }
163 unsigned int len = 0;
172 for (x = 0;x < 4;x++) {
173 ip4.
d[
x] = ip->
d[x+12];
177 const char *
c = V4mappedprefix;
179 for (len = 0;len < 12;++
len)
184 for (i = 0;i < 16;i++)
200 if (prefixlen == 12 && s[i] ==
'.') {
205 for (x = 0;x < 4;x++) {
206 ip->
d[x+12] = ip4.
d[
x];
212 ip->
d[prefixlen++] = (u >> 8);
213 ip->
d[prefixlen++] = (u & 255);
227 }
else if (suffixlen != 0)
234 if (suffixlen+prefixlen <= 12 && s[i] ==
'.') {
242 prefixlen = 12-suffixlen;
244 suffix[suffixlen++] = (u >> 8);
245 suffix[suffixlen++] = (u & 255);
247 if (prefixlen+suffixlen == 16)
250 for (i = 0;i < suffixlen;i++)
251 ip->
d[16-suffixlen+i] = suffix[i];
268 if (*s !=
'[')
return 0;
271 if (s[len + 1] !=
']')
return 0;
275 static inline int fromhex(
unsigned char c) {
276 if (c>=
'0' && c<=
'9')
278 else if (c>=
'A' && c<=
'F')
280 else if (c>=
'a' && c<=
'f')
296 unsigned char number;
302 for (i = 0; i < 4; i++) {
303 number = (
unsigned char) ip4->
d[i];
304 if (number > 255)
return 2;
306 for (j = 7; j >= 0; j--) {
307 if (number & (1<<j)) {
335 unsigned char lowbyte, highbyte;
341 for (i = 0; i < 16; i++) {
342 lowbyte = (
unsigned char) (ip6->
d[i]) & 0x0f;
343 highbyte = (
unsigned char) (ip6->
d[i] >> 4) & 0x0f;
345 for (j = 3; j >= 0; j--) {
346 if (highbyte & (1<<j)) {
357 for (j = 3; j >= 0; j--) {
358 if (lowbyte & (1<<j)) {
unsigned int ip6_bitstring(stralloc *ip6string, struct ip6_address *ip6, int prefix)
ip6_bitstring parse IPv6 address and represent as char string with length prefix
unsigned int fmt_ulong(char *, unsigned long)
void c(char *home, char *subdir, char *file, int uid, int gid, int mode)
unsigned int scan_xlong(const char *, unsigned long *)
void byte_copy(char *, unsigned int, char *)
unsigned int ip6_scan(struct ip6_address *ip, char *s)
ip6_scan parse compactified IPv6 address string and convert to ip6_address struct ...
unsigned int ip4_bitstring(stralloc *ip4string, struct ip_address *ip4, int prefix)
ip4_bitstring parse IPv4 address and represent as char string with length prefix
unsigned int fmt_str(char *, char *)
unsigned int scan_ulong(register char *, register unsigned long *)
unsigned int ip4_scan(struct ip_address *ip, char *s)
ip4_scan parse IPv4 address string and convert to ip_address
unsigned int ip6_fmt(char *s, struct ip6_address *ip)
ip6_fmt convert IPv6 address to compactified IPv6 address string
unsigned int fmt_xlong(char *, unsigned long)
int stralloc_copys(stralloc *, char *)
int stralloc_cats(stralloc *, char *)
unsigned int ip4_fmt(char *s, struct ip_address *ip)
ip4_fmt converts IPv4 address to dotted decimal string format
unsigned int ip4_scanbracket(struct ip_address *ip, char *s)
ip4_scanbracket parse IPv4 address string enclosed in brackets and convert to ip_address struct ...
unsigned int ip6_scanbracket(struct ip6_address *ip6, char *s)
ip6_scanbracket parse IPv6 string address enclosed in brackets
#define byte_equal(s, n, t)