From 10e81297a713dbf42f6668a4585bc1de6512d696 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 4 Mar 2010 16:44:59 -0800 Subject: Try using the ip_len header field to guess the input buffer's size. --- libnet/src/libnet_checksum.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libnet/src/libnet_checksum.c b/libnet/src/libnet_checksum.c index fcbde5b..a978555 100644 --- a/libnet/src/libnet_checksum.c +++ b/libnet/src/libnet_checksum.c @@ -152,8 +152,18 @@ static int check_ip_payload_size(libnet_t*l, const uint8_t *iphdr, int ip_hl, in int libnet_do_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len) { + uint16_t ip_len = 0; + struct libnet_ipv4_hdr* ip4 = (struct libnet_ipv4_hdr *)iphdr; + struct libnet_ipv6_hdr* ip6 = (struct libnet_ipv6_hdr *)iphdr; + + if(ip4->ip_v == 4) { + ip_len = ntohs(ip4->ip_len); + } else { + ip_len = ntohs(ip6->ip_len); + } + return libnet_inet_checksum(l, iphdr, protocol, h_len, - iphdr, iphdr + LIBNET_IPV4_H + h_len + iphdr, iphdr + ip_len ); } -- cgit v1.2.1