10 #include <sys/socket.h>
11 #include <netinet/in.h>
18 return c == ':' || isascii(c) && isxdigit(c);
26 if(c == ':' || isascii(c) && isalnum(c))
32 inet_pton(int af, char *src, void *dst)
34 int i, v4 = 1, elipsis = 0;
40 return inet_aton(src, (struct in_addr*)dst);
47 to = ((struct in6_addr*)dst)->s6_addr;
51 for(i = 0; i < 16 && ipcharok(*p); i+=2){
53 x = strtoul(p, &p, 16);
55 if(*p == '.' || (*p == 0 && i == 0)){ /* ends with v4? */
58 if(i > 16-4 || inet_aton(op, &in) == 0)
59 return 0; /* parse error */
61 memmove(to+i, (unsigned char*)&in.s_addr, 4);
65 if(x != (unsigned short)x || *p != ':' && !delimchar(*p))
66 return 0; /* parse error */
72 if(*++p == ':'){ /* :: is elided zero short(s) */
74 return 0; /* second :: */
78 } else if (p == op) /* strtoul made no progress? */
81 if (p == src || !delimchar(*p))
82 return 0; /* parse error */
84 memmove(&to[elipsis+16-i], &to[elipsis], i-elipsis);
85 memset(&to[elipsis], 0, 16-i);
88 to[10] = to[11] = 0xff;