summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libnet/src/libnet_advanced.c10
-rw-r--r--libnet/src/libnet_build_arp.c2
-rw-r--r--libnet/src/libnet_build_dhcp.c2
-rw-r--r--libnet/src/libnet_build_gre.c2
-rw-r--r--libnet/src/libnet_build_hsrp.c2
-rw-r--r--libnet/src/libnet_build_icmp.c2
-rw-r--r--libnet/src/libnet_build_ip.c16
-rw-r--r--libnet/src/libnet_build_link.c4
-rw-r--r--libnet/src/libnet_build_tcp.c4
-rw-r--r--libnet/src/libnet_build_token_ring.c4
-rw-r--r--libnet/src/libnet_checksum.c14
-rw-r--r--libnet/src/libnet_cq.c18
-rw-r--r--libnet/src/libnet_if_addr.c27
-rw-r--r--libnet/src/libnet_init.c6
-rw-r--r--libnet/src/libnet_link_bpf.c22
-rw-r--r--libnet/src/libnet_link_dlpi.c169
-rw-r--r--libnet/src/libnet_link_linux.c8
-rw-r--r--libnet/src/libnet_link_none.c2
-rw-r--r--libnet/src/libnet_link_pf.c4
-rw-r--r--libnet/src/libnet_link_win32.c20
-rw-r--r--libnet/src/libnet_pblock.c20
-rw-r--r--libnet/src/libnet_port_list.c8
-rw-r--r--libnet/src/libnet_prand.c2
-rw-r--r--libnet/src/libnet_raw.c16
-rw-r--r--libnet/src/libnet_resolve.c24
-rw-r--r--libnet/src/libnet_write.c20
26 files changed, 232 insertions, 196 deletions
diff --git a/libnet/src/libnet_advanced.c b/libnet/src/libnet_advanced.c
index cf25258..2ea4874 100644
--- a/libnet/src/libnet_advanced.c
+++ b/libnet/src/libnet_advanced.c
@@ -41,7 +41,7 @@ libnet_adv_cull_packet(libnet_t *l, uint8_t **packet, uint32_t *packet_s)
if (l->injection_type != LIBNET_LINK_ADV)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): advanced link mode not enabled\n", __func__);
+ "%s(): advanced link mode not enabled", __func__);
return (-1);
}
@@ -61,7 +61,7 @@ libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, uint8_t **header,
if (l->injection_type != LIBNET_LINK_ADV)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): advanced link mode not enabled\n", __func__);
+ "%s(): advanced link mode not enabled", __func__);
return (-1);
}
@@ -69,7 +69,7 @@ libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, uint8_t **header,
if (p == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): ptag not found, you sure it exists?\n", __func__);
+ "%s(): ptag not found, you sure it exists?", __func__);
return (-1);
}
*header = p->buf;
@@ -86,7 +86,7 @@ libnet_adv_write_link(libnet_t *l, const uint8_t *packet, uint32_t packet_s)
if (l->injection_type != LIBNET_LINK_ADV)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): advanced link mode not enabled\n", __func__);
+ "%s(): advanced link mode not enabled", __func__);
return (-1);
}
c = libnet_write_link(l, packet, packet_s);
@@ -120,7 +120,7 @@ libnet_adv_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t packet_s)
if (l->injection_type != LIBNET_RAW4_ADV)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): advanced raw4 mode not enabled\n", __func__);
+ "%s(): advanced raw4 mode not enabled", __func__);
return (-1);
}
c = libnet_write_raw_ipv4(l, packet, packet_s);
diff --git a/libnet/src/libnet_build_arp.c b/libnet/src/libnet_build_arp.c
index e1ad91d..5c06dae 100644
--- a/libnet/src/libnet_build_arp.c
+++ b/libnet/src/libnet_build_arp.c
@@ -124,7 +124,7 @@ uint8_t *tpa, libnet_t *l)
default:
hrd = 0;
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): unsupported link type\n", __func__);
+ "%s(): unsupported link type", __func__);
return (-1);
/* add other link-layers */
}
diff --git a/libnet/src/libnet_build_dhcp.c b/libnet/src/libnet_build_dhcp.c
index fa16c45..0fc49fa 100644
--- a/libnet/src/libnet_build_dhcp.c
+++ b/libnet/src/libnet_build_dhcp.c
@@ -100,7 +100,7 @@ libnet_t *l, libnet_ptag_t ptag)
if (payload_s && !payload)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): payload inconsistency\n", __func__);
+ "%s(): payload inconsistency", __func__);
goto bad;
}
diff --git a/libnet/src/libnet_build_gre.c b/libnet/src/libnet_build_gre.c
index 0790295..6599aba 100644
--- a/libnet/src/libnet_build_gre.c
+++ b/libnet/src/libnet_build_gre.c
@@ -325,7 +325,7 @@ libnet_ptag_t ptag)
if ((routing && !length) || (!routing && length))
{
- sprintf(l->err_buf, "%s(): routing inconsistency\n", __func__);
+ sprintf(l->err_buf, "%s(): routing inconsistency", __func__);
goto bad;
}
diff --git a/libnet/src/libnet_build_hsrp.c b/libnet/src/libnet_build_hsrp.c
index f11af33..a73cfd2 100644
--- a/libnet/src/libnet_build_hsrp.c
+++ b/libnet/src/libnet_build_hsrp.c
@@ -77,7 +77,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
if (payload_s && !payload)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): payload inconsistency\n", __func__);
+ "%s(): payload inconsistency", __func__);
goto bad;
}
diff --git a/libnet/src/libnet_build_icmp.c b/libnet/src/libnet_build_icmp.c
index 25a753f..1a53df6 100644
--- a/libnet/src/libnet_build_icmp.c
+++ b/libnet/src/libnet_build_icmp.c
@@ -47,7 +47,7 @@ do \
if (payload_s && !payload) \
{ \
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, \
- "%s(): payload inconsistency\n", __func__); \
+ "%s(): payload inconsistency", __func__); \
goto bad; \
} \
\
diff --git a/libnet/src/libnet_build_ip.c b/libnet/src/libnet_build_ip.c
index c75340f..23916ac 100644
--- a/libnet/src/libnet_build_ip.c
+++ b/libnet/src/libnet_build_ip.c
@@ -126,14 +126,14 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
else
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): IPv4 data pblock not found\n", __func__);
+ "%s(): IPv4 data pblock not found", __func__);
}
}
if (payload_s && !payload)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): payload inconsistency\n", __func__);
+ "%s(): payload inconsistency", __func__);
goto bad;
}
@@ -335,7 +335,7 @@ libnet_ptag_t ptag)
if (options_s > LIBNET_MAXOPTION_SIZE)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): options list is too large %d\n", __func__, options_s);
+ "%s(): options list is too large %d", __func__, options_s);
return (-1);
}
@@ -425,7 +425,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
if (LIBNET_IPV6_H + payload_s > IP_MAXPACKET)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): IP packet too large\n", __func__);
+ "%s(): IP packet too large", __func__);
return (-1);
}
@@ -491,7 +491,7 @@ libnet_ptag_t ptag)
if (LIBNET_IPV6_FRAG_H + payload_s > IP_MAXPACKET)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): IP packet too large\n", __func__);
+ "%s(): IP packet too large", __func__);
return (-1);
}
@@ -560,7 +560,7 @@ libnet_ptag_t ptag)
if (LIBNET_IPV6_ROUTING_H + payload_s > IP_MAXPACKET)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): IP packet too large\n", __func__);
+ "%s(): IP packet too large", __func__);
return (-1);
}
@@ -628,7 +628,7 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
if (LIBNET_IPV6_DESTOPTS_H + payload_s > IP_MAXPACKET)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): IP packet too large\n", __func__);
+ "%s(): IP packet too large", __func__);
return (-1);
}
@@ -694,7 +694,7 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
if (LIBNET_IPV6_HBHOPTS_H + payload_s > IP_MAXPACKET)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): IP packet too large\n", __func__);
+ "%s(): IP packet too large", __func__);
return (-1);
}
diff --git a/libnet/src/libnet_build_link.c b/libnet/src/libnet_build_link.c
index d2b851c..40cd8b8 100644
--- a/libnet/src/libnet_build_link.c
+++ b/libnet/src/libnet_build_link.c
@@ -52,7 +52,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
l, ptag);
}
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): linktype %d not supported\n", __func__, l->link_type);
+ "%s(): linktype %d not supported", __func__, l->link_type);
return -1;
}
@@ -71,7 +71,7 @@ libnet_autobuild_link(const uint8_t *dst, const uint8_t *oui, uint16_t type, lib
LIBNET_SAP_SNAP, 0x03, org, TOKEN_RING_TYPE_IP, l));
}
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): linktype %d not supported\n", __func__, l->link_type);
+ "%s(): linktype %d not supported", __func__, l->link_type);
return (-1);
}
diff --git a/libnet/src/libnet_build_tcp.c b/libnet/src/libnet_build_tcp.c
index e0c0fcb..2697d28 100644
--- a/libnet/src/libnet_build_tcp.c
+++ b/libnet/src/libnet_build_tcp.c
@@ -49,7 +49,7 @@ libnet_build_tcp(
if (payload_s && !payload)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): payload inconsistency\n", __func__);
+ "%s(): payload inconsistency", __func__);
return -1;
}
@@ -200,7 +200,7 @@ libnet_ptag_t ptag)
if (options_s > LIBNET_MAXOPTION_SIZE)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): options list is too large %d\n", __func__, options_s);
+ "%s(): options list is too large %d", __func__, options_s);
return (-1);
}
diff --git a/libnet/src/libnet_build_token_ring.c b/libnet/src/libnet_build_token_ring.c
index d0c2e0b..03a0f62 100644
--- a/libnet/src/libnet_build_token_ring.c
+++ b/libnet/src/libnet_build_token_ring.c
@@ -50,7 +50,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
!(((l->injection_type) & LIBNET_ADV_MASK)))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): called with non-link layer wire injection primitive\n",
+ "%s(): called with non-link layer wire injection primitive",
__func__);
p = NULL;
goto bad;
@@ -119,7 +119,7 @@ libnet_t *l)
!(((l->injection_type) & LIBNET_ADV_MASK)))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): called with non-link layer wire injection primitive\n",
+ "%s(): called with non-link layer wire injection primitive",
__func__);
p = NULL;
goto bad;
diff --git a/libnet/src/libnet_checksum.c b/libnet/src/libnet_checksum.c
index 1a7b796..01a1dd4 100644
--- a/libnet/src/libnet_checksum.c
+++ b/libnet/src/libnet_checksum.c
@@ -126,7 +126,7 @@ static int check_ip_payload_size(libnet_t*l, const uint8_t *iphdr, int ip_hl, in
if((iphdr+ip_hl+h_len) > end)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): ip payload not inside packet (pktsz %d, iphsz %d, payloadsz %d)\n", func,
+ "%s(): ip payload not inside packet (pktsz %d, iphsz %d, payloadsz %d)", func,
(int)(end - iphdr), ip_hl, h_len);
return -1;
}
@@ -187,7 +187,7 @@ libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const
if(iphdr < beg || (iphdr+sizeof(*iph_p)) > end)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): ipv4 hdr not inside packet (where %d, size %d)\n", __func__,
+ "%s(): ipv4 hdr not inside packet (where %d, size %d)", __func__,
(int)(iphdr-beg), (int)(end-beg));
return -1;
}
@@ -204,7 +204,7 @@ libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const
if((uint8_t*)(ip6h_p+1) > end)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): ipv6 hdr not inside packet\n", __func__);
+ "%s(): ipv6 hdr not inside packet", __func__);
return -1;
}
}
@@ -216,7 +216,7 @@ libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const
if((iphdr+ip_hl) > end)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): ip hdr len not inside packet\n", __func__);
+ "%s(): ip hdr len not inside packet", __func__);
return -1;
}
@@ -373,7 +373,7 @@ libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const
!(fv & (GRE_CSUM|GRE_VERSION_1)))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't compute GRE checksum (wrong flags_ver bits: 0x%x )\n", __func__, fv);
+ "%s(): can't compute GRE checksum (wrong flags_ver bits: 0x%x )", __func__, fv);
return (-1);
}
sum = libnet_in_cksum((uint16_t *)greh_p, h_len);
@@ -489,7 +489,7 @@ libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const
if((iphdr+h_len) > end)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): cdp payload not inside packet\n", __func__);
+ "%s(): cdp payload not inside packet", __func__);
return -1;
}
@@ -512,7 +512,7 @@ libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const
default:
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): unsupported protocol %d\n", __func__, protocol);
+ "%s(): unsupported protocol %d", __func__, protocol);
return (-1);
}
}
diff --git a/libnet/src/libnet_cq.c b/libnet/src/libnet_cq.c
index 7b59aba..6ff5266 100644
--- a/libnet/src/libnet_cq.c
+++ b/libnet/src/libnet_cq.c
@@ -81,14 +81,14 @@ libnet_cq_add(libnet_t *l, char *label)
if (cq_is_wlocked())
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't add, context queue is write locked\n", __func__);
+ "%s(): can't add, context queue is write locked", __func__);
return (-1);
}
/* ensure there is a label */
if (label == NULL)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): empty label\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): empty label",
__func__);
return (-1);
}
@@ -100,7 +100,7 @@ libnet_cq_add(libnet_t *l, char *label)
if (l_cq == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't malloc initial context queue: %s\n",
+ "%s(): can't malloc initial context queue: %s",
__func__, strerror(errno));
return (-1);
}
@@ -131,7 +131,7 @@ libnet_cq_add(libnet_t *l, char *label)
if (l_cq == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't malloc new context queue: %s\n",
+ "%s(): can't malloc new context queue: %s",
__func__, strerror(errno));
return (-1);
}
@@ -163,7 +163,7 @@ libnet_cq_remove(libnet_t *l)
if (l_cq == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't remove from empty context queue\n", __func__);
+ "%s(): can't remove from empty context queue", __func__);
return (NULL);
}
@@ -176,7 +176,7 @@ libnet_cq_remove(libnet_t *l)
if (cq_is_wlocked())
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't remove, context queue is write locked\n",
+ "%s(): can't remove, context queue is write locked",
__func__);
return (NULL);
}
@@ -184,7 +184,7 @@ libnet_cq_remove(libnet_t *l)
if ((p = libnet_cq_find_internal(l)) == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): context not present in context queue\n", __func__);
+ "%s(): context not present in context queue", __func__);
return (NULL);
}
@@ -275,13 +275,13 @@ libnet_cq_dup_check(libnet_t *l, char *label)
if (p->context == l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): context already in context queue\n", __func__);
+ "%s(): context already in context queue", __func__);
return (1);
}
if (strncmp(p->context->label, label, LIBNET_LABEL_SIZE) == 0)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): duplicate label %s\n", __func__, label);
+ "%s(): duplicate label %s", __func__, label);
return (1);
}
}
diff --git a/libnet/src/libnet_if_addr.c b/libnet/src/libnet_if_addr.c
index 9807539..ff4621f 100644
--- a/libnet/src/libnet_if_addr.c
+++ b/libnet/src/libnet_if_addr.c
@@ -55,7 +55,7 @@ libnet_check_iface(libnet_t *l)
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s() socket: %s\n", __func__,
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s() socket: %s", __func__,
strerror(errno));
return (-1);
}
@@ -67,14 +67,14 @@ libnet_check_iface(libnet_t *l)
if (res < 0)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s() ioctl: %s\n", __func__,
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s() ioctl: %s", __func__,
strerror(errno));
}
else
{
if ((ifr.ifr_flags & IFF_UP) == 0)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): %s is down\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): %s is down",
__func__, l->device);
res = -1;
}
@@ -124,7 +124,7 @@ libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, regis
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
{
- snprintf(errbuf, LIBNET_ERRBUF_SIZE, "%s(): socket error: %s\n",
+ snprintf(errbuf, LIBNET_ERRBUF_SIZE, "%s(): socket error: %s",
__func__, strerror(errno));
return (-1);
}
@@ -133,7 +133,7 @@ libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, regis
if ((fp = fopen(PROC_DEV_FILE, "r")) == NULL)
{
snprintf(errbuf, LIBNET_ERRBUF_SIZE,
- "%s(): fopen(proc_dev_file) failed: %s\n", __func__,
+ "%s(): fopen(proc_dev_file) failed: %s", __func__,
strerror(errno));
return (-1);
}
@@ -146,7 +146,7 @@ libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, regis
if(ioctl(fd, SIOCGIFCONF, &ifc) < 0)
{
snprintf(errbuf, LIBNET_ERRBUF_SIZE,
- "%s(): ioctl(SIOCGIFCONF) error: %s\n",
+ "%s(): ioctl(SIOCGIFCONF) error: %s",
__func__, strerror(errno));
#ifdef HAVE_LINUX_PROCFS
fclose(fp);
@@ -218,7 +218,7 @@ libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, regis
if (errno != EADDRNOTAVAIL)
{
snprintf(errbuf, LIBNET_ERRBUF_SIZE,
- "%s(): SIOCGIFADDR: dev=%s: %s\n", __func__, device,
+ "%s(): SIOCGIFADDR: dev=%s: %s", __func__, device,
strerror(errno));
close(fd);
#ifdef HAVE_LINUX_PROCFS
@@ -242,7 +242,7 @@ libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, regis
if ((al->device = strdup(device)) == NULL)
{
snprintf(errbuf, LIBNET_ERRBUF_SIZE,
- "%s(): strdup not enough memory\n", __func__);
+ "%s(): strdup not enough memory", __func__);
#ifdef HAVE_LINUX_PROCFS
fclose(fp);
#endif
@@ -262,7 +262,7 @@ libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, regis
if (ferror(fp))
{
snprintf(errbuf, LIBNET_ERRBUF_SIZE,
- "%s(): ferror: %s\n", __func__, strerror(errno));
+ "%s(): ferror: %s", __func__, strerror(errno));
fclose(fp);
return (-1);
}
@@ -305,7 +305,7 @@ libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev_unused
if (pcap_findalldevs(&devlist, err) == -1)
{
snprintf(errbuf, LIBNET_ERRBUF_SIZE,
- "%s(): error in pcap_findalldevs: %s\n", __func__, err);
+ "%s(): error in pcap_findalldevs: %s", __func__, err);
return (-1);
}
@@ -351,7 +351,6 @@ int
libnet_select_device(libnet_t *l)
{
int c, i;
- char err_buf[LIBNET_ERRBUF_SIZE];
struct libnet_ifaddr_list *address_list, *al;
uint32_t addr;
@@ -376,7 +375,7 @@ libnet_select_device(libnet_t *l)
/*
* Number of interfaces.
*/
- c = libnet_ifaddrlist(&address_list, l->device, err_buf);
+ c = libnet_ifaddrlist(&address_list, l->device, l->err_buf);
if (c < 0)
{
return (-1);
@@ -384,7 +383,7 @@ libnet_select_device(libnet_t *l)
else if (c == 0)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): no network interfaces found\n", __func__);
+ "%s(): no network interface found", __func__);
return (-1);
}
@@ -410,7 +409,7 @@ libnet_select_device(libnet_t *l)
if (i <= 0)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't find interface for IP %s\n", __func__,
+ "%s(): can't find interface for IP %s", __func__,
l->device);
goto bad;
}
diff --git a/libnet/src/libnet_init.c b/libnet/src/libnet_init.c
index c33369c..c00f5a9 100644
--- a/libnet/src/libnet_init.c
+++ b/libnet/src/libnet_init.c
@@ -43,7 +43,7 @@ libnet_init(int injection_type, const char *device, char *err_buf)
if ((WSAStartup(0x0202, &wsaData)) != 0)
{
snprintf(err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): unable to initialize winsock 2\n", __func__);
+ "%s(): unable to initialize winsock 2", __func__);
goto bad;
}
#endif
@@ -51,7 +51,7 @@ libnet_init(int injection_type, const char *device, char *err_buf)
l = (libnet_t *)malloc(sizeof (libnet_t));
if (l == NULL)
{
- snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s\n", __func__,
+ snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s", __func__,
strerror(errno));
goto bad;
}
@@ -101,7 +101,7 @@ libnet_init(int injection_type, const char *device, char *err_buf)
break;
default:
snprintf(err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): unsupported injection type\n", __func__);
+ "%s(): unsupported injection type", __func__);
goto bad;
break;
}
diff --git a/libnet/src/libnet_link_bpf.c b/libnet/src/libnet_link_bpf.c
index 794fbf9..875a8e4 100644
--- a/libnet/src/libnet_link_bpf.c
+++ b/libnet/src/libnet_link_bpf.c
@@ -83,7 +83,7 @@ libnet_bpf_open(char *err_buf)
if (fd == -1)
{
- snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): (%s): %s\n",
+ snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): (%s): %s",
__func__, device, strerror(errno));
}
return (fd);
@@ -108,7 +108,7 @@ libnet_open_link(libnet_t *l)
if (l->device == NULL)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): NULL device\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): NULL device",
__func__);
goto bad;
}
@@ -124,7 +124,7 @@ libnet_open_link(libnet_t *l)
*/
if (ioctl(l->fd, BIOCVERSION, (caddr_t)&bv) < 0)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCVERSION: %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCVERSION: %s",
__func__, strerror(errno));
goto bad;
}
@@ -132,7 +132,7 @@ libnet_open_link(libnet_t *l)
if (bv.bv_major != BPF_MAJOR_VERSION || bv.bv_minor < BPF_MINOR_VERSION)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): kernel bpf filter out of date\n", __func__);
+ "%s(): kernel bpf filter out of date", __func__);
goto bad;
}
@@ -144,7 +144,7 @@ libnet_open_link(libnet_t *l)
if (ioctl(l->fd, BIOCSETIF, (caddr_t)&ifr) == -1)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCSETIF: (%s): %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCSETIF: (%s): %s",
__func__, l->device, strerror(errno));
goto bad;
}
@@ -154,7 +154,7 @@ libnet_open_link(libnet_t *l)
*/
if (ioctl(l->fd, BIOCGDLT, (caddr_t)&v) == -1)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCGDLT: %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCGDLT: %s",
__func__, strerror(errno));
goto bad;
}
@@ -166,7 +166,7 @@ libnet_open_link(libnet_t *l)
#if defined(BIOCGHDRCMPLT) && defined(BIOCSHDRCMPLT) && !(__APPLE__)
if (ioctl(l->fd, BIOCSHDRCMPLT, &spoof_eth_src) == -1)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCSHDRCMPLT: %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCSHDRCMPLT: %s",
__func__, strerror(errno));
goto bad;
}
@@ -245,7 +245,7 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
if (c != size)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %d bytes written (%s)\n", __func__, c, strerror(errno));
+ "%s(): %d bytes written (%s)", __func__, c, strerror(errno));
}
return (c);
}
@@ -285,7 +285,7 @@ libnet_get_hwaddr(libnet_t *l)
if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): sysctl(): %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): sysctl(): %s",
__func__, strerror(errno));
return (NULL);
}
@@ -293,13 +293,13 @@ libnet_get_hwaddr(libnet_t *l)
buf = (int8_t *)malloc(len);
if (buf == NULL)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s",
__func__, strerror(errno));
return (NULL);
}
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): sysctl(): %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): sysctl(): %s",
__func__, strerror(errno));
free(buf);
return (NULL);
diff --git a/libnet/src/libnet_link_dlpi.c b/libnet/src/libnet_link_dlpi.c
index 65c3a46..46323e5 100644
--- a/libnet/src/libnet_link_dlpi.c
+++ b/libnet/src/libnet_link_dlpi.c
@@ -108,46 +108,121 @@ static int get_dlpi_ppa(int, const int8_t *, int, int8_t *);
/* XXX Needed by HP-UX (at least) */
static bpf_u_int32 ctlbuf[MAXDLBUF];
+/* Return a pointer to the last character in 'in' that is not in 's',
+ * or NULL if no such character exists. */
+static char *find_last_not_of(char *in, const char *s)
+{
+ char* cur;
+ cur = in + strlen(in);
+ for(; cur != in; cur--) {
+ if (!strchr(s, *cur)) {
+ break;
+ }
+ }
+ return cur == in ? NULL : cur;
+}
+
+/* Split device into device type and unit number.
+ * Return >0 on success. */
+static int
+dlpi_unit(const char *dev, int *namelen, int *unit)
+{
+ char *p;
+ char *eos;
+ if (!*dev) {
+ return 0;
+ }
+ p = find_last_not_of(dev, "0123456789");
+ if (!p) {
+ return 0;
+ }
+ p++;
+ if (!*p) {
+ return 0;
+ }
+ *unit = strtol(p, NULL, 10);
+ *namelen = p - dev;
+ return 1;
+}
+
+/* Sometimes the network device is at /dev/<ifname>, and sometimes at
+ * /dev/net/<ifname>. Sometimes both. Sometimes with unit number, sometimes
+ * without.
+ * This function tries to find the device, and won't be stopped just because
+ * it tried to open a directory. (e.g. interface net0 would try to open
+ * /dev/net).
+ */
+static int
+try_open_dev(libnet_t *l, const char *dev, int unit)
+{
+ const char *prefixes[] = {
+ DLPI_DEV_PREFIX,
+ "/dev",
+ "/dev/net",
+ "",
+ NULL
+ };
+ int ret;
+ char fullpath[MAXPATHLEN];
+ int cur_prefix;
+
+ for (cur_prefix = 0; prefixes[cur_prefix]; cur_prefix++) {
+ snprintf(fullpath, sizeof(fullpath),
+ "%s/%s", prefixes[cur_prefix], dev);
+ if (0 <= (ret = open(fullpath, O_RDWR))) {
+ return ret;
+ }
+ if (errno != ENOENT && errno != EISDIR) {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s",
+ __func__, fullpath, strerror(errno));
+ return -1;
+ }
+ snprintf(fullpath, sizeof(fullpath),
+ "%s/%s%d", prefixes[cur_prefix], dev, unit);
+ if (0 <= (ret = open(fullpath, O_RDWR))) {
+ return ret;
+ }
+ if (errno != ENOENT && errno != EISDIR) {
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s",
+ __func__, fullpath, strerror(errno));
+ return -1;
+ }
+ }
+ return -1;
+}
int
libnet_open_link(libnet_t *l)
{
register int8_t *cp;
int8_t *eos;
- register int ppa;
+ int ppa;
register dl_info_ack_t *infop;
bpf_u_int32 buf[MAXDLBUF];
- int8_t dname[100];
-#ifndef HAVE_DEV_DLPI
- int8_t dname2[100];
-#endif
+ int namelen;
+ int8_t dname[MAXPATHLEN];
if (l == NULL)
{
return (-1);
}
+ memset(&dname, 0, sizeof(dname));
+
/*
* Determine device and ppa
*/
- cp = strpbrk(l->device, "0123456789");
- if (cp == NULL)
- {
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %s is missing unit number\n", __func__, l->device);
- goto bad;
- }
- ppa = strtol(cp, &eos, 10);
- if (*eos != '\0')
- {
+ if (!dlpi_unit(l->device, &namelen, &ppa)) {
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %s bad unit number\n", __func__, l->device);
+ "%s(): %s has bad device type or unit number",
+ __func__, l->device);
goto bad;
}
+ strncpy(dname, l->device, namelen);
+#ifdef HAVE_DEV_DLPI
if (*(l->device) == '/')
{
- memset(&dname, 0, sizeof(dname));
strncpy(dname, l->device, sizeof(dname) - 1);
dname[sizeof(dname) - 1] = '\0';
}
@@ -155,7 +230,7 @@ libnet_open_link(libnet_t *l)
{
sprintf(dname, "%s/%s", DLPI_DEV_PREFIX, l->device);
}
-#ifdef HAVE_DEV_DLPI
+
/*
* Map network device to /dev/dlpi unit
*/
@@ -164,8 +239,6 @@ libnet_open_link(libnet_t *l)
l->fd = open(cp, O_RDWR);
if (l->fd == -1)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s\n",
- __func__, cp, strerror(errno));
goto bad;
}
@@ -181,45 +254,9 @@ libnet_open_link(libnet_t *l)
/*
* Try device without unit number
*/
- strcpy(dname2, dname);
- cp = strchr(dname, *cp);
- *cp = '\0';
-
- l->fd = open(dname, O_RDWR);
- if (l->fd == -1)
- {
- if (errno != ENOENT)
- {
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s\n",
- __func__, dname, strerror(errno));
- goto bad;
- }
-
- /*
- * Try again with unit number
- */
- l->fd = open(dname2, O_RDWR);
- if (l->fd == -1)
- {
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s\n",
- __func__, dname2, strerror(errno));
- goto bad;
- }
-
- cp = dname2;
- while (*cp && !isdigit((int)*cp))
- {
- cp++;
- }
- if (*cp)
- {
- ppa = atoi(cp);
- }
- else
- /*
- * XXX Assume unit zero
- */
- ppa = 0;
+ l->fd = try_open_dev(l, dname, ppa);
+ if (l->fd == -1) {
+ goto bad;
}
#endif
/*
@@ -275,7 +312,7 @@ libnet_open_link(libnet_t *l)
l->link_offset = 0x16;
break;
default:
- sprintf(l->err_buf, "%s(): unknown mac type 0x%lu\n", __func__,
+ sprintf(l->err_buf, "%s(): unknown mac type 0x%lu", __func__,
(uint32_t) infop->dl_mac_type);
goto bad;
}
@@ -286,7 +323,7 @@ libnet_open_link(libnet_t *l)
*/
if (strioctl(l->fd, DLIOCRAW, 0, NULL) < 0)
{
- sprintf(l->err_buf, "%s(): DLIOCRAW: %s\n", __func__, strerror(errno));
+ sprintf(l->err_buf, "%s(): DLIOCRAW: %s", __func__, strerror(errno));
goto bad;
}
#endif
@@ -313,7 +350,7 @@ int flags)
if (putmsg(fd, &ctl, (struct strbuf *) NULL, flags) < 0)
{
- sprintf(ebuf, "%s(): putmsg \"%s\": %s\n", __func__, what,
+ sprintf(ebuf, "%s(): putmsg \"%s\": %s", __func__, what,
strerror(errno));
return (-1);
}
@@ -334,7 +371,7 @@ recv_ack(int fd, int size, const int8_t *what, int8_t *bufp, int8_t *ebuf)
flags = 0;
if (getmsg(fd, &ctl, (struct strbuf*)NULL, &flags) < 0)
{
- sprintf(ebuf, "%s(): %s getmsg: %s\n", __func__, what, strerror(errno));
+ sprintf(ebuf, "%s(): %s getmsg: %s", __func__, what, strerror(errno));
return (-1);
}
@@ -531,7 +568,7 @@ register int8_t *ebuf)
if (ip->dl_hdw_state == HDW_DEAD)
{
- sprintf(ebuf, "%s: hardware state: DOWN\n", device);
+ sprintf(ebuf, "%s: hardware state: DOWN", device);
return (-1);
}
return ((int)ip->dl_ppa);
@@ -691,7 +728,7 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
if (c == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_write_link(): %d bytes written (%s)\n", c,
+ "libnet_write_link(): %d bytes written (%s)", c,
strerror(errno));
return (-1);
}
@@ -720,7 +757,7 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
if (c == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_write_link: %d bytes written (%s)\n", c,
+ "libnet_write_link: %d bytes written (%s)", c,
strerror(errno));
return (-1);
}
diff --git a/libnet/src/libnet_link_linux.c b/libnet/src/libnet_link_linux.c
index 924c106..054458d 100644
--- a/libnet/src/libnet_link_linux.c
+++ b/libnet/src/libnet_link_linux.c
@@ -141,7 +141,7 @@ libnet_open_link(libnet_t *l)
default:
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "unknown physical layer type 0x%x\n",
+ "unknown physical layer type 0x%x",
ifr.ifr_hwaddr.sa_family);
goto bad;
}
@@ -157,7 +157,7 @@ libnet_open_link(libnet_t *l)
if (setsockopt(l->fd, SOL_SOCKET, SO_BROADCAST, &n, sizeof(n)) == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s: set SO_BROADCAST failed: %s\n",
+ "%s: set SO_BROADCAST failed: %s",
__func__, strerror(errno));
goto bad;
}
@@ -242,7 +242,7 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
if (c != size)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_write_link(): only %d bytes written (%s)\n", c,
+ "libnet_write_link(): only %d bytes written (%s)", c,
strerror(errno));
}
return (c);
@@ -270,7 +270,7 @@ libnet_get_hwaddr(libnet_t *l)
if (libnet_select_device(l) == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_get_hwaddr: can't figure out a device to use\n");
+ "libnet_get_hwaddr: can't figure out a device to use");
return (NULL);
}
}
diff --git a/libnet/src/libnet_link_none.c b/libnet/src/libnet_link_none.c
index d387bc6..8be5fb4 100644
--- a/libnet/src/libnet_link_none.c
+++ b/libnet/src/libnet_link_none.c
@@ -32,7 +32,7 @@
static void nosupport(libnet_t* l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): no link support on this platform\n", __func__);
+ "%s(): no link support on this platform", __func__);
}
int
diff --git a/libnet/src/libnet_link_pf.c b/libnet/src/libnet_link_pf.c
index 0af154c..2b68634 100644
--- a/libnet/src/libnet_link_pf.c
+++ b/libnet/src/libnet_link_pf.c
@@ -56,7 +56,7 @@ libnet_open_link_interface(int8_t *device, int8_t *ebuf)
l->fd = pfopen(device, O_RDWR);
if (l->fd < 0)
{
- sprintf(ebuf, "pf open: %s: %s\n\your system may not be properly configured; see \"man packetfilter(4)\"\n",
+ sprintf(ebuf, "pf open: %s: %s\n\your system may not be properly configured; see \"man packetfilter(4)\"",
device, strerror(errno));
goto bad;
}
@@ -154,7 +154,7 @@ libnet_write_link_layer(struct libnet_link_int *l, const int8_t *device,
if (c != len)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_write_link: %d bytes written (%s)\n", c,
+ "libnet_write_link: %d bytes written (%s)", c,
strerror(errno));
}
return (c);
diff --git a/libnet/src/libnet_link_win32.c b/libnet/src/libnet_link_win32.c
index 390372c..ab68d71 100644
--- a/libnet/src/libnet_link_win32.c
+++ b/libnet/src/libnet_link_win32.c
@@ -62,7 +62,7 @@ libnet_open_link(libnet_t *l)
if (l->device == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): NULL device\n", __func__);
+ "%s(): NULL device", __func__);
return (-1);
}
@@ -74,7 +74,7 @@ libnet_open_link(libnet_t *l)
{
dwErrorCode=GetLastError();
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): unable to open the driver, error Code : %lx\n",
+ "%s(): unable to open the driver, error Code : %lx",
__func__, dwErrorCode);
return (-1);
}
@@ -103,7 +103,7 @@ libnet_open_link(libnet_t *l)
break;
case NdisMediumWan:
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s():, WinPcap has disabled support for Network type (%d)\n",
+ "%s():, WinPcap has disabled support for Network type (%d)",
__func__, IFType.LinkType);
return (-1);
break;
@@ -115,7 +115,7 @@ libnet_open_link(libnet_t *l)
break;
default:
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): network type (%d) is not supported\n",
+ "%s(): network type (%d) is not supported",
__func__, IFType.LinkType);
return (-1);
break;
@@ -125,7 +125,7 @@ libnet_open_link(libnet_t *l)
{
dwErrorCode=GetLastError();
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): unable to determine the network type, error Code : %lx\n",
+ "%s(): unable to determine the network type, error Code : %lx",
__func__, dwErrorCode);
return (-1);
}
@@ -154,8 +154,8 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
if ((lpPacket = PacketAllocatePacket()) == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): failed to allocate the LPPACKET structure\n", __func__);
- return (-1);
+ "%s(): failed to allocate the LPPACKET structure", __func__);
+ return (-1);
}
/* FIXME Packet* arguments aren't const, are they actually modified? That would be a problem, we can't modify our input */
PacketInitPacket(lpPacket, packet, size);
@@ -191,7 +191,7 @@ libnet_get_hwaddr(libnet_t *l)
if (libnet_select_device(l) == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't figure out a device to use\n", __func__);
+ "%s(): can't figure out a device to use", __func__);
return (NULL);
}
}
@@ -200,7 +200,7 @@ libnet_get_hwaddr(libnet_t *l)
if (mac == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): calloc error\n", __func__);
+ "%s(): calloc error", __func__);
return (NULL);
}
@@ -209,7 +209,7 @@ libnet_get_hwaddr(libnet_t *l)
if (OidData == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): OidData is NULL\n", __func__);
+ "%s(): OidData is NULL", __func__);
return(NULL);
}
diff --git a/libnet/src/libnet_pblock.c b/libnet/src/libnet_pblock.c
index a777001..bf2a548 100644
--- a/libnet/src/libnet_pblock.c
+++ b/libnet/src/libnet_pblock.c
@@ -74,7 +74,7 @@ libnet_pblock_probe(libnet_t *l, libnet_ptag_t ptag, uint32_t b_len, uint8_t typ
if (p->buf == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't resize pblock buffer: %s\n", __func__,
+ "%s(): can't resize pblock buffer: %s", __func__,
strerror(errno));
return (NULL);
}
@@ -101,7 +101,7 @@ static void* zmalloc(libnet_t* l, uint32_t size, const char* func)
if(v)
memset(v, 0, size);
else
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s\n", func,
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s", func,
strerror(errno));
return v;
}
@@ -254,7 +254,7 @@ libnet_pblock_find(libnet_t *l, libnet_ptag_t ptag)
}
}
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): couldn't find protocol block\n", __func__);
+ "%s(): couldn't find protocol block", __func__);
return (NULL);
}
@@ -264,14 +264,14 @@ libnet_pblock_append(libnet_t *l, libnet_pblock_t *p, const void *buf, uint32_t
if (len && !buf)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): payload inconsistency\n", __func__);
+ "%s(): payload inconsistency", __func__);
return -1;
}
if (p->copied + len > p->b_len)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): memcpy would overflow buffer\n", __func__);
+ "%s(): memcpy would overflow buffer", __func__);
return (-1);
}
memcpy(p->buf + p->copied, buf, len);
@@ -353,7 +353,7 @@ libnet_pblock_coalesce(libnet_t *l, uint8_t **packet, uint32_t *size)
}
if (*packet == NULL)
{
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s",
__func__, strerror(errno));
return (-1);
}
@@ -380,7 +380,7 @@ libnet_pblock_coalesce(libnet_t *l, uint8_t **packet, uint32_t *size)
(l->pblock_end->type != LIBNET_PBLOCK_802_3_H))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): packet assembly cannot find a layer 2 header\n",
+ "%s(): packet assembly cannot find a layer 2 header",
__func__);
goto err;
}
@@ -389,7 +389,7 @@ libnet_pblock_coalesce(libnet_t *l, uint8_t **packet, uint32_t *size)
if ((l->pblock_end->type != LIBNET_PBLOCK_IPV4_H))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): packet assembly cannot find an IPv4 header\n",
+ "%s(): packet assembly cannot find an IPv4 header",
__func__);
goto err;
}
@@ -398,7 +398,7 @@ libnet_pblock_coalesce(libnet_t *l, uint8_t **packet, uint32_t *size)
if ((l->pblock_end->type != LIBNET_PBLOCK_IPV6_H))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): packet assembly cannot find an IPv6 header\n",
+ "%s(): packet assembly cannot find an IPv6 header",
__func__);
goto err;
}
@@ -406,7 +406,7 @@ libnet_pblock_coalesce(libnet_t *l, uint8_t **packet, uint32_t *size)
default:
/* we should not end up here ever */
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): suddenly the dungeon collapses -- you die\n",
+ "%s(): suddenly the dungeon collapses -- you die",
__func__);
goto err;
break;
diff --git a/libnet/src/libnet_port_list.c b/libnet/src/libnet_port_list.c
index 046cb81..3ba7413 100644
--- a/libnet/src/libnet_port_list.c
+++ b/libnet/src/libnet_port_list.c
@@ -70,7 +70,7 @@ libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list)
if (!valid_token)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_build_plist_chain: illegal token # %d (%c)\n",
+ "libnet_build_plist_chain: illegal token # %d (%c)",
i + 1,
token_list[i]);
*plist = NULL;
@@ -84,7 +84,7 @@ libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list)
if (!(*plist))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_build_plist_chain: malloc %s\n", strerror(errno));
+ "libnet_build_plist_chain: malloc %s", strerror(errno));
*plist = NULL;
return (-1);
}
@@ -99,7 +99,7 @@ libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list)
{
all_lists = all_lists_tmp;
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_build_plist_chain: realloc %s\n", strerror(errno));
+ "libnet_build_plist_chain: realloc %s", strerror(errno));
*plist = NULL;
return(-1);
}
@@ -123,7 +123,7 @@ libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list)
if (!tmp->next)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_build_plist_chain: malloc %s\n", strerror(errno));
+ "libnet_build_plist_chain: malloc %s", strerror(errno));
/*
* XXX - potential memory leak if other nodes are allocated
* but not freed.
diff --git a/libnet/src/libnet_prand.c b/libnet/src/libnet_prand.c
index b5da4c6..f37c435 100644
--- a/libnet/src/libnet_prand.c
+++ b/libnet/src/libnet_prand.c
@@ -50,7 +50,7 @@ libnet_seed_prand(libnet_t *l)
if (gettimeofday(&seed, NULL) == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): cannot gettimeofday\n", __func__);
+ "%s(): cannot gettimeofday", __func__);
return (-1);
}
diff --git a/libnet/src/libnet_raw.c b/libnet/src/libnet_raw.c
index 4f79603..c8cfe16 100644
--- a/libnet/src/libnet_raw.c
+++ b/libnet/src/libnet_raw.c
@@ -85,7 +85,7 @@ libnet_open_raw4(libnet_t *l)
if (l->fd == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): SOCK_RAW allocation failed: %s\n",
+ "%s(): SOCK_RAW allocation failed: %s",
__func__, strerror(errno));
goto bad;
}
@@ -108,7 +108,7 @@ libnet_open_raw4(libnet_t *l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): set IP_HDRINCL failed: %s\n",
+ "%s(): set IP_HDRINCL failed: %s",
__func__, strerror(errno));
goto bad;
}
@@ -127,7 +127,7 @@ libnet_open_raw4(libnet_t *l)
if (getsockopt(l->fd, SOL_SOCKET, SO_SNDBUF, &n, &len) < 0)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): get SO_SNDBUF failed: %s\n",
+ "%s(): get SO_SNDBUF failed: %s",
__func__, strerror(errno));
goto bad;
}
@@ -141,7 +141,7 @@ libnet_open_raw4(libnet_t *l)
break;
}
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): set SO_SNDBUF failed: %s\n",
+ "%s(): set SO_SNDBUF failed: %s",
__func__, strerror(errno));
goto bad;
}
@@ -160,7 +160,7 @@ libnet_open_raw4(libnet_t *l)
if (setsockopt(l->fd, SOL_SOCKET, SO_BROADCAST, nptr, sizeof(n)) == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): set SO_BROADCAST failed: %s\n",
+ "%s(): set SO_BROADCAST failed: %s",
__func__, strerror(errno));
goto bad;
}
@@ -218,7 +218,7 @@ libnet_open_raw6(libnet_t *l)
if (l->fd == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): SOCK_RAW allocation failed: %s\n", __func__,
+ "%s(): SOCK_RAW allocation failed: %s", __func__,
strerror(errno));
goto bad;
}
@@ -227,14 +227,14 @@ libnet_open_raw6(libnet_t *l)
if (setsockopt(l->fd, SOL_SOCKET, SO_BROADCAST, oneptr, sizeof(one)) == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): set SO_BROADCAST failed: %s\n", __func__,
+ "%s(): set SO_BROADCAST failed: %s", __func__,
strerror(errno));
goto bad;
}
if(l->device != NULL)
if(setsockopt(l->fd, SOL_SOCKET, SO_BINDTODEVICE, l->device, strlen(l->device)) == -1) {
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): set SO_BINDTODEVICE failed: %s\n", __func__, strerror(errno));
+ "%s(): set SO_BINDTODEVICE failed: %s", __func__, strerror(errno));
goto bad;
}
diff --git a/libnet/src/libnet_resolve.c b/libnet/src/libnet_resolve.c
index d565f4a..6b9e30f 100644
--- a/libnet/src/libnet_resolve.c
+++ b/libnet/src/libnet_resolve.c
@@ -127,14 +127,14 @@ libnet_name2addr4(libnet_t *l, char *host_name, uint8_t use_name)
if (!(host_ent = gethostbyname(host_name)))
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %s\n", __func__,
+ "%s(): %s", __func__,
#if (_WIN32)
"gethostbyname failure"
#else
/* FIXME doesn't exist on windows, needs WSAGetLastError()/FormatMessage */
hstrerror(h_errno)
#endif
- );
+ );
/* XXX - this is actually 255.255.255.255 */
return (-1);
}
@@ -153,7 +153,7 @@ libnet_name2addr4(libnet_t *l, char *host_name, uint8_t use_name)
if (l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): expecting dots and decimals\n", __func__);
+ "%s(): expecting dots and decimals", __func__);
}
/* XXX - this is actually 255.255.255.255 */
return (-1);
@@ -175,7 +175,7 @@ libnet_name2addr4(libnet_t *l, char *host_name, uint8_t use_name)
if (l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): value greater than 255\n", __func__);
+ "%s(): value greater than 255", __func__);
}
/* XXX - this is actually 255.255.255.255 */
return (-1);
@@ -251,7 +251,7 @@ libnet_name2addr6(libnet_t *l, const char *host_name, uint8_t use_name)
if (l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't resolve IPv6 addresses\n", __func__);
+ "%s(): can't resolve IPv6 addresses", __func__);
}
return (in6addr_error);
#else
@@ -261,7 +261,7 @@ libnet_name2addr6(libnet_t *l, const char *host_name, uint8_t use_name)
sizeof(struct in_addr), AF_INET6, NULL)))
#else
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %s\n", __func__, strerror(errno));
+ "%s(): %s", __func__, strerror(errno));
return (in6addr_error);
#endif
#else
@@ -282,7 +282,7 @@ libnet_name2addr6(libnet_t *l, const char *host_name, uint8_t use_name)
if (l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): can't resolve IPv6 addresses.\n", __func__);
+ "%s(): can't resolve IPv6 addresses.", __func__);
}
return (in6addr_error);
#else
@@ -291,7 +291,7 @@ libnet_name2addr6(libnet_t *l, const char *host_name, uint8_t use_name)
if (l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): invalid IPv6 address\n", __func__);
+ "%s(): invalid IPv6 address", __func__);
}
return (in6addr_error);
}
@@ -318,7 +318,7 @@ libnet_get_ipaddr6(libnet_t *l)
if (getifaddrs(&ifaddr) != 0)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): getifaddrs(): %s\n", __func__, strerror(errno));
+ "%s(): getifaddrs(): %s", __func__, strerror(errno));
return (in6addr_error);
}
@@ -351,7 +351,7 @@ struct libnet_in6_addr
libnet_get_ipaddr6(libnet_t *l)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): not yet Implemented\n", __func__);
+ "%s(): not yet Implemented", __func__);
return (in6addr_error);
}
#endif /* WIN32 */
@@ -374,7 +374,7 @@ libnet_get_ipaddr4(libnet_t *l)
if (fd == -1)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): socket(): %s\n", __func__, strerror(errno));
+ "%s(): socket(): %s", __func__, strerror(errno));
return (-1);
}
@@ -397,7 +397,7 @@ libnet_get_ipaddr4(libnet_t *l)
if (ioctl(fd, SIOCGIFADDR, (int8_t*) &ifr) < 0)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): ioctl(): %s\n", __func__, strerror(errno));
+ "%s(): ioctl(): %s", __func__, strerror(errno));
close(fd);
return (-1);
}
diff --git a/libnet/src/libnet_write.c b/libnet/src/libnet_write.c
index 2417bfd..5c8717c 100644
--- a/libnet/src/libnet_write.c
+++ b/libnet/src/libnet_write.c
@@ -67,7 +67,7 @@ libnet_write(libnet_t *l)
if (len > LIBNET_MAX_PACKET)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): packet is too large (%d bytes)\n",
+ "%s(): packet is too large (%d bytes)",
__func__, len);
goto done;
}
@@ -83,7 +83,7 @@ libnet_write(libnet_t *l)
break;
default:
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): unsuported injection type\n", __func__);
+ "%s(): unsuported injection type", __func__);
goto done;
}
@@ -206,7 +206,7 @@ libnet_win32_write_raw_ipv4(libnet_t *l, const uint8_t *payload, uint32_t payloa
if (packet == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): failed to allocate packet\n", __func__);
+ "%s(): failed to allocate packet", __func__);
return (-1);
}
/* FIXME all the return paths below, except the last, leak 'packet' */
@@ -253,7 +253,7 @@ libnet_win32_write_raw_ipv4(libnet_t *l, const uint8_t *payload, uint32_t payloa
case NdisMediumArcnet878_2:
default:
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): network type (%d) is not supported\n", __func__,
+ "%s(): network type (%d) is not supported", __func__,
type.LinkType);
return (-1);
break;
@@ -263,7 +263,7 @@ libnet_win32_write_raw_ipv4(libnet_t *l, const uint8_t *payload, uint32_t payloa
if ((lpPacket = PacketAllocatePacket()) == NULL)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): failed to allocate the LPPACKET structure\n", __func__);
+ "%s(): failed to allocate the LPPACKET structure", __func__);
return (-1);
}
@@ -361,11 +361,11 @@ libnet_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t size)
{
#if !(__WIN32__)
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %d bytes written (%s)\n", __func__, c,
+ "%s(): %d bytes written (%s)", __func__, c,
strerror(errno));
#else /* __WIN32__ */
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %d bytes written (%d)\n", __func__, c,
+ "%s(): %d bytes written (%d)", __func__, c,
WSAGetLastError());
#endif /* !__WIN32__ */
}
@@ -376,7 +376,7 @@ int
libnet_write_raw_ipv6(libnet_t *l, const uint8_t *packet, uint32_t size)
{
#if defined HAVE_SOLARIS && !defined HAVE_SOLARIS_IPV6
- snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): no IPv6 support\n",
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): no IPv6 support",
__func__, strerror(errno));
return (-1);
}
@@ -402,11 +402,11 @@ libnet_write_raw_ipv6(libnet_t *l, const uint8_t *packet, uint32_t size)
{
#if !(__WIN32__)
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %d bytes written (%s)\n", __func__, c,
+ "%s(): %d bytes written (%s)", __func__, c,
strerror(errno));
#else /* __WIN32__ */
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %d bytes written (%d)\n", __func__, c,
+ "%s(): %d bytes written (%d)", __func__, c,
WSAGetLastError());
#endif /* !__WIN32__ */
}