summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac5
-rw-r--r--include/libnet/libnet-macros.h6
-rw-r--r--src/libnet_advanced.c8
-rw-r--r--src/libnet_build_802.1q.c3
-rw-r--r--src/libnet_build_802.1x.c5
-rw-r--r--src/libnet_build_802.2.c7
-rw-r--r--src/libnet_build_802.3.c3
-rw-r--r--src/libnet_build_arp.c17
-rw-r--r--src/libnet_build_bgp.c42
-rw-r--r--src/libnet_build_cdp.c14
-rw-r--r--src/libnet_build_dhcp.c6
-rw-r--r--src/libnet_build_dns.c5
-rw-r--r--src/libnet_build_ethernet.c6
-rw-r--r--src/libnet_build_fddi.c6
-rw-r--r--src/libnet_build_gre.c32
-rw-r--r--src/libnet_build_hsrp.c7
-rw-r--r--src/libnet_build_icmp.c19
-rw-r--r--src/libnet_build_igmp.c3
-rw-r--r--src/libnet_build_ip.c39
-rw-r--r--src/libnet_build_ipsec.c10
-rw-r--r--src/libnet_build_isl.c3
-rw-r--r--src/libnet_build_mpls.c3
-rw-r--r--src/libnet_build_ntp.c3
-rw-r--r--src/libnet_build_ospf.c41
-rw-r--r--src/libnet_build_rip.c3
-rw-r--r--src/libnet_build_rpc.c9
-rw-r--r--src/libnet_build_sebek.c3
-rw-r--r--src/libnet_build_stp.c6
-rw-r--r--src/libnet_build_tcp.c16
-rw-r--r--src/libnet_build_token_ring.c10
-rw-r--r--src/libnet_build_udp.c3
-rw-r--r--src/libnet_build_vrrp.c3
-rw-r--r--src/libnet_if_addr.c8
-rw-r--r--src/libnet_internal.c10
-rw-r--r--src/libnet_link_linux.c6
-rw-r--r--src/libnet_pblock.c7
-rw-r--r--src/libnet_port_list.c3
-rw-r--r--src/libnet_resolve.c2
-rw-r--r--src/libnet_write.c16
39 files changed, 165 insertions, 233 deletions
diff --git a/configure.ac b/configure.ac
index 43328d5..9e7da15 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,7 +54,7 @@ LT_INIT([pic-only])
#
# Check for headers
#
-AC_CHECK_HEADERS([sys/sockio.h])
+AC_CHECK_HEADERS([sys/sockio.h net/if.h sys/ioctl.h])
AC_CHECK_FUNCS([gethostbyname2])
AC_CHECK_FUNCS([getifaddrs])
AC_TYPE_UINT16_T
@@ -180,6 +180,9 @@ AM_CONDITIONAL([ENABLE_SAMPLES], [test "$enable_samples" = "yes"])
# what (not) to do if the user disables shared libraries
AM_CONDITIONAL([COND_SHARED], [test "x$enable_shared" != xno])
+# Enable some extra features.
+CFLAGS="$CFLAGS -D_DEFAULT_SOURCE=1"
+
# Check and set OS specific parameters
AS_CASE([$target_os],
[*linux*], [
diff --git a/include/libnet/libnet-macros.h b/include/libnet/libnet-macros.h
index 81901fe..276e611 100644
--- a/include/libnet/libnet-macros.h
+++ b/include/libnet/libnet-macros.h
@@ -170,9 +170,9 @@ if (payload_s) \
/* context queue macros and constants */
#define LIBNET_LABEL_SIZE 64
#define LIBNET_LABEL_DEFAULT "cardshark"
-#define CQ_LOCK_UNLOCKED (u_int)0x00000000
-#define CQ_LOCK_READ (u_int)0x00000001
-#define CQ_LOCK_WRITE (u_int)0x00000002
+#define CQ_LOCK_UNLOCKED (uint32_t)0x00000000
+#define CQ_LOCK_READ (uint32_t)0x00000001
+#define CQ_LOCK_WRITE (uint32_t)0x00000002
/**
* Provides an interface to iterate through the context queue of libnet
diff --git a/src/libnet_advanced.c b/src/libnet_advanced.c
index b885630..fb22ec6 100644
--- a/src/libnet_advanced.c
+++ b/src/libnet_advanced.c
@@ -81,7 +81,7 @@ libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, uint8_t **header,
int
libnet_adv_write_link(libnet_t *l, const uint8_t *packet, uint32_t packet_s)
{
- int c;
+ ssize_t c;
if (l->injection_type != LIBNET_LINK_ADV)
{
@@ -92,7 +92,7 @@ libnet_adv_write_link(libnet_t *l, const uint8_t *packet, uint32_t packet_s)
c = libnet_write_link(l, packet, packet_s);
/* do statistics */
- if (c == packet_s)
+ if (c == (ssize_t)packet_s)
{
l->stats.packets_sent++;
l->stats.bytes_written += c;
@@ -115,7 +115,7 @@ libnet_adv_write_link(libnet_t *l, const uint8_t *packet, uint32_t packet_s)
int
libnet_adv_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t packet_s)
{
- int c;
+ ssize_t c;
if (l->injection_type != LIBNET_RAW4_ADV)
{
@@ -126,7 +126,7 @@ libnet_adv_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t packet_s)
c = libnet_write_raw_ipv4(l, packet, packet_s);
/* do statistics */
- if (c == packet_s)
+ if (c == (ssize_t)packet_s)
{
l->stats.packets_sent++;
l->stats.bytes_written += c;
diff --git a/src/libnet_build_802.1q.c b/src/libnet_build_802.1q.c
index bcae75b..7d69d11 100644
--- a/src/libnet_build_802.1q.c
+++ b/src/libnet_build_802.1q.c
@@ -67,8 +67,7 @@ const uint8_t* payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
| (vlan_id & LIBNET_802_1Q_VIDMASK));
_802_1q_hdr.vlan_len = htons(len_proto);
- n = libnet_pblock_append(l, p, (uint8_t *)&_802_1q_hdr, LIBNET_802_1Q_H);
- if (n == (uint32_t)-1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&_802_1q_hdr, LIBNET_802_1Q_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_802.1x.c b/src/libnet_build_802.1x.c
index 4f78ea1..31c74e6 100644
--- a/src/libnet_build_802.1x.c
+++ b/src/libnet_build_802.1x.c
@@ -63,12 +63,11 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
dot1x_hdr.dot1x_type = eap_type;
dot1x_hdr.dot1x_length = htons(length);
- n = libnet_pblock_append(l, p, (uint8_t *)&dot1x_hdr, LIBNET_802_1X_H);
- if (n == (uint32_t)-1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&dot1x_hdr, LIBNET_802_1X_H) == -1)
{
goto bad;
}
-
+
LIBNET_DO_PAYLOAD(l, p);
return (ptag ? ptag : libnet_pblock_update(l, p, h,
diff --git a/src/libnet_build_802.2.c b/src/libnet_build_802.2.c
index 7d1be2e..d6ef92d 100644
--- a/src/libnet_build_802.2.c
+++ b/src/libnet_build_802.2.c
@@ -63,8 +63,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
_802_2_hdr.llc_ssap = ssap;
_802_2_hdr.llc_control = control;
- n = libnet_pblock_append(l, p, (uint8_t *)&_802_2_hdr, LIBNET_802_2_H);
- if (n == (uint32_t)-1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&_802_2_hdr,
+ LIBNET_802_2_H) == -1)
{
goto bad;
}
@@ -113,8 +113,7 @@ libnet_t *l, libnet_ptag_t ptag)
memcpy(_802_2_hdr.snap_oui, oui, 3);
_802_2_hdr.snap_type = htons(type);
- n = libnet_pblock_append(l, p, (uint8_t *)&_802_2_hdr, LIBNET_802_2SNAP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&_802_2_hdr, LIBNET_802_2SNAP_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_802.3.c b/src/libnet_build_802.3.c
index 9b2d20d..02743b2 100644
--- a/src/libnet_build_802.3.c
+++ b/src/libnet_build_802.3.c
@@ -63,8 +63,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
memcpy(_802_3_hdr._802_3_shost, src, ETHER_ADDR_LEN); /* src address */
_802_3_hdr._802_3_len = htons(len); /* packet length */
- n = libnet_pblock_append(l, p, (uint8_t *)&_802_3_hdr, LIBNET_802_3_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&_802_3_hdr, LIBNET_802_3_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_arp.c b/src/libnet_build_arp.c
index 7a0ee74..61e61cb 100644
--- a/src/libnet_build_arp.c
+++ b/src/libnet_build_arp.c
@@ -67,32 +67,27 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
arp_hdr.ar_pln = pln; /* protocol address length */
arp_hdr.ar_op = htons(op); /* opcode command */
- n = libnet_pblock_append(l, p, (uint8_t *)&arp_hdr, LIBNET_ARP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&arp_hdr, LIBNET_ARP_H) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
}
- n = libnet_pblock_append(l, p, sha, hln);
- if (n == -1)
+ if (libnet_pblock_append(l, p, sha, hln) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
}
- n = libnet_pblock_append(l, p, spa, pln);
- if (n == -1)
+ if (libnet_pblock_append(l, p, spa, pln) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
}
- n = libnet_pblock_append(l, p, tha, hln);
- if (n == -1)
+ if (libnet_pblock_append(l, p, tha, hln) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
}
- n = libnet_pblock_append(l, p, tpa, pln);
- if (n == -1)
+ if (libnet_pblock_append(l, p, tpa, pln) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -111,7 +106,7 @@ libnet_ptag_t
libnet_autobuild_arp(uint16_t op, const uint8_t *sha, const uint8_t *spa, const uint8_t *tha,
const uint8_t *tpa, libnet_t *l)
{
- u_short hrd;
+ uint16_t hrd;
switch (l->link_type)
{
diff --git a/src/libnet_build_bgp.c b/src/libnet_build_bgp.c
index db8ea56..bd01a31 100644
--- a/src/libnet_build_bgp.c
+++ b/src/libnet_build_bgp.c
@@ -64,8 +64,7 @@ libnet_t *l, libnet_ptag_t ptag)
bgp4_hdr.len = htons(len);
bgp4_hdr.type = type;
- n = libnet_pblock_append(l, p, (uint8_t *)&bgp4_hdr, LIBNET_BGP4_HEADER_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&bgp4_hdr, LIBNET_BGP4_HEADER_H) == -1)
{
goto bad;
}
@@ -108,35 +107,30 @@ libnet_t *l, libnet_ptag_t ptag)
}
/* for memory alignment reason, we need to append each field separately */
- n = libnet_pblock_append(l, p, (uint8_t *)&version, sizeof (version));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&version, sizeof (version)) == -1)
{
goto bad;
}
val = htons(src_as);
- n = libnet_pblock_append(l, p, (uint8_t *)&val, sizeof(src_as));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&val, sizeof(src_as)) == -1)
{
goto bad;
}
val = htons(hold_time);
- n = libnet_pblock_append(l, p, (uint8_t *)&val, sizeof(hold_time));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&val, sizeof(hold_time)) == -1)
{
goto bad;
}
n = htonl(bgp_id);
- n = libnet_pblock_append(l, p, (uint8_t *)&n, sizeof(bgp_id));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&n, sizeof(bgp_id)) == -1)
{
goto bad;
}
- n = libnet_pblock_append(l, p, (uint8_t *)&opt_len, sizeof(opt_len));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&opt_len, sizeof(opt_len)) == -1)
{
goto bad;
}
@@ -185,34 +179,30 @@ libnet_t *l, libnet_ptag_t ptag)
/* for memory alignment reason, we need to append each field separately */
length = htons(unfeasible_rt_len);
- n = libnet_pblock_append(l, p, (uint8_t *)&length,
- sizeof (unfeasible_rt_len));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&length,
+ sizeof (unfeasible_rt_len)) == -1)
{
goto bad;
}
if (unfeasible_rt_len && withdrawn_rt)
{
- n = libnet_pblock_append(l, p, withdrawn_rt, unfeasible_rt_len);
- if (n == -1)
+ if (libnet_pblock_append(l, p, withdrawn_rt, unfeasible_rt_len) == -1)
{
goto bad;
}
}
length = htons(total_path_attr_len);
- n = libnet_pblock_append(l, p, (uint8_t *)&length,
- sizeof (total_path_attr_len));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&length,
+ sizeof (total_path_attr_len)) == -1)
{
goto bad;
}
if (total_path_attr_len && path_attributes)
{
- n = libnet_pblock_append(l, p, path_attributes, total_path_attr_len);
- if (n == -1)
+ if (libnet_pblock_append(l, p, path_attributes, total_path_attr_len) == -1)
{
goto bad;
}
@@ -220,8 +210,7 @@ libnet_t *l, libnet_ptag_t ptag)
if (info_len && reachability_info)
{
- n = libnet_pblock_append(l, p, reachability_info, info_len);
- if (n == -1)
+ if (libnet_pblock_append(l, p, reachability_info, info_len) == -1)
{
goto bad;
}
@@ -267,9 +256,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
bgp4_hdr.err_code = err_code;
bgp4_hdr.err_subcode = err_subcode;
- n = libnet_pblock_append(l, p, (uint8_t *)&bgp4_hdr,
- LIBNET_BGP4_NOTIFICATION_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&bgp4_hdr,
+ LIBNET_BGP4_NOTIFICATION_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_cdp.c b/src/libnet_build_cdp.c
index 9f5c960..fea9e35 100644
--- a/src/libnet_build_cdp.c
+++ b/src/libnet_build_cdp.c
@@ -66,14 +66,12 @@ libnet_t *l, libnet_ptag_t ptag)
cdp_hdr.cdp_type = htons(type);
cdp_hdr.cdp_len = htons(len + 4); /* 4 bytes for len and type */
- n = libnet_pblock_append(l, p, (uint8_t *)&cdp_hdr, LIBNET_CDP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&cdp_hdr, LIBNET_CDP_H) == -1)
{
goto bad;
}
- n = libnet_pblock_append(l, p, value, len);
- if (n == -1)
+ if (libnet_pblock_append(l, p, value, len) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -103,7 +101,6 @@ int
libnet_build_cdp_value(uint16_t type, uint16_t len, uint8_t *value, libnet_t *l,
libnet_ptag_t ptag)
{
- uint32_t n;
libnet_pblock_t *p;
struct libnet_cdp_value_hdr cdp_value_hdr;
@@ -152,14 +149,13 @@ libnet_build_cdp_value(uint16_t type, uint16_t len, uint8_t *value, libnet_t *l,
break;
}
- n = libnet_pblock_append(l, p, (uint8_t *)&cdp_value_hdr, LIBNET_CDP_VALUE_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&cdp_value_hdr,
+ LIBNET_CDP_VALUE_H) == -1)
{
return (-1);
}
- n = libnet_pblock_append(l, p, value, len);
- if (n == -1)
+ if (libnet_pblock_append(l, p, value, len) == -1)
{
/* err msg set in libnet_pblock_append() */
return (-1);
diff --git a/src/libnet_build_dhcp.c b/src/libnet_build_dhcp.c
index 735594f..d15840b 100644
--- a/src/libnet_build_dhcp.c
+++ b/src/libnet_build_dhcp.c
@@ -91,8 +91,7 @@ libnet_t *l, libnet_ptag_t ptag)
}
dhcp_hdr.dhcp_magic = htonl(DHCP_MAGIC);
- n = libnet_pblock_append(l, p, (uint8_t *)&dhcp_hdr, LIBNET_DHCPV4_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&dhcp_hdr, LIBNET_DHCPV4_H) == -1)
{
goto bad;
}
@@ -106,8 +105,7 @@ libnet_t *l, libnet_ptag_t ptag)
if (payload_s)
{
- n = libnet_pblock_append(l, p, payload, payload_s);
- if (n == -1)
+ if (libnet_pblock_append(l, p, payload, payload_s) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_dns.c b/src/libnet_build_dns.c
index 5d42082..66519e2 100644
--- a/src/libnet_build_dns.c
+++ b/src/libnet_build_dns.c
@@ -77,7 +77,7 @@ libnet_build_dnsv4(uint16_t h_len, uint16_t id, uint16_t flags,
* anyway.
*/
memset(&dns_hdr, 0, sizeof(dns_hdr));
- dns_hdr.h_len = htons((u_short)(n - sizeof (dns_hdr.h_len)));
+ dns_hdr.h_len = htons((uint16_t)(n - sizeof (dns_hdr.h_len)));
dns_hdr.id = htons(id);
dns_hdr.flags = htons(flags);
dns_hdr.num_q = htons(num_q);
@@ -91,8 +91,7 @@ libnet_build_dnsv4(uint16_t h_len, uint16_t id, uint16_t flags,
* but not in UDP packets. As they are the first 2 bytes of the header,
* they are skipped if the packet is UDP...
*/
- n = libnet_pblock_append(l, p, ((uint8_t *)&dns_hdr) + offset, h_len);
- if (n == -1)
+ if (libnet_pblock_append(l, p, ((uint8_t *)&dns_hdr) + offset, h_len) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_ethernet.c b/src/libnet_build_ethernet.c
index 2715f58..005c602 100644
--- a/src/libnet_build_ethernet.c
+++ b/src/libnet_build_ethernet.c
@@ -74,8 +74,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
memcpy(eth_hdr.ether_shost, src, ETHER_ADDR_LEN); /* source address */
eth_hdr.ether_type = htons(type); /* packet type */
- n = libnet_pblock_append(l, p, (uint8_t *)&eth_hdr, LIBNET_ETH_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&eth_hdr, LIBNET_ETH_H) == -1)
{
goto bad;
}
@@ -139,8 +138,7 @@ libnet_autobuild_ethernet(const uint8_t *dst, uint16_t type, libnet_t *l)
memcpy(eth_hdr.ether_shost, src, ETHER_ADDR_LEN); /* source address */
eth_hdr.ether_type = htons(type); /* packet type */
- n = libnet_pblock_append(l, p, (uint8_t *)&eth_hdr, LIBNET_ETH_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&eth_hdr, LIBNET_ETH_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_fddi.c b/src/libnet_build_fddi.c
index 9299ce1..a3fa121 100644
--- a/src/libnet_build_fddi.c
+++ b/src/libnet_build_fddi.c
@@ -83,8 +83,7 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
protocol_type = htons(type);
memcpy(&fddi_hdr.fddi_type, &protocol_type, sizeof(int16_t)); /* Protocol Type */
- n = libnet_pblock_append(l, p, (uint8_t *)&fddi_hdr, LIBNET_FDDI_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&fddi_hdr, LIBNET_FDDI_H) == -1)
{
goto bad;
}
@@ -157,8 +156,7 @@ uint8_t cf, const uint8_t *org, uint16_t type, libnet_t *l)
protocol_type = htons(type);
memcpy(&fddi_hdr.fddi_type, &protocol_type, sizeof(int16_t));
- n = libnet_pblock_append(l, p, (uint8_t *)&fddi_hdr, LIBNET_FDDI_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&fddi_hdr, LIBNET_FDDI_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_gre.c b/src/libnet_build_gre.c
index 35c36f2..a60ddd8 100644
--- a/src/libnet_build_gre.c
+++ b/src/libnet_build_gre.c
@@ -192,8 +192,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
gre_hdr.flags_ver = htons(fv);
gre_hdr.type = htons(type);
- n = libnet_pblock_append(l, p, (uint8_t *)&gre_hdr, LIBNET_GRE_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&gre_hdr, LIBNET_GRE_H) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -203,17 +202,15 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
(fv & GRE_VERSION_MASK)) /* v1 */
{
sum = htons(sum);
- n = libnet_pblock_append(l, p, (uint8_t*)&sum,
- sizeof(gre_hdr.gre_sum));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t*)&sum,
+ sizeof(gre_hdr.gre_sum)) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
}
offset = htons(offset);
- n = libnet_pblock_append(l, p, (uint8_t*)&offset,
- sizeof(gre_hdr.gre_offset));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t*)&offset,
+ sizeof(gre_hdr.gre_offset)) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -224,9 +221,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
( (fv & GRE_VERSION_MASK) && (fv & GRE_SEQ)) ) /* v1 */
{
key = htonl(key);
- n = libnet_pblock_append(l, p, (uint8_t*)&key,
- sizeof(gre_hdr.gre_key));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t*)&key,
+ sizeof(gre_hdr.gre_key)) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -237,9 +233,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
( (fv & GRE_VERSION_MASK) && (fv & GRE_ACK)) ) /* v1 */
{
seq = htonl(seq);
- n = libnet_pblock_append(l, p, (uint8_t*)&seq,
- sizeof(gre_hdr.gre_seq));
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t*)&seq,
+ sizeof(gre_hdr.gre_seq)) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -316,8 +311,7 @@ libnet_ptag_t ptag)
sre_hdr.af = htons(af);
sre_hdr.sre_offset = offset;
sre_hdr.sre_length = length;
- n = libnet_pblock_append(l, p, (uint8_t *)&sre_hdr, LIBNET_GRE_SRE_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&sre_hdr, LIBNET_GRE_SRE_H) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -332,8 +326,7 @@ libnet_ptag_t ptag)
if (routing && length)
{
- n = libnet_pblock_append(l, p, routing, length);
- if (n == -1)
+ if (libnet_pblock_append(l, p, routing, length) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
@@ -375,8 +368,7 @@ libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t ptag)
return (-1);
}
- n = libnet_pblock_append(l, p, (uint8_t *)&zero, LIBNET_GRE_SRE_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&zero, LIBNET_GRE_SRE_H) == -1)
{
/* err msg set in libnet_pblock_append() */
goto bad;
diff --git a/src/libnet_build_hsrp.c b/src/libnet_build_hsrp.c
index 41b3c7d..cd3d044 100644
--- a/src/libnet_build_hsrp.c
+++ b/src/libnet_build_hsrp.c
@@ -37,7 +37,6 @@ uint8_t hello_time, uint8_t hold_time, uint8_t priority, uint8_t group,
uint8_t reserved, uint8_t authdata[HSRP_AUTHDATA_LENGTH], uint32_t virtual_ip,
const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
{
- uint32_t n;
libnet_pblock_t *p;
struct libnet_hsrp_hdr hsrp_hdr;
@@ -68,8 +67,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
memcpy(hsrp_hdr.authdata, authdata, HSRP_AUTHDATA_LENGTH*sizeof(uint8_t));
hsrp_hdr.virtual_ip = virtual_ip;
- n = libnet_pblock_append(l, p, (uint8_t *)&hsrp_hdr, LIBNET_HSRP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&hsrp_hdr, LIBNET_HSRP_H) == -1)
{
goto bad;
}
@@ -83,8 +81,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
if (payload_s)
{
- n = libnet_pblock_append(l, p, payload, payload_s);
- if (n == -1)
+ if (libnet_pblock_append(l, p, payload, payload_s) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_icmp.c b/src/libnet_build_icmp.c
index 366121c..1352ad9 100644
--- a/src/libnet_build_icmp.c
+++ b/src/libnet_build_icmp.c
@@ -38,8 +38,7 @@
#define LIBNET_BUILD_ICMP_ERR_FINISH(len) \
do \
{ \
- n = libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, len); \
- if (n == -1) \
+ if (libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, len) == -1) \
{ \
goto bad; \
} \
@@ -47,14 +46,13 @@ do \
if (payload_s && !payload) \
{ \
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, \
- "%s(): payload inconsistency", __func__); \
+ "%s(): payload inconsistency", __func__); \
goto bad; \
} \
\
if (payload_s) \
{ \
- n = libnet_pblock_append(l, p, payload, payload_s); \
- if (n == -1) \
+ if (libnet_pblock_append(l, p, payload, payload_s) == -1) \
{ \
goto bad; \
} \
@@ -100,8 +98,7 @@ libnet_t *l, libnet_ptag_t ptag)
icmp_hdr.icmp_id = htons(id); /* packet id */
icmp_hdr.icmp_seq = htons(seq); /* packet seq */
- n = libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, LIBNET_ICMPV4_ECHO_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, LIBNET_ICMPV4_ECHO_H) == -1)
{
goto bad;
}
@@ -160,8 +157,8 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
icmp_hdr.icmp_seq = htons(seq); /* packet seq */
icmp_hdr.icmp_mask = htonl(mask); /* address mask */
- n = libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, LIBNET_ICMPV4_MASK_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr,
+ LIBNET_ICMPV4_MASK_H) == -1)
{
goto bad;
}
@@ -222,8 +219,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
icmp_hdr.icmp_rtime = htonl(rtime); /* receive timestamp */
icmp_hdr.icmp_ttime = htonl(ttime); /* transmit timestamp */
- n = libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, LIBNET_ICMPV4_TS_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr,
+ LIBNET_ICMPV4_TS_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_igmp.c b/src/libnet_build_igmp.c
index f876df7..6b04ff6 100644
--- a/src/libnet_build_igmp.c
+++ b/src/libnet_build_igmp.c
@@ -64,8 +64,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
igmp_hdr.igmp_sum = (sum ? htons(sum) : 0);
igmp_hdr.igmp_group.s_addr = ip;
- n = libnet_pblock_append(l, p, (uint8_t *)&igmp_hdr, LIBNET_IGMP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&igmp_hdr, LIBNET_IGMP_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_ip.c b/src/libnet_build_ip.c
index e70fb16..971f498 100644
--- a/src/libnet_build_ip.c
+++ b/src/libnet_build_ip.c
@@ -90,8 +90,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
ip_hdr.ip_src.s_addr = src; /* source ip */
ip_hdr.ip_dst.s_addr = dst; /* destination ip */
- n = libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV4_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV4_H) == -1)
{
goto bad;
}
@@ -255,7 +254,7 @@ libnet_autobuild_ipv4(uint16_t len, uint8_t prot, uint32_t dst, libnet_t *l)
h = len; /* header length */
ptag = LIBNET_PTAG_INITIALIZER;
src = libnet_get_ipaddr4(l);
- if (src == -1)
+ if (src == UINT32_MAX)
{
/* err msg set in libnet_get_ipaddr() */
return (-1);
@@ -301,8 +300,7 @@ libnet_autobuild_ipv4(uint16_t len, uint8_t prot, uint32_t dst, libnet_t *l)
ip_hdr.ip_src.s_addr = src; /* source ip */
ip_hdr.ip_dst.s_addr = dst; /* destination ip */
- n = libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV4_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV4_H) == -1)
{
goto bad;
}
@@ -322,7 +320,7 @@ libnet_build_ipv4_options(const uint8_t *options, uint32_t options_s, libnet_t *
libnet_ptag_t ptag)
{
int options_size_increase = 0; /* increase will be negative if it's a decrease */
- uint32_t n, adj_size;
+ uint32_t adj_size;
libnet_pblock_t *p, *p_temp;
struct libnet_ipv4_hdr *ip_hdr;
@@ -371,15 +369,13 @@ libnet_ptag_t ptag)
}
/* append options */
- n = libnet_pblock_append(l, p, options, options_s);
- if (n == -1)
+ if (libnet_pblock_append(l, p, options, options_s) == -1)
{
goto bad;
}
/* append padding */
- n = libnet_pblock_append(l, p, (uint8_t*)"\0\0\0", adj_size - options_s);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t*)"\0\0\0", adj_size - options_s) == -1)
{
goto bad;
}
@@ -450,8 +446,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
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_pblock_append(l, p, (uint8_t *)&ip_hdr, LIBNET_IPV6_H) == -1)
{
goto bad;
}
@@ -514,9 +509,8 @@ libnet_ptag_t ptag)
/*
* Appened the protocol unit to the list.
*/
- n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_frag_hdr,
- LIBNET_IPV6_FRAG_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ipv6_frag_hdr,
+ LIBNET_IPV6_FRAG_H) == -1)
{
goto bad;
}
@@ -583,9 +577,8 @@ libnet_ptag_t ptag)
/*
* Appened the protocol unit to the list.
*/
- n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_routing_hdr,
- LIBNET_IPV6_ROUTING_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ipv6_routing_hdr,
+ LIBNET_IPV6_ROUTING_H) == -1)
{
goto bad;
}
@@ -649,9 +642,8 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
/*
* Appened the protocol unit to the list.
*/
- n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_destopts_hdr,
- LIBNET_IPV6_DESTOPTS_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ipv6_destopts_hdr,
+ LIBNET_IPV6_DESTOPTS_H) == -1)
{
goto bad;
}
@@ -715,9 +707,8 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
/*
* Appened the protocol unit to the list.
*/
- n = libnet_pblock_append(l, p, (uint8_t *)&ipv6_hbhopts_hdr,
- LIBNET_IPV6_HBHOPTS_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ipv6_hbhopts_hdr,
+ LIBNET_IPV6_HBHOPTS_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_ipsec.c b/src/libnet_build_ipsec.c
index 240f8d5..dadfa55 100644
--- a/src/libnet_build_ipsec.c
+++ b/src/libnet_build_ipsec.c
@@ -64,8 +64,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
return (-1);
}
- n = libnet_pblock_append(l, p, (uint8_t *)&esp_hdr, LIBNET_IPSEC_ESP_HDR_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&esp_hdr, LIBNET_IPSEC_ESP_HDR_H) == -1)
{
goto bad;
}
@@ -114,8 +113,8 @@ libnet_build_ipsec_esp_ftr(uint8_t len, uint8_t nh, int8_t *auth,
return (-1);
}
- n = libnet_pblock_append(l, p, (uint8_t *)&esp_ftr, LIBNET_IPSEC_ESP_FTR_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&esp_ftr,
+ LIBNET_IPSEC_ESP_FTR_H) == -1)
{
goto bad;
}
@@ -166,8 +165,7 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
ah_hdr.ah_seq = htonl(seq); /* AH sequence number */
ah_hdr.ah_auth = htonl(auth); /* authentication data */
- n = libnet_pblock_append(l, p, (uint8_t *)&ah_hdr, LIBNET_IPSEC_AH_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ah_hdr, LIBNET_IPSEC_AH_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_isl.c b/src/libnet_build_isl.c
index 24dfb5f..1ec8708 100644
--- a/src/libnet_build_isl.c
+++ b/src/libnet_build_isl.c
@@ -70,8 +70,7 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
isl_hdr.isl_index = htons(portindex);
isl_hdr.isl_reserved= htons(reserved);
- n = libnet_pblock_append(l, p, (uint8_t *)&isl_hdr, LIBNET_ISL_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&isl_hdr, LIBNET_ISL_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_mpls.c b/src/libnet_build_mpls.c
index 2e965be..48b49dc 100644
--- a/src/libnet_build_mpls.c
+++ b/src/libnet_build_mpls.c
@@ -65,8 +65,7 @@ libnet_ptag_t ptag)
((bos & 0x01) << 8) |
((ttl & 0xff))));
- n = libnet_pblock_append(l, p, (uint8_t *)&mpls_hdr, LIBNET_MPLS_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&mpls_hdr, LIBNET_MPLS_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_ntp.c b/src/libnet_build_ntp.c
index 0f217dc..6e82eed 100644
--- a/src/libnet_build_ntp.c
+++ b/src/libnet_build_ntp.c
@@ -83,8 +83,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
ntp_hdr.ntp_xmt_ts.integer = htonl(xmt_ts_int);
ntp_hdr.ntp_xmt_ts.fraction = htonl(xmt_ts_frac);
- n = libnet_pblock_append(l, p, (uint8_t *)&ntp_hdr, LIBNET_NTP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ntp_hdr, LIBNET_NTP_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_ospf.c b/src/libnet_build_ospf.c
index c19f6d8..99da739 100644
--- a/src/libnet_build_ospf.c
+++ b/src/libnet_build_ospf.c
@@ -71,8 +71,7 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
ospf_hdr.ospf_sum = sum;
ospf_hdr.ospf_auth_type = htons(autype); /* Type of auth */
- n = libnet_pblock_append(l, p, (uint8_t *)&ospf_hdr, LIBNET_OSPF_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&ospf_hdr, LIBNET_OSPF_H) == -1)
{
goto bad;
}
@@ -143,8 +142,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
hello_hdr.hello_bkup_rtr.s_addr = bkup_rtr; /* Networks backup router */
hello_hdr.hello_nbr.s_addr = htonl(neighbor);
- n = libnet_pblock_append(l, p, (uint8_t *)&hello_hdr, LIBNET_OSPF_HELLO_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&hello_hdr, LIBNET_OSPF_HELLO_H) == -1)
{
goto bad;
}
@@ -192,8 +190,8 @@ libnet_ptag_t ptag)
dbd_hdr.dbd_type = type; /* Type of exchange occuring */
dbd_hdr.dbd_seq = htonl(seqnum); /* DBD sequence number */
- n = libnet_pblock_append(l, p, (uint8_t *)&dbd_hdr, LIBNET_OSPF_DBD_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&dbd_hdr,
+ LIBNET_OSPF_DBD_H) == -1)
{
goto bad;
}
@@ -240,8 +238,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
lsr_hdr.lsr_lsid = htonl(lsid); /* Link State ID */
lsr_hdr.lsr_adrtr.s_addr = htonl(advrtr); /* Advertising router */
- n = libnet_pblock_append(l, p, (uint8_t *)&lsr_hdr, LIBNET_OSPF_LSR_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&lsr_hdr,
+ LIBNET_OSPF_LSR_H) == -1)
{
goto bad;
}
@@ -286,8 +284,7 @@ libnet_t *l, libnet_ptag_t ptag)
memset(&lh_hdr, 0, sizeof(lh_hdr));
lh_hdr.lsu_num = htonl(num); /* Number of LSAs that will be bcasted */
- n = libnet_pblock_append(l, p, (uint8_t *)&lh_hdr, LIBNET_OSPF_LSU_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&lh_hdr, LIBNET_OSPF_LSU_H) == -1)
{
goto bad;
}
@@ -340,8 +337,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
lsa_hdr.lsa_sum = sum;
lsa_hdr.lsa_len = htons(h);
- n = libnet_pblock_append(l, p, (uint8_t *)&lsa_hdr, LIBNET_OSPF_LSA_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&lsa_hdr,
+ LIBNET_OSPF_LSA_H) == -1)
{
goto bad;
}
@@ -402,9 +399,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
rtr_lsa_hdr.rtr_tos_num = tos;
rtr_lsa_hdr.rtr_metric = htons(metric);
- n = libnet_pblock_append(l, p, (uint8_t *)&rtr_lsa_hdr,
- LIBNET_OSPF_LS_RTR_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&rtr_lsa_hdr,
+ LIBNET_OSPF_LS_RTR_H) == -1)
{
goto bad;
}
@@ -450,9 +446,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
net_lsa_hdr.net_nmask.s_addr = htonl(nmask);
net_lsa_hdr.net_rtr_id = htonl(rtrid);
- n = libnet_pblock_append(l, p, (uint8_t *)&net_lsa_hdr,
- LIBNET_OSPF_LS_NET_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&net_lsa_hdr,
+ LIBNET_OSPF_LS_NET_H) == -1)
{
goto bad;
}
@@ -499,9 +494,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
sum_lsa_hdr.sum_metric = htonl(metric);
sum_lsa_hdr.sum_tos_metric = htonl(tos);
- n = libnet_pblock_append(l, p, (uint8_t *)&sum_lsa_hdr,
- LIBNET_OSPF_LS_SUM_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&sum_lsa_hdr,
+ LIBNET_OSPF_LS_SUM_H) == -1)
{
goto bad;
}
@@ -550,9 +544,8 @@ libnet_ptag_t ptag)
as_lsa_hdr.as_fwd_addr.s_addr = htonl(fwdaddr);
as_lsa_hdr.as_rte_tag = htonl(tag);
- n = libnet_pblock_append(l, p, (uint8_t *)&as_lsa_hdr,
- LIBNET_OSPF_LS_AS_EXT_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&as_lsa_hdr,
+ LIBNET_OSPF_LS_AS_EXT_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_rip.c b/src/libnet_build_rip.c
index 41c0b4d..d38ea64 100644
--- a/src/libnet_build_rip.c
+++ b/src/libnet_build_rip.c
@@ -71,8 +71,7 @@ libnet_ptag_t ptag)
rip_hdr.rip_next_hop = next_hop;
rip_hdr.rip_metric = htonl(metric);
- n = libnet_pblock_append(l, p, (uint8_t *)&rip_hdr, LIBNET_RIP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&rip_hdr, LIBNET_RIP_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_rpc.c b/src/libnet_build_rpc.c
index 90cb157..862b23b 100644
--- a/src/libnet_build_rpc.c
+++ b/src/libnet_build_rpc.c
@@ -41,6 +41,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
uint32_t n, h;
libnet_pblock_t *p;
struct libnet_rpc_call_tcp_hdr rpc_hdr;
+ int rc;
if (l == NULL)
{
@@ -91,16 +92,16 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
if (rm)
{
- n = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr,
- LIBNET_RPC_CALL_TCP_H);
+ rc = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr,
+ LIBNET_RPC_CALL_TCP_H);
}
else
{
- n = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr.rpc_common,
+ rc = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr.rpc_common,
LIBNET_RPC_CALL_H);
}
- if (n == -1)
+ if (rc == -1)
{
goto bad;
}
diff --git a/src/libnet_build_sebek.c b/src/libnet_build_sebek.c
index 6463750..aa41ecd 100644
--- a/src/libnet_build_sebek.c
+++ b/src/libnet_build_sebek.c
@@ -71,8 +71,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
memcpy(sebek_hdr.cmd, cmd, SEBEK_CMD_LENGTH*sizeof(uint8_t));
sebek_hdr.length = htonl(length);
- n = libnet_pblock_append(l, p, (uint8_t *)&sebek_hdr, LIBNET_SEBEK_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&sebek_hdr, LIBNET_SEBEK_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_stp.c b/src/libnet_build_stp.c
index d99edbc..3557b76 100644
--- a/src/libnet_build_stp.c
+++ b/src/libnet_build_stp.c
@@ -121,8 +121,7 @@ uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
/* until we get some data marshalling in place we can't use this */
/*n = libnet_pblock_append(l, p, (uint8_t *)&stp_hdr, LIBNET_STP_CONF_H); */
- n = libnet_pblock_append(l, p, stp_hdr, LIBNET_STP_CONF_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, stp_hdr, LIBNET_STP_CONF_H) == -1)
{
goto bad;
}
@@ -170,8 +169,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
stp_hdr.stp_version = version;
stp_hdr.stp_bpdu_type = bpdu_type;
- n = libnet_pblock_append(l, p, (uint8_t *)&stp_hdr, LIBNET_STP_TCN_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&stp_hdr, LIBNET_STP_TCN_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_tcp.c b/src/libnet_build_tcp.c
index d5724ec..71ff09f 100644
--- a/src/libnet_build_tcp.c
+++ b/src/libnet_build_tcp.c
@@ -38,7 +38,7 @@ libnet_build_tcp(
uint8_t control, uint16_t win, uint16_t sum, uint16_t urg, uint16_t h_len,
const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
{
- int n, offset;
+ int offset;
libnet_pblock_t *p = NULL;
libnet_ptag_t ptag_data = 0;
struct libnet_tcp_hdr tcp_hdr;
@@ -77,8 +77,7 @@ libnet_build_tcp(
tcp_hdr.th_sum = (sum ? htons(sum) : 0); /* checksum */
tcp_hdr.th_urp = htons(urg); /* urgent pointer */
- n = libnet_pblock_append(l, p, (uint8_t *)&tcp_hdr, LIBNET_TCP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&tcp_hdr, LIBNET_TCP_H) == -1)
{
goto bad;
}
@@ -136,8 +135,7 @@ libnet_build_tcp(
goto bad;
}
- n = libnet_pblock_append(l, p_data, payload, payload_s);
- if (n == -1)
+ if (libnet_pblock_append(l, p_data, payload, payload_s) == -1)
{
goto bad;
}
@@ -182,7 +180,7 @@ libnet_build_tcp_options(const uint8_t *options, uint32_t options_s, libnet_t *l
libnet_ptag_t ptag)
{
static const uint8_t padding[] = { 0 };
- int n, offset, underflow;
+ int offset, underflow;
uint32_t i, j, adj_size;
libnet_pblock_t *p, *p_temp;
struct libnet_ipv4_hdr *ip_hdr;
@@ -239,14 +237,12 @@ libnet_ptag_t ptag)
return (-1);
}
- n = libnet_pblock_append(l, p, options, options_s);
- if (n == -1)
+ if (libnet_pblock_append(l, p, options, options_s) == -1)
{
goto bad;
}
- n = libnet_pblock_append(l, p, padding, adj_size - options_s);
- if (n == -1)
+ if (libnet_pblock_append(l, p, padding, adj_size - options_s) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_token_ring.c b/src/libnet_build_token_ring.c
index 3f62d42..bc693fb 100644
--- a/src/libnet_build_token_ring.c
+++ b/src/libnet_build_token_ring.c
@@ -80,9 +80,8 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
memcpy(&token_ring_hdr.token_ring_llc_org_code, org, LIBNET_ORG_CODE_SIZE);
token_ring_hdr.token_ring_type = htons(type);
- n = libnet_pblock_append(l, p, (uint8_t *)&token_ring_hdr,
- LIBNET_TOKEN_RING_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&token_ring_hdr,
+ LIBNET_TOKEN_RING_H) == -1)
{
goto bad;
}
@@ -158,9 +157,8 @@ libnet_t *l)
token_ring_hdr.token_ring_type = htons(type);
- n = libnet_pblock_append(l, p, (uint8_t *)&token_ring_hdr,
- LIBNET_TOKEN_RING_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&token_ring_hdr,
+ LIBNET_TOKEN_RING_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_udp.c b/src/libnet_build_udp.c
index 7071a52..0fd8e4a 100644
--- a/src/libnet_build_udp.c
+++ b/src/libnet_build_udp.c
@@ -63,8 +63,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
udp_hdr.uh_ulen = htons(len); /* total length of UDP packet*/
udp_hdr.uh_sum = (sum ? htons(sum) : 0);/* checksum */
- n = libnet_pblock_append(l, p, (uint8_t *)&udp_hdr, LIBNET_UDP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&udp_hdr, LIBNET_UDP_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_build_vrrp.c b/src/libnet_build_vrrp.c
index 8086edf..5fcfb2e 100644
--- a/src/libnet_build_vrrp.c
+++ b/src/libnet_build_vrrp.c
@@ -70,8 +70,7 @@ libnet_ptag_t ptag)
vrrp_hdr.vrrp_advert_int = advert_int;
vrrp_hdr.vrrp_sum = (sum ? htons(sum) : 0);
- n = libnet_pblock_append(l, p, (uint8_t *)&vrrp_hdr, LIBNET_VRRP_H);
- if (n == -1)
+ if (libnet_pblock_append(l, p, (uint8_t *)&vrrp_hdr, LIBNET_VRRP_H) == -1)
{
goto bad;
}
diff --git a/src/libnet_if_addr.c b/src/libnet_if_addr.c
index 48906e0..18b0a33 100644
--- a/src/libnet_if_addr.c
+++ b/src/libnet_if_addr.c
@@ -36,6 +36,14 @@
#include <sys/sockio.h>
#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+
#include "../include/ifaddrlist.h"
#define MAX_IPADDR 512
diff --git a/src/libnet_internal.c b/src/libnet_internal.c
index 3cee967..10fe20a 100644
--- a/src/libnet_internal.c
+++ b/src/libnet_internal.c
@@ -102,8 +102,8 @@ libnet_diag_dump_context(libnet_t *l)
break;
}
- fprintf(stderr, "pblock start:\t%p\n", l->protocol_blocks);
- fprintf(stderr, "pblock end:\t%p\n", l->pblock_end);
+ fprintf(stderr, "pblock start:\t%p\n", (void*)l->protocol_blocks);
+ fprintf(stderr, "pblock end:\t%p\n", (void*)l->pblock_end);
fprintf(stderr, "link type:\t%d\n", l->link_type);
fprintf(stderr, "link offset:\t%d\n", l->link_offset);
fprintf(stderr, "aligner:\t%d\n", l->aligner);
@@ -128,15 +128,15 @@ libnet_diag_dump_pblock(libnet_t *l)
fprintf(stderr, "pblock type:\t%s\n",
libnet_diag_dump_pblock_type(p->type));
fprintf(stderr, "ptag number:\t%d\n", p->ptag);
- fprintf(stderr, "pblock address:\t%p\n", p);
- fprintf(stderr, "next pblock\t%p ", p->next);
+ fprintf(stderr, "pblock address:\t%p\n", (void*)p);
+ fprintf(stderr, "next pblock\t%p ", (void*)p->next);
if (p->next)
{
fprintf(stderr, "(%s)",
libnet_diag_dump_pblock_type(p->next->type));
}
fprintf(stderr, "\n");
- fprintf(stderr, "prev pblock\t%p ", p->prev);
+ fprintf(stderr, "prev pblock\t%p ", (void*)p->prev);
if (p->prev)
{
fprintf(stderr, "(%s)",
diff --git a/src/libnet_link_linux.c b/src/libnet_link_linux.c
index 84c8124..1e06f70 100644
--- a/src/libnet_link_linux.c
+++ b/src/libnet_link_linux.c
@@ -201,7 +201,7 @@ get_iface_index(int fd, const char *device)
int
libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
{
- int c;
+ ssize_t c;
#if (HAVE_PACKET_SOCKET)
struct sockaddr_ll sa;
#else
@@ -229,10 +229,10 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
c = sendto(l->fd, packet, size, 0,
(struct sockaddr *)&sa, sizeof (sa));
- if (c != size)
+ if (c != (ssize_t)size)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "libnet_write_link(): only %d bytes written (%s)", c,
+ "libnet_write_link(): only %zd bytes written (%s)", c,
strerror(errno));
}
return (c);
diff --git a/src/libnet_pblock.c b/src/libnet_pblock.c
index 9fd015f..fa46d35 100644
--- a/src/libnet_pblock.c
+++ b/src/libnet_pblock.c
@@ -500,10 +500,9 @@ libnet_pblock_coalesce(libnet_t *l, uint8_t **packet, uint32_t *size)
q->ptag, libnet_diag_dump_pblock_type(q->type),
ip_offset);
#endif
- c = libnet_inet_checksum(l, iph,
- libnet_pblock_p2p(q->type), q->h_len,
- beg, end);
- if (c == -1)
+ if (libnet_inet_checksum(l, iph,
+ libnet_pblock_p2p(q->type), q->h_len,
+ beg, end) == -1)
{
/* err msg set in libnet_do_checksum() */
goto err;
diff --git a/src/libnet_port_list.c b/src/libnet_port_list.c
index 9c7c3b6..fff151e 100644
--- a/src/libnet_port_list.c
+++ b/src/libnet_port_list.c
@@ -40,7 +40,8 @@ libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list)
char libnet_plist_legal_tokens[] = "0123456789,- ";
libnet_plist_t *tmp;
char *tok;
- int i, j, valid_token, cur_node;
+ int i, valid_token, cur_node;
+ size_t j;
uint16_t *all_lists_tmp;
static uint8_t cur_id;
diff --git a/src/libnet_resolve.c b/src/libnet_resolve.c
index 23475e6..3fc5f5f 100644
--- a/src/libnet_resolve.c
+++ b/src/libnet_resolve.c
@@ -120,7 +120,7 @@ libnet_name2addr4(libnet_t *l, const char *host_name, uint8_t use_name)
if (use_name == LIBNET_RESOLVE)
{
- if ((addr.s_addr = inet_addr(host_name)) == -1)
+ if ((addr.s_addr = inet_addr(host_name)) == INADDR_NONE)
{
if (!(host_ent = gethostbyname(host_name)))
{
diff --git a/src/libnet_write.c b/src/libnet_write.c
index 8f8107e..fa6ac94 100644
--- a/src/libnet_write.c
+++ b/src/libnet_write.c
@@ -35,7 +35,7 @@
int
libnet_write(libnet_t *l)
{
- int c;
+ uint32_t c;
uint32_t len;
uint8_t *packet = NULL;
@@ -45,7 +45,7 @@ libnet_write(libnet_t *l)
}
c = libnet_pblock_coalesce(l, &packet, &len);
- if (c == - 1)
+ if (c == UINT32_MAX)
{
/* err msg set in libnet_pblock_coalesce() */
return (-1);
@@ -264,7 +264,7 @@ libnet_write_raw_ipv6(libnet_t *l, const uint8_t *packet, uint32_t size)
int
libnet_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t size)
{
- int c;
+ ssize_t c;
struct sockaddr_in sin;
struct libnet_ipv4_hdr *ip_hdr;
@@ -298,10 +298,10 @@ libnet_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t size)
ip_hdr->ip_off = UNFIX(ip_hdr->ip_off);
#endif /* LIBNET_BSD_BYTE_SWAP */
- if (c != size)
+ if (c != (ssize_t)size)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %d bytes written (%s)", __func__, c,
+ "%s(): %zd bytes written (%s)", __func__, c,
strerror(errno));
}
return (c);
@@ -310,7 +310,7 @@ libnet_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t size)
int
libnet_write_raw_ipv6(libnet_t *l, const uint8_t *packet, uint32_t size)
{
- int c = -1;
+ ssize_t c = -1;
#if defined HAVE_SOLARIS && !defined HAVE_SOLARIS_IPV6
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): no IPv6 support",
@@ -332,10 +332,10 @@ libnet_write_raw_ipv6(libnet_t *l, const uint8_t *packet, uint32_t size)
sizeof(ip_hdr->ip_dst.libnet_s6_addr));
c = sendto(l->fd, packet, size, 0, (struct sockaddr *)&sin, sizeof(sin));
- if (c != size)
+ if (c != (ssize_t)size)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
- "%s(): %d bytes written (%s)", __func__, c,
+ "%s(): %zd bytes written (%s)", __func__, c,
strerror(errno));
}
#endif /* HAVE_SOLARIS && !HAVE_SOLARIS_IPV6 */