diff options
Diffstat (limited to 'src/network/inet_pton.c')
-rw-r--r-- | src/network/inet_pton.c | 31 |
1 files changed, 31 insertions, 0 deletions
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 <sys/socket.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <stdlib.h> +#include <ctype.h> +#include <errno.h> +#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; +} |