diff options
author | Lawrence Teo <lteo@cvs.openbsd.org> | 2014-06-20 04:04:53 +0000 |
---|---|---|
committer | Lawrence Teo <lteo@cvs.openbsd.org> | 2014-06-20 04:04:53 +0000 |
commit | 52bfa89556e0719100a1a96bd1695d65ad5b9e32 (patch) | |
tree | 64eed16719ad06a0a33cd4ef0e5c841c68a168ae /usr.sbin/tcpdump/print-ip.c | |
parent | c0d146063d45fc9282793453cb0e29f9bc7b8ff5 (diff) |
Instead of showing the difference between a bad checksum and a good
checksum, make tcpdump (with the -v flag) show the actual bad checksum
within the IP/protocol header itself and what the good checksum should
be, e.g. "[bad tcp cksum abcd! -> d1e6]"
This change applies to IP, TCP (over IPv4 and IPv6), UDP (over IPv4 and
IPv6), ICMP, and ICMPv6. This commit also fixes several inconsistencies
in the way bad checksums were displayed for these protocols.
Tested on amd64, i386, and macppc.
ok henning@
Diffstat (limited to 'usr.sbin/tcpdump/print-ip.c')
-rw-r--r-- | usr.sbin/tcpdump/print-ip.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c index c3324980fef..4fd1e8d1394 100644 --- a/usr.sbin/tcpdump/print-ip.c +++ b/usr.sbin/tcpdump/print-ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-ip.c,v 1.37 2014/01/11 04:35:52 lteo Exp $ */ +/* $OpenBSD: print-ip.c,v 1.38 2014/06/20 04:04:52 lteo Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -627,7 +627,6 @@ ip_print(register const u_char *bp, register u_int length) (void)printf(" [ttl %d]", (int)ip->ip_ttl); if (vflag) { - int sum; char *sep = ""; printf(" ("); @@ -642,12 +641,12 @@ ip_print(register const u_char *bp, register u_int length) (void)printf("%slen %u", sep, ntohs(ip->ip_len)); sep = ", "; if ((u_char *)ip + hlen <= snapend) { + u_int16_t sum, ip_sum; sum = in_cksum((const u_short *)ip, hlen, 0); if (sum != 0) { - (void)printf("%sbad cksum %x!", sep, - ntohs(ip->ip_sum)); - if (vflag > 1) - (void)printf(" differs by %x", htons(sum)); + ip_sum = EXTRACT_16BITS(&ip->ip_sum); + (void)printf("%sbad ip cksum %x! -> %x", sep, ip_sum, + in_cksum_shouldbe(ip_sum, sum)); sep = ", "; } } |