/*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id$";
+static const char rcsid[] = "$BINDId: inet_net_pton.c,v 1.11 1999/01/08 19:23:44 vixie Exp $";
#endif
#include <sys/types.h>
# define SPRINTF(x) ((size_t)sprintf x)
#endif
-static int inet_net_pton_ipv4 __P((const char *src, u_char *dst,
- size_t size));
+static int inet_net_pton_ipv4 (const char *src, u_char *dst,
+ size_t size) __THROW;
/*
* static int
* not an IPv4 network specification.
* note:
* network byte order assumed. this means 192.5.5.240/28 has
- * 0x11110000 in its fourth octet.
+ * 0b11110000 in its fourth octet.
* author:
* Paul Vixie (ISC), June 1996
*/
/* Hexadecimal: Eat nybble string. */
if (size <= 0)
goto emsgsize;
- *dst = 0, dirty = 0;
+ dirty = 0;
+ tmp = 0; /* To calm down gcc. */
src++; /* skip x or X. */
- while ((ch = *src++) != '\0' &&
- isascii(ch) && isxdigit(ch)) {
+ while (isxdigit((ch = *src++))) {
ch = _tolower(ch);
- n = strchr(xdigits, ch) - xdigits;
+ n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
assert(n >= 0 && n <= 15);
- *dst |= n;
- if (!dirty++)
- *dst <<= 4;
- else if (size-- > 0)
- *++dst = 0, dirty = 0;
+ if (dirty == 0)
+ tmp = n;
else
+ tmp = (tmp << 4) | n;
+ if (++dirty == 2) {
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = (u_char) tmp;
+ dirty = 0;
+ }
+ }
+ if (dirty) { /* Odd trailing nybble? */
+ if (size-- <= 0)
goto emsgsize;
+ *dst++ = (u_char) (tmp << 4);
}
- if (dirty)
- size--;
} else if (isascii(ch) && isdigit(ch)) {
/* Decimal: eat dotted digit string. */
for (;;) {
tmp = 0;
do {
- n = strchr(xdigits, ch) - xdigits;
+ n = ((const char *) __rawmemchr(xdigits, ch)
+ - xdigits);
assert(n >= 0 && n <= 9);
tmp *= 10;
tmp += n;
if (tmp > 255)
goto enoent;
- } while ((ch = *src++) != '\0' &&
- isascii(ch) && isdigit(ch));
+ } while (isascii((ch = *src++)) && isdigit(ch));
if (size-- <= 0)
goto emsgsize;
*dst++ = (u_char) tmp;
ch = *src++; /* Skip over the /. */
bits = 0;
do {
- n = strchr(xdigits, ch) - xdigits;
+ n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
assert(n >= 0 && n <= 9);
bits *= 10;
bits += n;
- } while ((ch = *src++) != '\0' &&
- isascii(ch) && isdigit(ch));
+ } while (isascii((ch = *src++)) && isdigit(ch));
if (ch != '\0')
goto enoent;
if (bits > 32)