19 #ifndef HAVE_INET_PTON 21 #ifdef HAVE_SYS_PARAM_H 22 #include <sys/param.h> 24 #ifdef HAVE_SYS_TYPES_H 25 #include <sys/types.h> 27 #ifdef HAVE_SYS_SOCKET_H 28 #include <sys/socket.h> 30 #ifdef HAVE_NETINET_IN_H 31 #include <netinet/in.h> 33 #ifdef HAVE_ARPA_INET_H 34 #include <arpa/inet.h> 47 #define EAFNOSUPPORT WSAEAFNOSUPPORT 58 static int inet_pton4(
const char *src,
unsigned char *dst);
60 static int inet_pton6(
const char *src,
unsigned char *dst);
78 return (
inet_pton4(src, (
unsigned char *) dst));
81 #define AF_INET6 (AF_MAX+1) 84 return (inet_pton6(src, (
unsigned char *) dst));
105 static const char digits[] =
"0123456789";
106 int saw_digit, octets, ch;
113 while ((ch = *src++) !=
'\0') {
116 if ((pch = strchr(digits, ch)) != NULL) {
117 unsigned int val = *tp * 10 + (
unsigned int) (pch - digits);
121 *tp = (
unsigned char) val;
127 }
else if (ch ==
'.' && saw_digit) {
156 static int inet_pton6(
const char *src,
unsigned char *dst)
158 static const char xdigits_l[] =
"0123456789abcdef", xdigits_u[] =
"0123456789ABCDEF";
159 unsigned char tmp[
IN6ADDRSZ], *tp, *endp, *colonp;
160 const char *xdigits, *curtok;
174 while ((ch = *src++) !=
'\0') {
177 if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
178 pch = strchr((xdigits = xdigits_u), ch);
181 val |= (pch - xdigits);
197 *tp++ = (
unsigned char) (val >> 8) & 0xff;
198 *tp++ = (
unsigned char) val & 0xff;
213 *tp++ = (
unsigned char) (val >> 8) & 0xff;
214 *tp++ = (
unsigned char) val & 0xff;
216 if (colonp != NULL) {
221 const int n = tp - colonp;
224 for (i = 1; i <= n; i++) {
225 endp[-i] = colonp[n - i];
233 memcpy(dst, tmp, IN6ADDRSZ);
int switch_inet_pton(int af, const char *src, void *dst)
static int inet_pton4(const char *src, unsigned char *dst)