hallo,

i would like to add a disable checksum flag to tcpdump.

i assume this will affect ip, tcp, udp, icmp, icmp6, isoclns, igmp, vrrp,
mobile printers, and tcpdump.c file (is it all?)

proposed change:
add a global int cksumflag=1 in tcpdump.c :)
add a command line flag: k (?),
which when specified disables the checksum calculation (cksumflag=0);
check cksumflag before calculating checksums in printers.

i attached the patch against today's cvs, which worked on my setup,
but i have no idea what some printers do, so, please, let me know
if there is more changes needed or things should be done differently.

 ???

thanks,

-alexm
--
001, 010, 011, 100, 101 - ����� ������ ��������







diff -urN tcpdump.orig/print-icmp.c tcpdump/print-icmp.c
--- tcpdump.orig/print-icmp.c   Fri Jul 18 12:39:24 2003
+++ tcpdump/print-icmp.c        Fri Jul 18 12:39:34 2003
@@ -41,6 +41,8 @@
 #include "udp.h"
 #include "ipproto.h"
 
+extern int cksumflag;
+
 /*
  * Interface Control Message Protocol Definitions.
  * Per RFC 792, September 1981.
@@ -477,7 +479,7 @@
                break;
        }
        (void)printf("icmp %d: %s", plen, str);
-       if (vflag && !fragmented) { /* don't attempt checksumming if this is a frag */
+       if (vflag && !fragmented && cksumflag) { /* don't attempt checksumming if this 
is a frag */
                u_int16_t sum, icmp_sum;
                if (TTEST2(*bp, plen)) {
                        sum = in_cksum((u_short*)dp, plen, 0);
diff -urN tcpdump.orig/print-icmp6.c tcpdump/print-icmp6.c
--- tcpdump.orig/print-icmp6.c  Fri Jul 18 12:39:24 2003
+++ tcpdump/print-icmp6.c       Fri Jul 18 12:39:34 2003
@@ -46,6 +46,8 @@
 #include "udp.h"
 #include "ah.h"
 
+extern int cksumflag;
+
 static const char *get_rtpref(u_int);
 static const char *get_lifetime(u_int32_t);
 static void print_lladdr(const u_char *, size_t);
@@ -171,7 +173,7 @@
 
        TCHECK(dp->icmp6_cksum);
 
-       if (vflag && !fragmented) {
+       if (vflag && !fragmented && cksumflag) {
                int sum = dp->icmp6_cksum;
 
                if (TTEST2(bp[0], icmp6len)) {
diff -urN tcpdump.orig/print-igmp.c tcpdump/print-igmp.c
--- tcpdump.orig/print-igmp.c   Fri Jul 18 12:39:24 2003
+++ tcpdump/print-igmp.c        Fri Jul 18 12:39:34 2003
@@ -41,6 +41,8 @@
 #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
 #endif
 
+extern int cksumflag;
+
 /* (following from ipmulti/mrouted/prune.h) */
 
 /*
@@ -319,7 +321,7 @@
         break;
     }
 
-    if (vflag && TTEST2(bp[0], len)) {
+    if (vflag && cksumflag && TTEST2(bp[0], len)) {
         /* Check the IGMP checksum */
         if (in_cksum((const u_short*)bp, len, 0))
             printf(" bad igmp cksum %x!", EXTRACT_16BITS(&bp[2]));
diff -urN tcpdump.orig/print-ip.c tcpdump/print-ip.c
--- tcpdump.orig/print-ip.c     Fri Jul 18 12:39:24 2003
+++ tcpdump/print-ip.c  Fri Jul 18 12:39:34 2003
@@ -41,6 +41,8 @@
 #include "ip.h"
 #include "ipproto.h"
 
+extern int cksumflag;
+
 /*
  * print the recorded route in an IP RR, LSRR or SSRR option.
  */
@@ -434,7 +436,7 @@
                 printf(" )");
             }
 
-           if ((u_char *)ip + hlen <= snapend) {
+           if ((u_char *)ip + hlen <= snapend && cksumflag) {
                sum = in_cksum((const u_short *)ip, hlen, 0);
                if (sum != 0) {
                    ip_sum = EXTRACT_16BITS(&ip->ip_sum);
diff -urN tcpdump.orig/print-isoclns.c tcpdump/print-isoclns.c
--- tcpdump.orig/print-isoclns.c        Fri Jul 18 12:39:24 2003
+++ tcpdump/print-isoclns.c     Fri Jul 18 12:39:34 2003
@@ -45,6 +45,8 @@
 #include "extract.h"
 #include "gmpls.h"
 
+extern int cksumflag;
+
 #define        NLPID_CLNS      129     /* 0x81 */
 #define        NLPID_ESIS      130     /* 0x82 */
 #define        NLPID_ISIS      131     /* 0x83 */
@@ -545,7 +547,7 @@
         if(vflag < 1)
                return;
 
-       if (vflag && osi_cksum(p, li)) {
+       if (vflag && cksumflag && osi_cksum(p, li)) {
                printf(" bad cksum (got 0x%02x%02x)",
                       eh->cksum[1], eh->cksum[0]);
                default_print(p, length);
diff -urN tcpdump.orig/print-mobile.c tcpdump/print-mobile.c
--- tcpdump.orig/print-mobile.c Fri Jul 18 12:39:24 2003
+++ tcpdump/print-mobile.c      Fri Jul 18 12:39:34 2003
@@ -55,6 +55,8 @@
 
 #define MOBILE_SIZE (8)
 
+extern int cksumflag;
+
 struct mobile_ip {
        u_int16_t proto;
        u_int16_t hcheck;
@@ -101,7 +103,7 @@
                (void)printf("> %s ",ipaddr_string(&mob->odst));
                (void)printf("(oproto=%d)",proto>>8);
        }
-       if (in_cksum((u_short *)mob, osp ? 12 : 8, 0)!=0) {
+       if (cksumflag && in_cksum((u_short *)mob, osp ? 12 : 8, 0)!=0) {
                (void)printf(" (bad checksum %d)",crc);
        }
 
diff -urN tcpdump.orig/print-tcp.c tcpdump/print-tcp.c
--- tcpdump.orig/print-tcp.c    Fri Jul 18 12:39:24 2003
+++ tcpdump/print-tcp.c Fri Jul 18 12:39:34 2003
@@ -50,6 +50,8 @@
 
 #include "nameser.h"
 
+extern int cksumflag;
+
 static void print_tcp_rst_data(register const u_char *sp, u_int length);
 
 #define MAX_RST_DATA_LEN       30
@@ -398,7 +400,7 @@
                return;
        }
 
-       if (IP_V(ip) == 4 && vflag && !fragmented) {
+       if (IP_V(ip) == 4 && vflag && !fragmented && cksumflag) {
                u_int16_t sum, tcp_sum;
                if (TTEST2(tp->th_sport, length)) {
                        sum = tcp_cksum(ip, tp, length);
@@ -411,7 +413,7 @@
                }
        }
 #ifdef INET6
-       if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) {
+       if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented && cksumflag) {
                int sum;
                if (TTEST2(tp->th_sport, length)) {
                        sum = tcp6_cksum(ip6, tp, length);
diff -urN tcpdump.orig/print-udp.c tcpdump/print-udp.c
--- tcpdump.orig/print-udp.c    Fri Jul 18 12:39:24 2003
+++ tcpdump/print-udp.c Fri Jul 18 12:39:34 2003
@@ -57,6 +57,8 @@
 #include "nfs.h"
 #include "bootp.h"
 
+extern int cksumflag;
+
 struct rtcphdr {
        u_int16_t rh_flags;     /* T:2 P:1 CNT:5 PT:8 */
        u_int16_t rh_len;       /* length of message (in words) */
@@ -575,7 +577,7 @@
        }
        udpipaddr_print(ip, sport, dport);
 
-       if (IP_V(ip) == 4 && vflag && !fragmented) {
+       if (IP_V(ip) == 4 && vflag && !fragmented && cksumflag) {
                int sum = up->uh_sum;
                if (sum == 0) {
                        (void)printf("[no cksum] ");
@@ -588,7 +590,7 @@
                }
        }
 #ifdef INET6
-       if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented) {
+       if (IP_V(ip) == 6 && ip6->ip6_plen && vflag && !fragmented && cksumflag) {
                int sum = up->uh_sum;
                /* for IPv6, UDP checksum is mandatory */
                if (TTEST2(cp[0], length)) {
diff -urN tcpdump.orig/print-vrrp.c tcpdump/print-vrrp.c
--- tcpdump.orig/print-vrrp.c   Fri Jul 18 12:39:24 2003
+++ tcpdump/print-vrrp.c        Fri Jul 18 12:39:34 2003
@@ -41,6 +41,8 @@
 #include "extract.h"
 #include "addrtoname.h"
 
+extern int cksumflag;
+
 /*
  * RFC 2338:
  *     0                   1                   2                   3
@@ -110,7 +112,7 @@
                int i;
                char c;
 
-               if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0))
+               if (cksumflag && TTEST2(bp[0], len) && in_cksum((const u_short*)bp, 
len, 0))
                        printf(" (bad vrrp cksum %x!)",
                                EXTRACT_16BITS(&bp[6]));
                printf(" addrs");
diff -urN tcpdump.orig/tcpdump.c tcpdump/tcpdump.c
--- tcpdump.orig/tcpdump.c      Fri Jul 18 12:39:24 2003
+++ tcpdump/tcpdump.c   Fri Jul 18 12:39:34 2003
@@ -69,6 +69,8 @@
 #include "gmt2local.h"
 #include "pcap-missing.h"
 
+int cksumflag = 1;
+
 int aflag;                     /* translate network and broadcast addresses */
 int dflag;                     /* print filter code */
 int eflag;                     /* print ethernet header */
@@ -334,6 +336,7 @@
        infile = NULL;
        RFileName = NULL;
        WFileName = NULL;
+
        if ((cp = strrchr(argv[0], '/')) != NULL)
                program_name = cp + 1;
        else
@@ -348,7 +351,7 @@
 
        opterr = 0;
        while (
-           (op = getopt(argc, argv, "aA" B_FLAG "c:C:d" D_FLAG 
"eE:fF:i:lLm:nNOpqr:Rs:StT:u" U_FLAG "vw:xXy:Y")) != -1)
+           (op = getopt(argc, argv, "aA" B_FLAG "c:C:d" D_FLAG 
"eE:fF:i:klLm:nNOpqr:Rs:StT:u" U_FLAG "vw:xXy:Y")) != -1)
                switch (op) {
 
                case 'a':
@@ -401,6 +404,10 @@
                        return 0;
 #endif /* HAVE_PCAP_FINDALLDEVS */
 
+               case 'k':
+                       cksumflag = 0;
+                       break;
+
                case 'L':
                        Lflag++;
                        break;
@@ -753,6 +760,9 @@
                        (void)fprintf(stderr, "%s: ", program_name);
                (void)fprintf(stderr, "listening on %s, link-type %u, capture size %u 
bytes\n",
                    device, pcap_datalink(pd), snaplen);
+#ifdef _AIX /* no checksum on AIX loopback */
+               if (pcap_datalink(pd) == 0) cksumflag = 0;
+#endif /* _AIX */
                (void)fflush(stderr);
        }
 #endif /* WIN32 */
@@ -1032,7 +1042,7 @@
 #endif /* WIN32 */
 #endif /* HAVE_PCAP_LIB_VERSION */
        (void)fprintf(stderr,
-"Usage: %s [-aAd" D_FLAG "eflLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [-c count] [ -C 
file_size ]\n", program_name);
+"Usage: %s [-aAd" D_FLAG "efklLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [-c count] [ 
-C file_size ]\n", program_name);
        (void)fprintf(stderr,
 "\t\t[ -E algo:secret ] [ -F file ] [ -i interface ] [ -r file ]\n");
        (void)fprintf(stderr,

Reply via email to