4 #include <sys/socket.h>
5 #include <netinet/in.h>
9 int __ipparse(void *dest, int family, const char *s0)
12 unsigned char *d = dest;
13 unsigned long a[16] = { 0 };
17 if (family == AF_INET6) goto not_v4;
20 a[i] = strtoul(s, &z, 0);
21 if (z==s || (*z && *z != '.') || !isdigit(*s)) {
22 if (family == AF_INET) return -1;
31 a[1] = a[0] & 0xffffff;
40 ((struct sockaddr_in *)d)->sin_family = AF_INET;
41 d = (void *)&((struct sockaddr_in *)d)->sin_addr;
43 if (a[i] > 255) return -1;
50 ((struct sockaddr_in6 *)d)->sin6_family = AF_INET6;
51 return inet_pton(AF_INET6, s, (void *)&((struct sockaddr_in6 *)d)->sin6_addr) <= 0 ? -1 : 0;