Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Jun 2006 08:33:28 GMT
From:      Clément Lecigne <clem1@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 99920 for review
Message-ID:  <200606240833.k5O8XS0i018788@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=99920

Change 99920 by clem1@clem1_ipv6vulns on 2006/06/24 08:32:58

	libnet_get_ipaddr6() libnet implementation. 

Affected files ...

.. //depot/projects/soc2006/clem1_ipv6vulns/libnet/include/libnet.h.in#2 edit
.. //depot/projects/soc2006/clem1_ipv6vulns/libnet/include/libnet/libnet-functions.h#3 edit
.. //depot/projects/soc2006/clem1_ipv6vulns/libnet/src/Makefile.in#3 edit
.. //depot/projects/soc2006/clem1_ipv6vulns/libnet/src/libnet_resolve.c#3 edit

Differences ...

==== //depot/projects/soc2006/clem1_ipv6vulns/libnet/include/libnet.h.in#2 (text+ko) ====

@@ -81,6 +81,7 @@
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
 #include <net/if.h>
+#include <ifaddrs.h>
 #else /* __WIN32__ */
 #if (__CYGWIN__)
 #include <sys/socket.h>

==== //depot/projects/soc2006/clem1_ipv6vulns/libnet/include/libnet/libnet-functions.h#3 (text+ko) ====

@@ -1789,7 +1789,7 @@
  * Returns the IP address for the device libnet was initialized with. If
  * libnet was initialized without a device (in raw socket mode) the function
  * will attempt to find one. If the function fails and returns -1 a call to 
- * libnet_geterrror() will tell you why.
+ * libnet_geterror() will tell you why.
  * @param l pointer to a libnet context
  * @return a big endian IP address suitable for use in a libnet_build function or -1
  */
@@ -1798,9 +1798,12 @@
 libnet_get_ipaddr4(libnet_t *l);
 
 /**
- * This function is not yet implemented under IPv6.
+ * Returns the IPv6 address for the device libnet was initialized with. If the
+ * function fails and returns in6addr_error (struct libnet_in6_addr) a call to
+ * libnet_geterror() will tell you why.
  * @param l pointer to a libnet context
- * @return well, nothing yet
+ * @return a big endian IP address (struct libnet_in6_addr) suitable for use in
+ * a libnet_build function.
  */
 struct libnet_in6_addr
 libnet_get_ipaddr6(libnet_t *l);

==== //depot/projects/soc2006/clem1_ipv6vulns/libnet/src/Makefile.in#3 (text+ko) ====

@@ -187,7 +187,8 @@
 	libnet_build_cdp.$(OBJEXT) libnet_build_data.$(OBJEXT) \
 	libnet_build_dhcp.$(OBJEXT) libnet_build_dns.$(OBJEXT) \
 	libnet_build_ethernet.$(OBJEXT) libnet_build_fddi.$(OBJEXT) \
-	libnet_build_gre.$(OBJEXT) libnet_build_icmp.$(OBJEXT) \
+	libnet_build_gre.$(OBJEXT) libnet_build_icmpv6.$(OBJEXT) \
+    libnet_build_icmpv4.$(OBJEXT) \
 	libnet_build_igmp.$(OBJEXT) libnet_build_ip.$(OBJEXT) \
 	libnet_build_ipsec.$(OBJEXT) libnet_build_isl.$(OBJEXT) \
 	libnet_build_mpls.$(OBJEXT) libnet_build_ntp.$(OBJEXT) \

==== //depot/projects/soc2006/clem1_ipv6vulns/libnet/src/libnet_resolve.c#3 (text+ko) ====

@@ -289,9 +289,59 @@
 struct libnet_in6_addr
 libnet_get_ipaddr6(libnet_t *l)
 {
+#if defined(__WIN32__)
     snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
            "%s(): not yet Implemented\n", __func__);
     return (in6addr_error);
+#else
+    struct ifaddrs *ifap0, *ifap;
+    struct libnet_in6_addr v6;
+    u_int8_t ok = 0;
+    
+    if (getifaddrs(&ifap0)) {
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+                "%s(): %s\n", __func__, strerror(errno));
+        return (in6addr_error);
+    }
+    
+    for (ifap = ifap0; ifap; ifap = ifap->ifa_next) {
+        if (ifap->ifa_addr == NULL)
+        {
+            continue;
+        }
+
+        if (ifap->ifa_addr->sa_family != AF_INET6)
+        {
+            continue;
+        }
+
+        if (strncmp(l->device, ifap->ifa_name, IFNAMSIZ))
+        {
+            continue;
+        }
+        else
+        {
+            if(IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *) ifap->ifa_addr)->sin6_addr)
+                    || IN6_IS_ADDR_SITELOCAL(&((struct sockaddr_in6 *) ifap->ifa_addr)->sin6_addr))
+            {
+                continue;
+            }
+            memcpy(&v6, &((struct sockaddr_in6 *) ifap->ifa_addr)->sin6_addr, 16);
+            ok++;
+            break;
+        }
+    }
+    
+    freeifaddrs(ifap0);
+    
+    if (!ok)
+    {
+        snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+                "%s(): could not find ipv6 address for %s\n", __func__, l->device);
+        return (in6addr_error);
+    }
+    return (v6);
+#endif /* !WIN32 */
 }
 
 #if !defined(__WIN32__)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606240833.k5O8XS0i018788>