From: guy Date: Mon, 9 Oct 2000 02:59:39 +0000 (+0000) Subject: Some compilers may pad structures to a length that's a multiple of 2 or X-Git-Tag: tcpdump-3.5.1~100 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/d16cf6488c6a3a8a4257311c80d5766ed8b7cdcb Some compilers may pad structures to a length that's a multiple of 2 or 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. --- diff --git a/ether.h b/ether.h index c68f25c0..105e05e3 100644 --- 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 c2b7cd8a..7c546cb2 100644 --- 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 */ diff --git a/print-ether.c b/print-ether.c index d75a64d2..3838e73d 100644 --- a/print-ether.c +++ b/print-ether.c @@ -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); } diff --git a/print-fddi.c b/print-fddi.c index 92afbdfa..f1e0ecf8 100644 --- a/print-fddi.c +++ b/print-fddi.c @@ -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, diff --git a/print-pppoe.c b/print-pppoe.c index dd8ad24b..344d7903 100644 --- a/print-pppoe.c +++ b/print-pppoe.c @@ -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;