summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawrence Teo <lteo@cvs.openbsd.org>2014-01-11 04:40:46 +0000
committerLawrence Teo <lteo@cvs.openbsd.org>2014-01-11 04:40:46 +0000
commitc6333c11ef5db00078e7f93f8f6278d16a576753 (patch)
tree4c884f0c1b91fd21f2abfb313d6bc7ea8cab89b2
parent17a396dd4e2d5d4a1387a44bc71c59d327388ef4 (diff)
Let tcpdump detect bad ICMP checksums with the -v flag.
Tested on amd64, i386, loongson, and macppc. OK florian@
-rw-r--r--usr.sbin/tcpdump/print-icmp.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/usr.sbin/tcpdump/print-icmp.c b/usr.sbin/tcpdump/print-icmp.c
index a554c0a434f..fcb51f4478a 100644
--- a/usr.sbin/tcpdump/print-icmp.c
+++ b/usr.sbin/tcpdump/print-icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print-icmp.c,v 1.21 2014/01/11 04:35:52 lteo Exp $ */
+/* $OpenBSD: print-icmp.c,v 1.22 2014/01/11 04:40:45 lteo Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@@ -373,7 +373,17 @@ icmp_print(const u_char *bp, u_int length, const u_char *bp2)
str = tok2str(icmp2str, "type-#%u", dp->icmp_type);
break;
}
- (void)printf("icmp: %s", str);
+ (void)printf("icmp: %s", str);
+ if (vflag) {
+ u_int16_t sum;
+ if (TTEST2(dp->icmp_type, length)) {
+ sum = in_cksum((const u_short *)dp, length, 0);
+ if (sum != 0)
+ (void)printf(" [bad icmp cksum %x!]", sum);
+ else
+ (void)printf(" [icmp cksum ok]");
+ }
+ }
if (vflag > 1 && !ICMP_INFOTYPE(dp->icmp_type) &&
TTEST(dp->icmp_ip)) {
(void)printf(" for ");