20 #if defined(LIBC_SCCS) && !defined(lint)
21 static const char rcsid[] =
"Id: inet_net_pton.c,v 1.4.2.3 2004/03/17 00:40:11 marka Exp $";
99 static const char xdigits[] =
"0123456789abcdef";
100 static const char digits[] =
"0123456789";
106 const u_char *odst = dst;
109 if (ch ==
'0' && (src[0] ==
'x' || src[0] ==
'X')
110 && isxdigit((
unsigned char) src[1]))
117 while ((ch = *src++) !=
'\0' && isxdigit((
unsigned char) ch))
119 if (isupper((
unsigned char) ch))
120 ch = tolower((
unsigned char) ch);
121 n = strchr(xdigits, ch) - xdigits;
122 assert(n >= 0 && n <= 15);
126 tmp = (tmp << 4) | n;
131 *dst++ = (u_char) tmp;
139 *dst++ = (u_char) (tmp << 4);
142 else if (isdigit((
unsigned char) ch))
156 }
while ((ch = *src++) !=
'\0' &&
157 isdigit((
unsigned char) ch));
160 *dst++ = (u_char) tmp;
161 if (ch ==
'\0' || ch ==
'/')
166 if (!isdigit((
unsigned char) ch))
174 if (ch ==
'/' && isdigit((
unsigned char) src[0]) && dst > odst)
185 }
while ((ch = *src++) !=
'\0' && isdigit((
unsigned char) ch));
204 else if (*odst >= 224)
206 else if (*odst >= 192)
208 else if (*odst >= 128)
214 if (bits < ((dst - odst) * 8))
215 bits = (dst - odst) * 8;
221 if (bits == 8 && *odst == 224)
225 while (bits > ((dst - odst) * 8))
262 static const char digits[] =
"0123456789";
263 const u_char *odst = dst;
271 while (ch = *src++, isdigit((
unsigned char) ch))
282 }
while ((ch = *src++) !=
'\0' && isdigit((
unsigned char) ch));
285 *dst++ = (u_char) tmp;
286 if (ch ==
'\0' || ch ==
'/')
294 if (ch ==
'/' && isdigit((
unsigned char) src[0]) && dst > odst)
305 }
while ((ch = *src++) !=
'\0' && isdigit((
unsigned char) ch));
330 if ((bits / 8) > (dst - odst))
351 static const char digits[] =
"0123456789";
358 while ((ch = *src++) !=
'\0')
365 if (n++ != 0 &&
val == 0)
382 getv4(
const char *src, u_char *dst,
int *bitsp)
384 static const char digits[] =
"0123456789";
392 while ((ch = *src++) !=
'\0')
399 if (n++ != 0 &&
val == 0)
407 if (ch ==
'.' || ch ==
'/')
434 #define NS_IN6ADDRSZ 16
436 #define NS_INADDRSZ 4
441 static const char xdigits_l[] =
"0123456789abcdef",
442 xdigits_u[] =
"0123456789ABCDEF";
470 while ((ch = *src++) !=
'\0')
474 if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
475 pch = strchr((xdigits = xdigits_u), ch);
479 val |= (pch - xdigits);
495 else if (*src ==
'\0')
499 *tp++ = (u_char) (
val >> 8) & 0xff;
500 *tp++ = (u_char)
val & 0xff;
507 getv4(curtok, tp, &bits) > 0)
513 if (ch ==
'/' &&
getbits(src, &bits) > 0)
521 *tp++ = (u_char) (
val >> 8) & 0xff;
522 *tp++ = (u_char)
val & 0xff;
535 const int n = tp - colonp;
540 for (
i = 1;
i <= n;
i++)
542 endp[-
i] = colonp[n -
i];
int pg_inet_net_pton(int af, const char *src, void *dst, size_t size)
static int inet_net_pton_ipv6(const char *src, u_char *dst)
static int inet_net_pton_ipv4(const char *src, u_char *dst)
static int getbits(const char *src, int *bitsp)
static int getv4(const char *src, u_char *dst, int *bitsp)
static int inet_cidr_pton_ipv6(const char *src, u_char *dst, size_t size)
static int inet_cidr_pton_ipv4(const char *src, u_char *dst, size_t size)
static pg_noinline void Size size