diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2010-03-04 16:44:59 -0800 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2010-03-04 16:44:59 -0800 |
commit | 10e81297a713dbf42f6668a4585bc1de6512d696 (patch) | |
tree | 03f5a7b56a966d26a6e1957a4a3133f3cfb9cf54 | |
parent | b284eda57b691db7384e128a78871ce98f99c159 (diff) | |
download | libnet-10e81297a713dbf42f6668a4585bc1de6512d696.tar.gz |
Try using the ip_len header field to guess the input buffer's size.
-rw-r--r-- | libnet/src/libnet_checksum.c | 12 |
1 files changed, 11 insertions, 1 deletions
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 ); } |