From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/network/inet_pton.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/network/inet_pton.c (limited to 'src/network/inet_pton.c') diff --git a/src/network/inet_pton.c b/src/network/inet_pton.c new file mode 100644 index 00000000..349c4025 --- /dev/null +++ b/src/network/inet_pton.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#include +#include +#include "__dns.h" + +int inet_pton(int af, const char *s, void *a0) +{ + unsigned char *a = a0; + const char *z; + unsigned long x; + int i; + + /* Reimplement this because inet_pton cannot accept special v4 forms */ + if (af==AF_INET) { + for (i=0; i<4 && *s; i++) { + a[i] = x = strtoul(s, (char **)&z, 10); + if (!isdigit(*s) || z==s || (*z && *z != '.') || x>255) + return 0; + s=z+1; + } + return 0; + } else if (af==AF_INET6) { + return !__ipparse(a, AF_INET6, s); + } + + errno = EAFNOSUPPORT; + return 0; +} -- cgit v1.2.1