#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.130 2003-11-16 09:36:23 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.132 2003-11-19 00:36:07 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
{
register const struct ip *ip;
register u_int hlen, len, len0, off;
+ const u_char *ipend;
register const u_char *cp;
u_char nh;
int advance;
}
hlen = IP_HL(ip) * 4;
if (hlen < sizeof (struct ip)) {
- (void)printf("bad-hlen %d", hlen);
+ (void)printf("bad-hlen %u", hlen);
return;
}
len = EXTRACT_16BITS(&ip->ip_len);
if (length < len)
- (void)printf("truncated-ip - %d bytes missing! ",
+ (void)printf("truncated-ip - %u bytes missing! ",
len - length);
+ if (len < hlen) {
+ (void)printf("bad-len %u", len);
+ return;
+ }
+
+ /*
+ * Cut off the snapshot length to the end of the IP payload.
+ */
+ ipend = bp + len;
+ if (ipend < snapend)
+ snapend = ipend;
+
len -= hlen;
len0 = len;
case IPPROTO_AH:
nh = *cp;
advance = ah_print(cp);
+ if (advance <= 0)
+ break;
cp += advance;
len -= advance;
goto again;
{
int enh, padlen;
advance = esp_print(cp, (const u_char *)ip, &enh, &padlen);
+ if (advance <= 0)
+ break;
cp += advance;
len -= advance + padlen;
- if (enh < 0)
- break;
nh = enh & 0xff;
goto again;
}
{
int enh;
advance = ipcomp_print(cp, &enh);
+ if (advance <= 0)
+ break;
cp += advance;
len -= advance;
- if (enh < 0)
- break;
nh = enh & 0xff;
goto again;
}