X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/7fd1be1520c42204a6c7ec62ba34b1dd7b0884bb..8fb0656b71083c70f6c749a5cb9ad7152abb2a9d:/print-ip.c diff --git a/print-ip.c b/print-ip.c index 09ae8105..505cf847 100644 --- a/print-ip.c +++ b/print-ip.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.81 2000-05-01 17:35:45 fenner Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-ip.c,v 1.89 2000-10-03 02:54:58 itojun Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -33,16 +33,7 @@ static const char rcsid[] = #include #include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_MALLOC_H -#include -#endif + #include #include #include @@ -52,6 +43,8 @@ static const char rcsid[] = #include "interface.h" #include "extract.h" /* must come after interface.h */ +#include "ip.h" + /* Compatibility */ #ifndef IPPROTO_ND #define IPPROTO_ND 77 @@ -299,7 +292,15 @@ ip_optprint(register const u_char *cp, u_int length) for (; length > 0; cp += len, length -= len) { int tt = *cp; - len = (tt == IPOPT_NOP || tt == IPOPT_EOL) ? 1 : cp[1]; + if (tt == IPOPT_NOP || tt == IPOPT_EOL) + len = 1; + else { + if (&cp[1] >= snapend) { + printf("[|ip]"); + return; + } + len = cp[1]; + } if (len <= 0) { printf("[|ip op len %d]", len); return; @@ -442,7 +443,7 @@ ip_print(register const u_char *bp, register u_int length) (void)printf("truncated-ip %d", length); return; } - hlen = ip->ip_hl * 4; + hlen = IP_HL(ip) * 4; if (hlen < sizeof (struct ip)) { (void)printf("bad-hlen %d", hlen); return; @@ -706,6 +707,8 @@ again: (void)printf("%sid %d", sep, (int)ntohs(ip->ip_id)); sep = ", "; } + (void)printf("%slen %d", sep, (int)ntohs(ip->ip_len)); + sep = ", "; if ((u_char *)ip + hlen <= snapend) { sum = in_cksum((const u_short *)ip, hlen, 0); if (sum != 0) { @@ -721,3 +724,29 @@ again: printf(")"); } } + +void +ipN_print(register const u_char *bp, register u_int length) +{ + struct ip *ip, hdr; + + ip = (struct ip *)bp; + if (length < 4) { + (void)printf("truncated-ip %d", length); + return; + } + memcpy (&hdr, (char *)ip, 4); + switch (IP_V(&hdr)) { + case 4: + ip_print (bp, length); + return; +#ifdef INET6 + case 6: + ip6_print (bp, length); + return; +#endif + default: + (void)printf("unknown ip %d", IP_V(&hdr)); + return; + } +}