summaryrefslogtreecommitdiff
path: root/print-esp.c
diff options
context:
space:
mode:
authorguy <guy>2002-12-11 07:13:49 +0000
committerguy <guy>2002-12-11 07:13:49 +0000
commitfcc82f451d3e51fdf636abbf927edb287bada0e0 (patch)
tree938119171c0d1eb45c66c2f576b95293f04f468b /print-esp.c
parent3a4254f5c662637cf669ff66b941240d7e456d6d (diff)
downloadtcpdump-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-esp.c')
-rw-r--r--print-esp.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/print-esp.c b/print-esp.c
index eabddfa9..8eebc574 100644
--- a/print-esp.c
+++ b/print-esp.c
@@ -23,7 +23,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.30 2002-11-13 09:35:13 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-esp.c,v 1.31 2002-12-11 07:13:59 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -58,6 +58,7 @@ static const char rcsid[] =
#define AVOID_CHURN 1
#include "interface.h"
#include "addrtoname.h"
+#include "extract.h"
static struct esp_algorithm *espsecret_xform=NULL; /* cache of decoded alg. */
static char *espsecret_key=NULL;
@@ -215,8 +216,8 @@ esp_print(register const u_char *bp, register const u_char *bp2,
fputs("[|ESP]", stdout);
goto fail;
}
- printf("ESP(spi=0x%08x", (u_int32_t)ntohl(esp->esp_spi));
- printf(",seq=0x%x", (u_int32_t)ntohl(esp->esp_seq));
+ printf("ESP(spi=0x%08x", EXTRACT_32BITS(&esp->esp_spi));
+ printf(",seq=0x%x", EXTRACT_32BITS(&esp->esp_seq));
printf(")");
/* if we don't have decryption key, we can't decrypt this packet. */
@@ -237,20 +238,20 @@ esp_print(register const u_char *bp, register const u_char *bp2,
ip6 = (struct ip6_hdr *)bp2;
ip = NULL;
/* we do not attempt to decrypt jumbograms */
- if (!ntohs(ip6->ip6_plen))
+ if (!EXTRACT_16BITS(&ip6->ip6_plen))
goto fail;
/* if we can't get nexthdr, we do not need to decrypt it */
- len = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen);
+ len = sizeof(struct ip6_hdr) + EXTRACT_16BITS(&ip6->ip6_plen);
break;
#endif /*INET6*/
case 4:
/* nexthdr & padding are in the last fragment */
- if (ntohs(ip->ip_off) & IP_MF)
+ if (EXTRACT_16BITS(&ip->ip_off) & IP_MF)
goto fail;
#ifdef INET6
ip6 = NULL;
#endif
- len = ntohs(ip->ip_len);
+ len = EXTRACT_16BITS(&ip->ip_len);
break;
default:
goto fail;