From owner-p4-projects@FreeBSD.ORG Sat Jun 24 08:33:30 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D76B916A506; Sat, 24 Jun 2006 08:33:29 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8567A16A4E6 for ; Sat, 24 Jun 2006 08:33:29 +0000 (UTC) (envelope-from clem1@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 45C4043D48 for ; Sat, 24 Jun 2006 08:33:29 +0000 (GMT) (envelope-from clem1@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k5O8XTVn018792 for ; Sat, 24 Jun 2006 08:33:29 GMT (envelope-from clem1@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k5O8XS0i018788 for perforce@freebsd.org; Sat, 24 Jun 2006 08:33:28 GMT (envelope-from clem1@FreeBSD.org) Date: Sat, 24 Jun 2006 08:33:28 GMT Message-Id: <200606240833.k5O8XS0i018788@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to clem1@FreeBSD.org using -f From: Clément Lecigne To: Perforce Change Reviews Cc: Subject: PERFORCE change 99920 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Jun 2006 08:33:30 -0000 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 #include #include +#include #else /* __WIN32__ */ #if (__CYGWIN__) #include ==== //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__)