21 #ifndef HAVE_INET_PTON
23 #ifdef HAVE_SYS_PARAM_H
24 #include <sys/param.h>
26 #ifdef HAVE_SYS_TYPES_H
27 #include <sys/types.h>
29 #ifdef HAVE_SYS_SOCKET_H
30 #include <sys/socket.h>
32 #ifdef HAVE_NETINET_IN_H
33 #include <netinet/in.h>
35 #ifdef HAVE_ARPA_INET_H
36 #include <arpa/inet.h>
48 #define EAFNOSUPPORT WSAEAFNOSUPPORT
56 static int inet_pton4(
const char *
src,
unsigned char *
dst);
58 static int inet_pton6(
const char *
src,
unsigned char *
dst);
77 return (inet_pton4(src, dst));
80 #define AF_INET6 AF_MAX+1
83 return (inet_pton6(src, dst));
103 inet_pton4(
const char *
src,
unsigned char *
dst)
105 static const char digits[] =
"0123456789";
106 int saw_digit, octets, ch;
112 while ((ch = *src++) !=
'\0') {
115 if ((pch = strchr(digits, ch)) !=
NULL) {
116 u_int
new = *tp * 10 + (pch - digits);
126 }
else if (ch ==
'.' && saw_digit) {
156 inet_pton6(
const char *src,
unsigned char *dst)
158 static const char xdigits_l[] =
"0123456789abcdef",
159 xdigits_u[] =
"0123456789ABCDEF";
160 unsigned char tmp[
IN6ADDRSZ], *tp, *endp, *colonp;
161 const char *xdigits, *curtok;
175 while ((ch = *src++) !=
'\0') {
178 if ((pch = strchr((xdigits = xdigits_l), ch)) ==
NULL)
179 pch = strchr((xdigits = xdigits_u), ch);
182 val |= (pch - xdigits);
198 *tp++ = (
unsigned char) (val >> 8) & 0xff;
199 *tp++ = (
unsigned char) val & 0xff;
204 if (ch ==
'.' && ((tp +
INADDRSZ) <= endp) &&
205 inet_pton4(curtok, tp) > 0) {
215 *tp++ = (
unsigned char) (val >> 8) & 0xff;
216 *tp++ = (
unsigned char) val & 0xff;
218 if (colonp !=
NULL) {
223 const int n = tp - colonp;
226 for (i = 1; i <=
n; i++) {
227 endp[-
i] = colonp[n -
i];
235 memcpy(dst, tmp, IN6ADDRSZ);
int Curl_inet_pton(int af, const char *src, void *dst)