summaryrefslogblamecommitdiff
path: root/src/network/inet_pton.c
blob: b7f4834fc98ae3ebf5aba6a23fe93c606afd3538 (plain) (tree)






















                                                                               
                         




                                                  
                  
 
#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 1;
	} else if (af==AF_INET6) {
		return !__ipparse(a, AF_INET6, s);
	}

	errno = EAFNOSUPPORT;
	return -1;
}