diff options
author | Carmelo Amoroso <carmelo.amoroso@st.com> | 2007-11-20 10:09:16 +0000 |
---|---|---|
committer | Carmelo Amoroso <carmelo.amoroso@st.com> | 2007-11-20 10:09:16 +0000 |
commit | 244539cd0852bbcf8f21507d7ff866d8e7fcff18 (patch) | |
tree | 5a04e6a195814b645007e4ccecb128d8c7b31ee7 /libc/inet/inet_net.c | |
parent | 1cac0350028cc4a47715f63e61379d3318b0c965 (diff) | |
download | uClibc-alpine-244539cd0852bbcf8f21507d7ff866d8e7fcff18.tar.bz2 uClibc-alpine-244539cd0852bbcf8f21507d7ff866d8e7fcff18.tar.xz |
Fix Makefile.in and synch them with trunk. Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/inet/inet_net.c')
-rw-r--r-- | libc/inet/inet_net.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/libc/inet/inet_net.c b/libc/inet/inet_net.c index f8148c274..71ed8dc88 100644 --- a/libc/inet/inet_net.c +++ b/libc/inet/inet_net.c @@ -50,55 +50,51 @@ libc_hidden_proto(__ctype_b) */ libc_hidden_proto(inet_network) in_addr_t -inet_network(const char *cp) +inet_network(cp) + register const char *cp; { - register in_addr_t val, base, n; + register u_int32_t val, base, n, i; register char c; - in_addr_t parts[4], *pp = parts; - register unsigned int i; + u_int32_t parts[4], *pp = parts; + int digit; again: - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, other=decimal. - */ - val = 0; base = 10; - /* - * The 4.4BSD version of this file also accepts 'x__' as a hexa - * number. I don't think this is correct. -- Uli - */ - if (*cp == '0') { - if (*++cp == 'x' || *cp == 'X') - base = 16, cp++; - else - base = 8; - } - while ((c = *cp)) { + val = 0; base = 10; digit = 0; + if (*cp == '0') + digit = 1, base = 8, cp++; + if (*cp == 'x' || *cp == 'X') + base = 16, cp++; + while ((c = *cp) != 0) { if (isdigit(c)) { + if (base == 8 && (c == '8' || c == '9')) + return (INADDR_NONE); val = (val * base) + (c - '0'); cp++; + digit = 1; continue; } if (base == 16 && isxdigit(c)) { - val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); + val = (val << 4) + (tolower (c) + 10 - 'a'); cp++; + digit = 1; continue; } break; } + if (!digit) + return (INADDR_NONE); + if (pp >= parts + 4 || val > 0xff) + return (INADDR_NONE); if (*cp == '.') { - if (pp >= parts + 4) - return (INADDR_NONE); *pp++ = val, cp++; goto again; } if (*cp && !isspace(*cp)) return (INADDR_NONE); + if (pp >= parts + 4 || val > 0xff) + return (INADDR_NONE); *pp++ = val; n = pp - parts; - if (n > 4) - return (INADDR_NONE); for (val = 0, i = 0; i < n; i++) { val <<= 8; val |= parts[i] & 0xff; |