]> The Tcpdump Group git mirrors - tcpdump/commitdiff
do not use integer bitfield when we care about the resulting member size.
authoritojun <itojun>
Tue, 3 Oct 2000 02:26:53 +0000 (02:26 +0000)
committeritojun <itojun>
Tue, 3 Oct 2000 02:26:53 +0000 (02:26 +0000)
u_int x:4, y:4; will occupy sizeof(int) on some platforms, while it occupy
1 byte on some platforms.  use macro to decode th_off.

print-sl.c
print-tcp.c
tcp.h

index aa6bfa9d57e3541ebb5629d0b057c2f1f7057826..d3f5776ac031c9ac49075a4f1109ebfeb3bbddc4 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.52 2000-09-29 04:58:50 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-sl.c,v 1.53 2000-10-03 02:26:53 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -193,7 +193,7 @@ sliplink_print(register const u_char *p, register const struct ip *ip,
                 */
                lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p;
                hlen = ip->ip_hl;
-               hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off;
+               hlen += TH_OFF((struct tcphdr *)&((int *)ip)[hlen]);
                lastlen[dir][lastconn] = length - (hlen << 2);
                printf("utcp %d: ", lastconn);
                break;
@@ -283,7 +283,7 @@ compressed_sl_print(const u_char *chdr, const struct ip *ip,
         * 'length - hlen' is the amount of data in the packet.
         */
        hlen = ip->ip_hl;
-       hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off;
+       hlen += TH_OFF((struct tcphdr *)&((int32_t *)ip)[hlen]);
        lastlen[dir][lastconn] = length - (hlen << 2);
        printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr);
 }
index e70ffa35db7a5053ee47ca190b44721b9365ae7d..ed6ff34363455be54049ba3bab3d6b380ce90123 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.76 2000-09-30 03:35:56 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.77 2000-10-03 02:26:53 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -264,7 +264,7 @@ tcp_print(register const u_char *bp, register u_int length,
        dport = ntohs(tp->th_dport);
 
 
-       hlen = tp->th_off * 4;
+       hlen = TH_OFF(tp) * 4;
 
        /*
         * If data present and NFS port used, assume NFS.
@@ -320,7 +320,7 @@ tcp_print(register const u_char *bp, register u_int length,
        urp = ntohs(tp->th_urp);
 
        if (qflag) {
-               (void)printf("tcp %d", length - tp->th_off * 4);
+               (void)printf("tcp %d", length - TH_OFF(tp) * 4);
                return;
        }
        if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH|
@@ -640,7 +640,7 @@ tcp_print(register const u_char *bp, register u_int length,
        /*
         * Decode payload if necessary.
         */
-       bp += (tp->th_off * 4);
+       bp += TH_OFF(tp) * 4;
        if (flags & TH_RST) {
                if (vflag)
                        print_tcp_rst_data(bp, length);
diff --git a/tcp.h b/tcp.h
index c39cce7ea390cce5b7c81e53b8175b01a9767d2e..487c166a3ab6f284312265e8ef42464ea6a66668 100644 (file)
--- a/tcp.h
+++ b/tcp.h
@@ -1,4 +1,4 @@
-/* @(#) $Header: /tcpdump/master/tcpdump/tcp.h,v 1.3 2000-09-29 05:05:48 guy Exp $ (LBL) */
+/* @(#) $Header: /tcpdump/master/tcpdump/tcp.h,v 1.4 2000-10-03 02:26:53 itojun Exp $ (LBL) */
 /*
  * Copyright (c) 1982, 1986, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -67,14 +67,8 @@ struct tcphdr {
        u_short th_dport;               /* destination port */
        tcp_seq th_seq;                 /* sequence number */
        tcp_seq th_ack;                 /* acknowledgement number */
-#if BYTE_ORDER == LITTLE_ENDIAN 
-       u_int   th_x2:4,                /* (unused) */
-               th_off:4;               /* data offset */
-#endif
-#if BYTE_ORDER == BIG_ENDIAN 
-       u_int   th_off:4,               /* data offset */
-               th_x2:4;                /* (unused) */
-#endif
+       u_char  th_x2off;
+#define TH_OFF(th)     ((th)->th_x2off & 0x0f) /* data offset, th_off */
        u_char  th_flags;
 #define        TH_FIN  0x01
 #define        TH_SYN  0x02