diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2010-02-22 14:12:42 -0800 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2010-02-22 14:12:42 -0800 |
commit | ef534a4eb3162c3b0b1ed3ea8e12e2d13e6228b5 (patch) | |
tree | 2a25017c32b5d81d0b396065101a155db7077fec | |
parent | 4682fcf892605763d027f9318744dee29797848a (diff) | |
download | libnet-ef534a4eb3162c3b0b1ed3ea8e12e2d13e6228b5.tar.gz |
h_len is calculated for ip, udp, tcp, icmp, and igmp, so is allowed to be zero.
-rw-r--r-- | libnet/src/libnet_checksum.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/libnet/src/libnet_checksum.c b/libnet/src/libnet_checksum.c index 6fd1ff3..c1efd17 100644 --- a/libnet/src/libnet_checksum.c +++ b/libnet/src/libnet_checksum.c @@ -164,12 +164,6 @@ libnet_do_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const u int sum = 0; int is_ipv6 = 0; /* TODO - remove this, it is redundant with ip6h_p */ - if (h_len == 0) - { - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): header length can't be zero\n", __func__); - return -1; - } /* Check for memory under/over reads/writes. */ if(iphdr < beg || (iphdr+sizeof(*iph_p)) > end) { @@ -295,6 +289,8 @@ libnet_do_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const u struct libnet_icmpv4_hdr *icmph_p = (struct libnet_icmpv4_hdr *)(iphdr + ip_hl); + h_len = end - (uint8_t*) icmph_p; /* ignore h_len, sum the packet we've coalesced */ + CHECK_IP_PAYLOAD_SIZE(); icmph_p->icmp_sum = 0; @@ -312,6 +308,8 @@ libnet_do_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const u struct libnet_igmp_hdr *igmph_p = (struct libnet_igmp_hdr *)(iphdr + ip_hl); + h_len = end - (uint8_t*) igmph_p; /* ignore h_len, sum the packet we've coalesced */ + CHECK_IP_PAYLOAD_SIZE(); igmph_p->igmp_sum = 0; |