commit 79089333b4ed433ebca54a2dc1fdcf4a3094be16
parent fc8caba9abf20dc12eb58aa244b52576748652cd
Author: Jordan Ritter <jpr5@darkridge.com>
Date: Wed, 6 Jun 2001 15:12:11 +0000
potential fix for bug in payload length calculation; the pcap_pkthdr
caplen was not being considered
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/ngrep.c b/ngrep.c
@@ -429,7 +429,10 @@ void process(u_char *data1, struct pcap_pkthdr* h, u_char *p) {
}
data = ((char*)tcp) + tcphdr_offset;
- len = ntohs(ip_packet->ip_len) - ip_hl - tcphdr_offset;
+
+ if ((len = ntohs(ip_packet->ip_len)) < h->caplen)
+ len -= ip_hl + tcphdr_offset;
+ else len = h->caplen - link_offset - ip_hl - tcphdr_offset;
if (((len || show_empty) && (((int)(*match_func)(data, len)) != invert_match))
|| keep_matching) {
@@ -480,7 +483,10 @@ void process(u_char *data1, struct pcap_pkthdr* h, u_char *p) {
}
data = ((char*)udp) + udphdr_offset;
- len = ntohs(ip_packet->ip_len) - ip_hl - udphdr_offset;
+
+ if ((len = ntohs(ip_packet->ip_len)) < h->caplen)
+ len -= ip_hl + udphdr_offset;
+ else len = h->caplen - link_offset - ip_hl - udphdr_offset;
if (((len || show_empty) && (((int)(*match_func)(data, len)) != invert_match))
|| keep_matching) {
@@ -529,7 +535,10 @@ void process(u_char *data1, struct pcap_pkthdr* h, u_char *p) {
}
data = ((char*)ic) + icmphdr_offset;
- len = ntohs(ip_packet->ip_len) - ip_hl - icmphdr_offset;
+
+ if ((len = ntohs(ip_packet->ip_len)) < h->caplen)
+ len -= ip_hl + icmphdr_offset;
+ else len = h->caplen - link_offset - ip_hl - icmphdr_offset;
if (((len || show_empty) && (((int)(*match_func)(data, len)) != invert_match))
|| keep_matching) {