summaryrefslogtreecommitdiff
path: root/libnet
diff options
context:
space:
mode:
Diffstat (limited to 'libnet')
-rw-r--r--libnet/include/libnet/libnet-functions.h10
-rw-r--r--libnet/src/libnet_build_ip.c58
-rw-r--r--libnet/src/libnet_resolve.c16
3 files changed, 23 insertions, 61 deletions
diff --git a/libnet/include/libnet/libnet-functions.h b/libnet/include/libnet/libnet-functions.h
index 9de11ef..e9c0340 100644
--- a/libnet/include/libnet/libnet-functions.h
+++ b/libnet/include/libnet/libnet-functions.h
@@ -229,6 +229,14 @@ libnet_name2addr4(libnet_t *l, char *host_name, uint8_t use_name);
extern const struct libnet_in6_addr in6addr_error;
/**
+ * Check a libnet_in6_addr structure for identity with in6addr_error.
+ * @param addr address to check
+ * @return 1 if addr is in6addr_error, 0 if it is not
+ */
+int
+libnet_in6_is_error(struct libnet_in6_addr addr);
+
+/**
* Takes a dotted decimal string or a canonical DNS name and returns a
* network byte ordered IPv6 address. This may incur a DNS lookup if mode is
* set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode
@@ -242,7 +250,7 @@ extern const struct libnet_in6_addr in6addr_error;
* @return network byte ordered IPv6 address structure
*/
struct libnet_in6_addr
-libnet_name2addr6(libnet_t *l, char *host_name, uint8_t use_name);
+libnet_name2addr6(libnet_t *l, const char *host_name, uint8_t use_name);
/**
* Should document this baby right here.
diff --git a/libnet/src/libnet_build_ip.c b/libnet/src/libnet_build_ip.c
index 1ecbc76..c05c235 100644
--- a/libnet/src/libnet_build_ip.c
+++ b/libnet/src/libnet_build_ip.c
@@ -749,67 +749,15 @@ libnet_ptag_t
libnet_autobuild_ipv6(uint16_t len, uint8_t nh, struct libnet_in6_addr dst,
libnet_t *l, libnet_ptag_t ptag)
{
- int libnet_in6_addr_cmp(struct libnet_in6_addr addr1, struct libnet_in6_addr addr2) {
- /* Returns != 0 if addresses are equal, 0 otherwise. */
- uint32_t *p1 = (uint32_t*)&addr1.__u6_addr, *p2 = (uint32_t*)&addr2.__u6_addr;
- return ((p1[0] == p2[0]) && (p1[1] == p2[1]) && (p1[2] == p2[2]) &&
- (p1[3] == p2[3]));
- }
-
- uint32_t n;
- libnet_pblock_t *p;
- struct libnet_ipv6_hdr ip_hdr;
struct libnet_in6_addr src;
- if (l == NULL)
- {
- return (-1);
- }
-
- n = LIBNET_IPV6_H; /* size of memory block */
- /*
- * Find the existing protocol block if a ptag is specified, or create
- * a new one.
- */
- p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_H);
- if (p == NULL)
- {
- return (-1);
- }
-
src = libnet_get_ipaddr6(l);
- if (libnet_in6_addr_cmp(src, in6addr_error))
- {
- /* err msg set in libnet_get_ipaddr6() */
- return (-1);
- }
- memset(&ip_hdr, 0, sizeof(ip_hdr));
- ip_hdr.ip_flags[0] = 0x06 << 4; /* ip version */
- ip_hdr.ip_flags[1] = 0;
- ip_hdr.ip_flags[2] = 0;
- ip_hdr.ip_flags[3] = 0;
- ip_hdr.ip_len = htons(len);
- ip_hdr.ip_nh = nh;
- ip_hdr.ip_hl = 64;
- ip_hdr.ip_src = src;
- ip_hdr.ip_dst = dst;
-
- n = libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV6_H);
- if (n == -1)
+ if (libnet_in6_is_error(src))
{
- goto bad;
+ return (-1);
}
- /* no checksum for IPv6 */
- ptag = ptag ? ptag : libnet_pblock_update(l, p, LIBNET_IPV6_H,
- LIBNET_PBLOCK_IPV6_H);
-
- return ptag;
-
-bad:
- libnet_pblock_delete(l, p);
- return (-1);
+ return libnet_build_ipv6(0, 0, len, nh, 64, src, dst, NULL, 0, l, ptag);
}
-/* EOF */
diff --git a/libnet/src/libnet_resolve.c b/libnet/src/libnet_resolve.c
index 961d710..fd58956 100644
--- a/libnet/src/libnet_resolve.c
+++ b/libnet/src/libnet_resolve.c
@@ -230,8 +230,14 @@ libnet_addr2name6_r(struct libnet_in6_addr addr, uint8_t use_name,
const struct libnet_in6_addr in6addr_error = IN6ADDR_ERROR_INIT;
+int
+libnet_in6_is_error(struct libnet_in6_addr addr)
+{
+ return 0 == memcmp(&addr, &in6addr_error, sizeof(addr));
+}
+
struct libnet_in6_addr
-libnet_name2addr6(libnet_t *l, char *host_name, uint8_t use_name)
+libnet_name2addr6(libnet_t *l, const char *host_name, uint8_t use_name)
{
#if !defined (__WIN32__)
struct libnet_in6_addr addr;
@@ -272,14 +278,14 @@ libnet_name2addr6(libnet_t *l, char *host_name, uint8_t use_name)
}
else
{
- #if defined(__WIN32__) /* Silence Win32 warning */
- if (l)
+#if defined(__WIN32__) /* Silence Win32 warning */
+ if (l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
"%s(): can't resolve IPv6 addresses.\n", __func__);
}
return (in6addr_error);
- #else
+#else
if(!inet_pton(AF_INET6, host_name, &addr))
{
if (l)
@@ -290,7 +296,7 @@ libnet_name2addr6(libnet_t *l, char *host_name, uint8_t use_name)
return (in6addr_error);
}
return (addr);
- #endif
+#endif
}
}