]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Some compilers may pad structures to a length that's a multiple of 2 or
authorguy <guy>
Mon, 9 Oct 2000 02:59:39 +0000 (02:59 +0000)
committerguy <guy>
Mon, 9 Oct 2000 02:59:39 +0000 (02:59 +0000)
4 bytes, even though no member in the structure requires such an
alignment; don't use "sizeof (struct ether_header)" or "sizeof (struct
fddi_header)", explicitly #define the header length and use that
#defined value.

ether.h
fddi.h
print-ether.c
print-fddi.c
print-pppoe.c

diff --git a/ether.h b/ether.h
index c68f25c089ce0c63a9874481c5bad8923c7355e5..105e05e369638d1322ad1c4ae1dd1129a0239c19 100644 (file)
--- a/ether.h
+++ b/ether.h
@@ -1,4 +1,4 @@
-/* @(#) $Header: /tcpdump/master/tcpdump/ether.h,v 1.4 2000-10-03 02:54:55 itojun Exp $ (LBL) */
+/* @(#) $Header: /tcpdump/master/tcpdump/ether.h,v 1.5 2000-10-09 02:59:39 guy Exp $ (LBL) */
 /*
  * Copyright (c) 1982, 1986, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -49,10 +49,18 @@ struct ether_addr {
 };
 
 /*
- * Structure of a 10Mb/s Ethernet header.
+ * Structure of a DEC/Intel/Xerox or 802.3 Ethernet header.
  */
 struct ether_header {
        u_int8_t        ether_dhost[ETHER_ADDR_LEN];
        u_int8_t        ether_shost[ETHER_ADDR_LEN];
        u_int16_t       ether_type;
 };
+
+/*
+ * Length of a DEC/Intel/Xerox or 802.3 Ethernet header; note that some
+ * compilers may pad "struct ether_header" to a multiple of 4 bytes,
+ * for example, so "sizeof (struct ether_header)" may not give the right
+ * answer.
+ */
+#define ETHER_HDRLEN           14
diff --git a/fddi.h b/fddi.h
index c2b7cd8a5369a2b49e42ff7f906e464ca9aea1da..7c546cb29952b57ac9563ecb51a72ff67018dfe0 100644 (file)
--- a/fddi.h
+++ b/fddi.h
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/fddi.h,v 1.8 1999-10-07 23:47:10 mcr Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/fddi.h,v 1.9 2000-10-09 02:59:39 guy Exp $ (LBL)
  */
 
 /*
@@ -37,6 +37,13 @@ struct fddi_header {
        u_char  fddi_shost[6];
 };
 
+/*
+ * Length of an FDDI header; note that some compilers may pad
+ * "struct fddi_header" to a multiple of 4 bytes, for example, so
+ * "sizeof (struct fddi_header)" may not give the right
+ * answer.
+ */
+#define FDDI_HDRLEN 13
 
 /* Useful values for fddi_fc (frame control) field */
 
index d75a64d291e83354ab5d53e21b1a80badb739137..3838e73d6dc7537db4ba3f1cb012d5aebd1967c7 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.57 2000-10-07 05:46:21 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.58 2000-10-09 02:59:39 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -85,7 +85,7 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
 
        ts_print(&h->ts);
 
-       if (caplen < sizeof(struct ether_header)) {
+       if (caplen < ETHER_HDRLEN) {
                printf("[|ether]");
                goto out;
        }
@@ -101,10 +101,10 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
        packetp = p;
        snapend = p + caplen;
 
-       length -= sizeof(struct ether_header);
-       caplen -= sizeof(struct ether_header);
+       length -= ETHER_HDRLEN;
+       caplen -= ETHER_HDRLEN;
        ep = (struct ether_header *)p;
-       p += sizeof(struct ether_header);
+       p += ETHER_HDRLEN;
 
        ether_type = ntohs(ep->ether_type);
 
@@ -128,7 +128,7 @@ ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
        } else if (ether_encap_print(ether_type, p, length, caplen) == 0) {
                /* ether_type not known, print raw packet */
                if (!eflag)
-                       ether_print((u_char *)ep, length + sizeof(*ep));
+                       ether_print((u_char *)ep, length + ETHER_HDRLEN);
                if (!xflag && !qflag)
                        default_print(p, caplen);
        }
index 92afbdfa04f5ce92db35f35c0ed59fbd3525b449..f1e0ecf82df154c29dde337f5ebf5bd8f1f545cd 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.46 2000-10-06 04:23:11 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-fddi.c,v 1.47 2000-10-09 02:59:40 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -88,8 +88,6 @@ int   fddi_bitswap = 1;
  *  - vj
  */
 
-#define FDDI_HDRLEN (sizeof(struct fddi_header))
-
 static u_char fddi_bit_swap[] = {
        0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
        0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
index dd8ad24b1a65ae3550f69bdfceea74693cd9464b..344d7903f6c9fb5c684e682ac6633db1886cc30a 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.11 2000-10-06 04:23:13 guy Exp $ (LBL)";
+"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.12 2000-10-09 02:59:40 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -101,7 +101,7 @@ pppoe_print(register const u_char *bp, u_int length)
   const u_char *pppoe_packet, *pppoe_payload;
 
   eh = (struct ether_header *)packetp;
-  pppoe_packet = packetp+sizeof(struct ether_header);
+  pppoe_packet = packetp+ETHER_HDRLEN;
   if (pppoe_packet > snapend) {
     printf("[|pppoe]");
     return;