diff options
author | guy <guy> | 2002-12-11 07:13:49 +0000 |
---|---|---|
committer | guy <guy> | 2002-12-11 07:13:49 +0000 |
commit | fcc82f451d3e51fdf636abbf927edb287bada0e0 (patch) | |
tree | 938119171c0d1eb45c66c2f576b95293f04f468b /print-igmp.c | |
parent | 3a4254f5c662637cf669ff66b941240d7e456d6d (diff) | |
download | tcpdump-fcc82f451d3e51fdf636abbf927edb287bada0e0.tar.gz |
The "__attribute__((packed))" tag on structures causes some files not to
compile with Sun C, as "interface.h" isn't being included before the
structures are being declared.
Furthermore, in the files that Sun C *can* compile, it doesn't cause Sun
C to generate code that's safe with unaligned accesses, as
"__attribute__" is defined as a do-nothing macro with compilers that
don't support it.
Therefore, we get rid of that tag on the structures to which it was
added, and instead use "EXTRACT_16BIT()" and "EXTRACT_32BIT()" to fetch
16-bit and 32-bit big-endian quantities from packets. We also fix some
other references to multi-byte quantities to get rid of code that tries
to do unaligned loads on platforms that don't support them.
We also throw in a hack that makes those macros use
"__attribute__((packed))" on structures containing only one 16-bit or
32-bit integer to get the compiler to generate unaligned-safe code
rather than doing it by hand. (GCC on SPARC produces the same code that
doing it by hand does; I don't know if GCC on any other big-endian
strict-alignment processor generates better code for that case. On
little-endian processors, as "ntohs()" and "ntohl()" might be functions,
that might actually produce worse code.)
Fix some places to use "%u" rather than "%d" to print unsigned
quantities.
Diffstat (limited to 'print-igmp.c')
-rw-r--r-- | print-igmp.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/print-igmp.c b/print-igmp.c index b1f3b493..84fc7621 100644 --- a/print-igmp.c +++ b/print-igmp.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.10 2002-11-09 17:19:26 itojun Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-igmp.c,v 1.11 2002-12-11 07:14:02 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -51,7 +51,7 @@ struct tr_query { u_int32_t tr_dst; /* traceroute destination */ u_int32_t tr_raddr; /* traceroute response address */ u_int32_t tr_rttlqid; /* response ttl and qid */ -} __attribute__((packed)); +}; #define TR_GETTTL(x) (int)(((x) >> 24) & 0xff) #define TR_GETQID(x) ((x) & 0x00ffffff) @@ -72,7 +72,7 @@ struct tr_resp { u_int8_t tr_fttl; /* ttl required to forward on outvif */ u_int8_t tr_smask; /* subnet mask for src addr */ u_int8_t tr_rflags; /* forwarding error codes */ -} __attribute__((packed)); +}; /* defs within mtrace */ #define TR_QUERY 1 @@ -116,12 +116,12 @@ print_mtrace(register const u_char *bp, register u_int len) (void)printf(" [invalid len %d]", len); return; } - printf("mtrace %lu: %s to %s reply-to %s", - (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)), + printf("mtrace %u: %s to %s reply-to %s", + TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)), ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), ipaddr_string(&tr->tr_raddr)); - if (IN_CLASSD(ntohl(tr->tr_raddr))) - printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid))); + if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr))) + printf(" with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))); return; trunc: (void)printf("[|igmp]"); @@ -139,11 +139,11 @@ print_mresp(register const u_char *bp, register u_int len) return; } printf("mresp %lu: %s to %s reply-to %s", - (u_long)TR_GETQID(ntohl(tr->tr_rttlqid)), + (u_long)TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)), ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), ipaddr_string(&tr->tr_raddr)); - if (IN_CLASSD(ntohl(tr->tr_raddr))) - printf(" with-ttl %d", TR_GETTTL(ntohl(tr->tr_rttlqid))); + if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr))) + printf(" with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))); return; trunc: (void)printf("[|igmp]"); |