* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
-static int inet_pton4(const char *src, u_char *dst);
-static int inet_pton6(const char *src, u_char *dst);
+static int inet_pton4(const char *src, u_char *dst);
+static int inet_pton6(const char *src, u_char *dst);
/* int
* inet_pton(af, src, dst)
{
switch (af) {
case AF_INET:
- return (inet_pton4(src, dst));
+ return inet_pton4(src, dst);
case AF_INET6:
- return (inet_pton6(src, dst));
+ return inet_pton6(src, dst);
default:
- return (-1);
+ return -1;
}
/* NOTREACHED */
}
{
static const char digits[] = "0123456789";
int saw_digit, octets, ch;
-#define NS_INADDRSZ 4
+#define NS_INADDRSZ 4
u_char tmp[NS_INADDRSZ], *tp;
saw_digit = 0;
if ((pch = strchr(digits, ch)) != NULL) {
u_int new = *tp * 10 + (pch - digits);
- if (saw_digit && *tp == 0)
- return (0);
- if (new > 255)
- return (0);
+ if (saw_digit && *tp == 0) {
+ return 0;
+ }
+ if (new > 255) {
+ return 0;
+ }
*tp = new;
if (!saw_digit) {
- if (++octets > 4)
- return (0);
+ if (++octets > 4) {
+ return 0;
+ }
saw_digit = 1;
}
} else if (ch == '.' && saw_digit) {
- if (octets == 4)
- return (0);
+ if (octets == 4) {
+ return 0;
+ }
*++tp = 0;
saw_digit = 0;
- } else
- return (0);
+ } else {
+ return 0;
+ }
+ }
+ if (octets < 4) {
+ return 0;
}
- if (octets < 4)
- return (0);
memcpy(dst, tmp, NS_INADDRSZ);
- return (1);
+ return 1;
}
/* int
inet_pton6(const char *src, u_char *dst)
{
static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
-#define NS_IN6ADDRSZ 16
-#define NS_INT16SZ 2
+ xdigits_u[] = "0123456789ABCDEF";
+#define NS_IN6ADDRSZ 16
+#define NS_INT16SZ 2
u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
const char *xdigits, *curtok;
int ch, seen_xdigits;
endp = tp + NS_IN6ADDRSZ;
colonp = NULL;
/* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- return (0);
+ if (*src == ':') {
+ if (*++src != ':') {
+ return 0;
+ }
+ }
curtok = src;
seen_xdigits = 0;
val = 0;
while ((ch = *src++) != '\0') {
const char *pch;
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) {
pch = strchr((xdigits = xdigits_u), ch);
+ }
if (pch != NULL) {
val <<= 4;
val |= (pch - xdigits);
- if (++seen_xdigits > 4)
- return (0);
+ if (++seen_xdigits > 4) {
+ return 0;
+ }
continue;
}
if (ch == ':') {
curtok = src;
if (!seen_xdigits) {
- if (colonp)
- return (0);
+ if (colonp) {
+ return 0;
+ }
colonp = tp;
continue;
} else if (*src == '\0') {
- return (0);
+ return 0;
+ }
+ if (tp + NS_INT16SZ > endp) {
+ return 0;
}
- if (tp + NS_INT16SZ > endp)
- return (0);
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
seen_xdigits = 0;
inet_pton4(curtok, tp) > 0) {
tp += NS_INADDRSZ;
seen_xdigits = 0;
- break; /*%< '\\0' was seen by inet_pton4(). */
+ break; /*%< '\\0' was seen by inet_pton4(). */
}
- return (0);
+ return 0;
}
if (seen_xdigits) {
- if (tp + NS_INT16SZ > endp)
- return (0);
+ if (tp + NS_INT16SZ > endp) {
+ return 0;
+ }
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
}
const int n = tp - colonp;
int i;
- if (tp == endp)
- return (0);
+ if (tp == endp) {
+ return 0;
+ }
for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
+ endp[-i] = colonp[n - i];
colonp[n - i] = 0;
}
tp = endp;
}
- if (tp != endp)
- return (0);
+ if (tp != endp) {
+ return 0;
+ }
memcpy(dst, tmp, NS_IN6ADDRSZ);
- return (1);
+ return 1;
}