OSDN Git Service

- trim any trailing whitespace
[uclinux-h8/uClibc.git] / libc / inet / ntop.c
index 02590fd..f19556d 100644 (file)
@@ -15,6 +15,8 @@
  * SOFTWARE.
  */
 
+#define __FORCE_GLIBC
+#include <features.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
+
+/* Experimentally off - libc_hidden_proto(memcpy) */
+/* Experimentally off - libc_hidden_proto(memset) */
+/* Experimentally off - libc_hidden_proto(strchr) */
+/* Experimentally off - libc_hidden_proto(strcpy) */
+/* Experimentally off - libc_hidden_proto(strlen) */
+libc_hidden_proto(sprintf)
+libc_hidden_proto(tolower)
 
 /*
  * WARNING: Don't even consider trying to compile this on a system where
  *     Paul Vixie, 1996.
  */
 static const char *
-inet_ntop4(src, dst, size)
-       const u_char *src;
-       char *dst;
-       size_t size;
+inet_ntop4(const u_char *src, char *dst, size_t size)
 {
        char tmp[sizeof ("255.255.255.255") + 1] = "\0";
        int octet;
@@ -57,10 +65,12 @@ inet_ntop4(src, dst, size)
        i = 0;
        for (octet = 0; octet <= 3; octet++) {
 
+#if 0  /* since src is unsigned char, it will never be > 255 ... */
                if (src[octet] > 255) {
                        __set_errno (ENOSPC);
                        return (NULL);
                }
+#endif
                tmp[i++] = '0' + src[octet] / 100;
                if (tmp[i - 1] == '0') {
                        tmp[i - 1] = '0' + (src[octet] / 10 % 10);
@@ -89,13 +99,10 @@ inet_ntop4(src, dst, size)
  *     Paul Vixie, 1996.
  */
 
-#ifdef INET_IPV6
+#ifdef __UCLIBC_HAS_IPV6__
 
 static const char *
-inet_ntop6(src, dst, size)
-       const u_char *src;
-       char *dst;
-       size_t size;
+inet_ntop6(const u_char *src, char *dst, size_t size)
 {
        /*
         * Note that int32_t and int16_t need only be "at least" large enough
@@ -119,6 +126,8 @@ inet_ntop6(src, dst, size)
                words[i / 2] = (src[i] << 8) | src[i + 1];
        best.base = -1;
        cur.base = -1;
+       best.len = best.len; /* shutting up compiler warning */
+       cur.len = cur.len;   /* shutting up compiler warning */
        for (i = 0; i < 8; i++) {
                if (words[i] == 0) {
                        if (cur.base == -1)
@@ -163,7 +172,7 @@ inet_ntop6(src, dst, size)
                        tp += strlen(tp);
                        break;
                }
-               tp += SPRINTF((tp, "%x", words[i]));
+               tp += sprintf(tp, "%x", words[i]);
        }
        /* Was it a trailing run of 0x00's? */
        if (best.base != -1 && (best.base + best.len) == 8)
@@ -179,7 +188,7 @@ inet_ntop6(src, dst, size)
        }
        return strcpy(dst, tmp);
 }
-#endif /* INET_IPV6 */
+#endif /* __UCLIBC_HAS_IPV6__ */
 
 
 /* int
@@ -193,9 +202,7 @@ inet_ntop6(src, dst, size)
  *     Paul Vixie, 1996.
  */
 static int
-inet_pton4(src, dst)
-       const char *src;
-       u_char *dst;
+inet_pton4(const char *src, u_char *dst)
 {
        int saw_digit, octets, ch;
        u_char tmp[4], *tp;
@@ -244,12 +251,17 @@ inet_pton4(src, dst)
  *     Paul Vixie, 1996.
  */
 
-#ifdef INET_IPV6
+#ifdef __UCLIBC_HAS_IPV6__
+
+/* We cannot use the macro version of tolower() or very bad
+ * things happen when '*src++' gets evaluated multiple times.
+ * So undef it here so we get the function version of tolower
+ * instead.
+ */
+#undef tolower
 
 static int
-inet_pton6(src, dst)
-       const char *src;
-       u_char *dst;
+inet_pton6(const char *src, u_char *dst)
 {
        static const char xdigits[] = "0123456789abcdef";
        u_char tmp[16], *tp, *endp, *colonp;
@@ -257,6 +269,7 @@ inet_pton6(src, dst)
        int ch, saw_xdigit;
        u_int val;
 
+
        tp = memset(tmp, '\0', 16);
        endp = tp + 16;
        colonp = NULL;
@@ -333,7 +346,7 @@ inet_pton6(src, dst)
        return (1);
 }
 
-#endif /* INET_IPV6 */
+#endif /* __UCLIBC_HAS_IPV6__ */
 
 
 
@@ -345,17 +358,14 @@ inet_pton6(src, dst)
  * author:
  *     Paul Vixie, 1996.
  */
-extern const char *
-inet_ntop(af, src, dst, size)
-       int af;
-       const void *src;
-       char *dst;
-       size_t size;
+libc_hidden_proto(inet_ntop)
+const char *
+inet_ntop(int af, const void *src, char *dst, socklen_t size)
 {
        switch (af) {
        case AF_INET:
                return (inet_ntop4(src, dst, size));
-#ifdef INET_IPV6
+#ifdef __UCLIBC_HAS_IPV6__
        case AF_INET6:
                return (inet_ntop6(src, dst, size));
 #endif
@@ -365,6 +375,7 @@ inet_ntop(af, src, dst, size)
        }
        /* NOTREACHED */
 }
+libc_hidden_def(inet_ntop)
 
 
 /* int
@@ -378,16 +389,14 @@ inet_ntop(af, src, dst, size)
  * author:
  *     Paul Vixie, 1996.
  */
-extern int
-inet_pton(af, src, dst)
-       int af;
-       const char *src;
-       void *dst;
+libc_hidden_proto(inet_pton)
+int
+inet_pton(int af, const char *src, void *dst)
 {
        switch (af) {
        case AF_INET:
                return (inet_pton4(src, dst));
-#ifdef INET_IPV6
+#ifdef __UCLIBC_HAS_IPV6__
        case AF_INET6:
                return (inet_pton6(src, dst));
 #endif
@@ -397,4 +406,4 @@ inet_pton(af, src, dst)
        }
        /* NOTREACHED */
 }
-
+libc_hidden_def(inet_pton)