57#if defined (LIBC_SCCS) && !defined (lint)
58static char rcsid[] =
"$Id: inet_pton.c,v 1.1.1.1 2003/11/19 01:51:30 kyu3 Exp $";
107 return (inet_pton4 (src, dst));
109 return (inet_pton6 (src, dst));
111 errno = EAFNOSUPPORT;
134 static const char digits[] =
"0123456789";
135 int saw_digit, octets, ch;
136 u_char tmp[NS_INADDRSZ], *tp;
141 while ((ch = *src++) !=
'\0') {
144 if ((pch = strchr (digits, ch)) !=
NULL) {
145 u_int
new = *tp * 10 + (u_int)(pch - digits);
159 }
else if ((ch ==
'.') && saw_digit) {
175 memcpy (dst, tmp, NS_INADDRSZ);
198 static const char xdigits_l[] =
"0123456789abcdef",
199 xdigits_u[] =
"0123456789ABCDEF";
200 u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
201 const char *xdigits, *curtok;
205 memset ((tp = tmp),
'\0', NS_IN6ADDRSZ);
206 endp = tp + NS_IN6ADDRSZ;
218 while ((ch = *src++) !=
'\0') {
221 if ((pch = strchr ((xdigits = xdigits_l), ch)) ==
NULL) {
222 pch = strchr ((xdigits = xdigits_u), ch);
227 val |= (pch - xdigits);
247 if (tp + NS_INT16SZ > endp) {
251 *tp++ = (u_char)(val >> 8) & 0xff;
252 *tp++ = (u_char)val & 0xff;
258 if ((ch ==
'.') && ((tp + NS_INADDRSZ) <= endp) &&
259 (inet_pton4 (curtok, tp) > 0))
270 if (tp + NS_INT16SZ > endp) {
274 *tp++ = (u_char)(val >> 8) & 0xff;
275 *tp++ = (u_char)val & 0xff;
278 if (colonp !=
NULL) {
283 const int n = (int)(tp - colonp);
286 for (i = 1; i <= n; i++) {
287 endp[-i] = colonp[n - i];
298 memcpy (dst, tmp, NS_IN6ADDRSZ);