summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrepolho <repura0@gmail.com>2011-11-09 17:37:26 -0200
committerSam Roberts <vieuxtech@gmail.com>2012-03-05 16:45:46 -0800
commitbdbf78c0d578484b407abcc86ba22808cce2e7d6 (patch)
tree8ab9166aa3ce71697b561a8be0cd4e0598b5cb3c
parent96786d4a0652d1649d8f9a9b271582553ed74d54 (diff)
downloadlibnet-bdbf78c0d578484b407abcc86ba22808cce2e7d6.tar.gz
Implemented unix version of libnet_get_ipaddr6()
-rw-r--r--libnet/include/libnet/libnet-functions.h6
-rw-r--r--libnet/src/libnet_resolve.c48
2 files changed, 53 insertions, 1 deletions
diff --git a/libnet/include/libnet/libnet-functions.h b/libnet/include/libnet/libnet-functions.h
index eccc35d..6f98ab0 100644
--- a/libnet/include/libnet/libnet-functions.h
+++ b/libnet/include/libnet/libnet-functions.h
@@ -1869,7 +1869,11 @@ uint32_t
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
+ * libnet was initialized without a device (in raw socket mode) the function
+ * will attempt to find one. If the function fails and returns in6addr_error, a
+ * call to libnet_geterrror() will tell you why.
+ * This function is not yet implemented for Win32 platforms.
* @param l pointer to a libnet context
* @return well, nothing yet
*/
diff --git a/libnet/src/libnet_resolve.c b/libnet/src/libnet_resolve.c
index 642fcd5..961d710 100644
--- a/libnet/src/libnet_resolve.c
+++ b/libnet/src/libnet_resolve.c
@@ -294,6 +294,53 @@ libnet_name2addr6(libnet_t *l, char *host_name, uint8_t use_name)
}
}
+#if !defined(__WIN32__)
+
+#include <ifaddrs.h>
+
+struct libnet_in6_addr
+libnet_get_ipaddr6(libnet_t *l)
+{
+ struct ifaddrs *ifaddr, *p;
+ struct libnet_in6_addr addr;
+
+ if (l == NULL)
+ {
+ return (in6addr_error);
+ }
+
+ if (getifaddrs(&ifaddr) != 0)
+ {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
+ "%s(): getifaddrs(): %s\n", __func__, strerror(errno));
+ return (in6addr_error);
+ }
+
+ if (l->device == NULL)
+ {
+ if (libnet_select_device(l) == -1)
+ {
+ /* error msg set in libnet_select_device() */
+ return (in6addr_error);
+ }
+ }
+
+ for (p = ifaddr; p != NULL; p = p->ifa_next)
+ {
+ if ((strcmp(p->ifa_name, l->device) == 0) && (p->ifa_addr != NULL) &&
+ (p->ifa_addr->sa_family == AF_INET6))
+ {
+ memcpy(&addr.__u6_addr,
+ ((struct sockaddr_in6*)p->ifa_addr)->sin6_addr.s6_addr, 16);
+ freeifaddrs(ifaddr);
+ return (addr);
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ return (in6addr_error);
+}
+#else
struct libnet_in6_addr
libnet_get_ipaddr6(libnet_t *l)
{
@@ -301,6 +348,7 @@ libnet_get_ipaddr6(libnet_t *l)
"%s(): not yet Implemented\n", __func__);
return (in6addr_error);
}
+#endif /* WIN32 */
#if !defined(__WIN32__)
uint32_t