We now always have inet_ntop, even if it's our own implementation.
authoraland <aland>
Wed, 20 Apr 2005 20:15:30 +0000 (20:15 +0000)
committeraland <aland>
Wed, 20 Apr 2005 20:15:30 +0000 (20:15 +0000)
We always have AF_INET6, even if it's our own definition.

Our own inet_ntop now prints IPv4 and IPv6 in a dumb, but simple
format

src/lib/misc.c
src/lib/print.c

index d4c5425..5de2661 100644 (file)
@@ -45,7 +45,6 @@ static const char rcsid[] =
 int            librad_dodns = 0;
 int            librad_debug = 0;
 
-
 /*
  *     Return a printable host name (or IP address in dot notation)
  *     for the supplied IP address.
@@ -374,18 +373,34 @@ int inet_pton(int af, const char *src, void *dst)
 const char *inet_ntop(int af, const void *src, char *dst, size_t cnt)
 {
        if (af == AF_INET) {
-               uint32_t ipaddr;
+               struct in_addr *ipaddr = src;
 
-               if (cnt <= 15) return NULL;
-               
-               ipaddr = *(uint32_t *) src;
-               ipaddr = ntohl(ipaddr);
+               if (cnt <= INET_ADDRSTRLEN) return NULL;
                
                snprintf(dst, cnt, "%d.%d.%d.%d",
-                        (ipaddr >> 24) & 0xff,
-                        (ipaddr >> 16) & 0xff,
-                        (ipaddr >>  8) & 0xff,
-                        (ipaddr      ) & 0xff);
+                        ipaddr.s_addr[0], ipaddr.s_addr[1],
+                        ipaddr.s_addr[2], ipaddr.s_addr[3]);
+               return dst;
+       }
+
+       /*
+        *      If the system doesn't define this, we define it
+        *      in missing.h
+        */
+       if (af == AF_INET6) {
+               struct in6_addr *ipaddr = src;
+               
+               if (cnt <= INET6_ADDRSTRLEN) return NULL;
+
+               snprintf(dst, cnt, "%x:%x:%x:%x:%x:%x:%x:%x",
+                        ipaddr.s6_addr[0], ipaddr.s6_addr[1], 
+                        ipaddr.s6_addr[2], ipaddr.s6_addr[3], 
+                        ipaddr.s6_addr[4], ipaddr.s6_addr[5], 
+                        ipaddr.s6_addr[6], ipaddr.s6_addr[7], 
+                        ipaddr.s6_addr[8], ipaddr.s6_addr[9], 
+                        ipaddr.s6_addr[10], ipaddr.s6_addr[11], 
+                        ipaddr.s6_addr[12], ipaddr.s6_addr[13], 
+                        ipaddr.s6_addr[14], ipaddr.s6_addr[15]);
                return dst;
        }
 
@@ -506,6 +521,7 @@ const char *ip_ntoh(const lrad_ipaddr_t *src, char *dst, size_t cnt)
        return dst;
 }
 
+
 static const char *hextab = "0123456789abcdef";
 
 /*
index 82f77d4..9c3c3b7 100644 (file)
@@ -199,25 +199,9 @@ int vp_prints_value(char * out, int outlen, VALUE_PAIR *vp, int delimitst)
                        break;
 
                case PW_TYPE_IPV6ADDR:
-#if defined(HAVE_INET_NTOP) && defined(AF_INET6)
                        a = inet_ntop(AF_INET6,
                                      (const struct in6_addr *) vp->strvalue,
                                      buf, sizeof(buf));
-#else
-                       /*
-                        *      Do it really stupidly.
-                        */
-                       snprintf(buf, sizeof(buf), "%x:%x:%x:%x:%x:%x:%x:%x",
-                                (vp->strvalue[0] << 8) | vp->strvalue[1],
-                                (vp->strvalue[2] << 8) | vp->strvalue[3],
-                                (vp->strvalue[4] << 8) | vp->strvalue[5],
-                                (vp->strvalue[6] << 8) | vp->strvalue[7],
-                                (vp->strvalue[8] << 8) | vp->strvalue[9],
-                                (vp->strvalue[10] << 8) | vp->strvalue[11],
-                                (vp->strvalue[12] << 8) | vp->strvalue[13],
-                                (vp->strvalue[15] << 8) | vp->strvalue[15]);
-                       a = buf;
-#endif
                        break;
 
                default: