10 #include <arpa/inet.h>
11 #include <netinet/in6.h>
13 static inline int hexval(int ch)
15 if ( ch >= '0' && ch <= '9' ) {
17 } else if ( ch >= 'A' && ch <= 'F' ) {
19 } else if ( ch >= 'a' && ch <= 'f' ) {
26 int inet_pton(int af, const char *src, void *dst)
30 return inet_aton(src, (struct in_addr *)dst);
34 struct in6_addr *d = (struct in6_addr *)dst;
35 int colons = 0, dcolons = 0;
39 /* A double colon will increment colons by 2, dcolons by 1 */
40 for ( p = dst ; *p ; p++ ) {
45 } else if ( !isxdigit(*p) )
46 return 0; /* Not a valid address */
49 if ( colons > 7 || dcolons > 1 || (!dcolons && colons != 7) )
50 return 0; /* Not a valid address */
52 memset(d, 0, sizeof(struct in6_addr));
55 for ( p = dst ; *p ; p++ ) {
63 d->s6_addr16[i] = htons((ntohs(d->s6_addr16[i]) << 4) + hexval(*p));