1 #include <sys/socket.h>
9 static int hexval(unsigned c)
11 if (c-'0'<10) return c-'0';
13 if (c-'a'<6) return c-'a'+10;
17 int inet_pton(int af, const char *s, void *a0)
20 unsigned char *a = a0;
23 int i, j, v, d, brk=-1, need_v4=0;
25 /* Reimplement this because inet_pton cannot accept special v4 forms */
27 for (i=0; i<4 && *s; i++) {
28 a[i] = x = strtoul(s, (char **)&z, 10);
29 if (!isdigit(*s) || z==s || (*z && *z != '.') || x>255)
34 } else if (af!=AF_INET6) {
39 if (s[0]==':' && s[1]==':') {
44 for (i=0; ; i++, s+=j+1) {
45 if (s[0]==':' && brk<0) {
52 if (hexval(s[0])<0) return -1;
53 while (s[0]=='0' && s[1]=='0') s++;
54 for (v=j=0; j<5 && (d=hexval(s[j]))>=0; j++)
56 if (v > 65535) return -1;
59 if (brk<0 && i!=7) return -1;
63 if (s[j]==':') continue;
64 if (s[j]!='.') return -1;
72 memmove(ip+brk+7-i, ip+brk, 2*(i+1-brk));
73 for (j=0; j<7-i; j++) ip[brk+j] = 0;
79 if (need_v4 &&inet_pton(AF_INET, (void *)s, a-4) <= 0) return -1;