diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-02-04 08:35:13 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-02-04 08:35:13 +0000 |
commit | a692fc0ef6481191f5808e355cdec541e7cafb18 (patch) | |
tree | c50146948a18ec0e859e995816249f1e6ebb496f /usr.sbin | |
parent | 7ae9a60262917bae9ffe0b7a63e84e4177a687f9 (diff) |
Some more non-alignment problems resolved.
ok deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/tcpdump/addrtoname.c | 7 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-atalk.c | 7 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-ip.c | 7 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-ip6.c | 28 |
4 files changed, 31 insertions, 18 deletions
diff --git a/usr.sbin/tcpdump/addrtoname.c b/usr.sbin/tcpdump/addrtoname.c index 087e84fef5d..7ad261ee278 100644 --- a/usr.sbin/tcpdump/addrtoname.c +++ b/usr.sbin/tcpdump/addrtoname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: addrtoname.c,v 1.22 2004/02/02 09:43:27 otto Exp $ */ +/* $OpenBSD: addrtoname.c,v 1.23 2004/02/04 08:35:12 otto Exp $ */ /* * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -25,7 +25,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.c,v 1.22 2004/02/02 09:43:27 otto Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/addrtoname.c,v 1.23 2004/02/04 08:35:12 otto Exp $ (LBL)"; #endif #include <sys/types.h> @@ -46,6 +46,7 @@ struct rtentry; #include <arpa/inet.h> #include <ctype.h> +#include <inttypes.h> #include <netdb.h> #include <pcap.h> #include <pcap-namedb.h> @@ -169,7 +170,7 @@ getname(const u_char *ap) /* * Extract 32 bits in network order, dealing with alignment. */ - switch ((long)ap & 3) { + switch ((intptr_t)ap & (sizeof(u_int32_t)-1)) { case 0: addr = *(u_int32_t *)ap; diff --git a/usr.sbin/tcpdump/print-atalk.c b/usr.sbin/tcpdump/print-atalk.c index 403b1958bc9..b52240788cd 100644 --- a/usr.sbin/tcpdump/print-atalk.c +++ b/usr.sbin/tcpdump/print-atalk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-atalk.c,v 1.22 2004/02/02 09:43:27 otto Exp $ */ +/* $OpenBSD: print-atalk.c,v 1.23 2004/02/04 08:35:12 otto Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -25,7 +25,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atalk.c,v 1.22 2004/02/02 09:43:27 otto Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atalk.c,v 1.23 2004/02/04 08:35:12 otto Exp $ (LBL)"; #endif #include <sys/param.h> @@ -46,6 +46,7 @@ struct rtentry; #include <netinet/tcp.h> #include <netinet/tcpip.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -223,7 +224,7 @@ ddp_print(register const u_char *bp, register u_int length, register int t, register u_short snet, register u_char snode, u_char skt) { - if ((long)bp & 3) { + if ((intptr_t)bp & (sizeof(long)-1)) { static u_char *abuf = NULL; if (abuf == NULL) { diff --git a/usr.sbin/tcpdump/print-ip.c b/usr.sbin/tcpdump/print-ip.c index ad025421e17..3542cd6439b 100644 --- a/usr.sbin/tcpdump/print-ip.c +++ b/usr.sbin/tcpdump/print-ip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-ip.c,v 1.23 2004/02/02 09:43:27 otto Exp $ */ +/* $OpenBSD: print-ip.c,v 1.24 2004/02/04 08:35:12 otto Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.23 2004/02/02 09:43:27 otto Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-ip.c,v 1.24 2004/02/04 08:35:12 otto Exp $ (LBL)"; #endif #include <sys/param.h> @@ -39,6 +39,7 @@ static const char rcsid[] = #include <netinet/tcp.h> #include <netinet/tcpip.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -364,7 +365,7 @@ ip_print(register const u_char *bp, register u_int length) * This will never happen with BPF. It does happen with raw packet * dumps from -r. */ - if ((long)ip & 3) { + if ((intptr_t)ip & (sizeof(long)-1)) { static u_char *abuf = NULL; static int didwarn = 0; diff --git a/usr.sbin/tcpdump/print-ip6.c b/usr.sbin/tcpdump/print-ip6.c index 3dee1dc64a5..79dc408e0fe 100644 --- a/usr.sbin/tcpdump/print-ip6.c +++ b/usr.sbin/tcpdump/print-ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-ip6.c,v 1.4 2003/01/27 10:00:40 henning Exp $ */ +/* $OpenBSD: print-ip6.c,v 1.5 2004/02/04 08:35:12 otto Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 @@ -41,8 +41,10 @@ static const char rcsid[] = #include <netinet/udp_var.h> #include <netinet/tcp.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include "interface.h" @@ -65,23 +67,31 @@ ip6_print(register const u_char *bp, register int length) ip6 = (const struct ip6_hdr *)bp; -#ifdef TCPDUMP_ALIGN /* * The IP header is not word aligned, so copy into abuf. * This will never happen with BPF. It does happen with * raw packet dumps from -r. */ - if ((int)ip & (sizeof(long)-1)) { - static u_char *abuf; + if ((intptr_t)ip6 & (sizeof(long)-1)) { + static u_char *abuf = NULL; + static int didwarn = 0; - if (abuf == NULL) + if (abuf == NULL) { abuf = (u_char *)malloc(snaplen); - bcopy((char *)ip, (char *)abuf, min(length, snaplen)); - snapend += abuf - (u_char *)ip; + if (abuf == NULL) + error("ip6_print: malloc"); + } + memcpy((char *)abuf, (char *)ip6, min(length, snaplen)); + snapend += abuf - (u_char *)ip6; packetp = abuf; - ip = (struct ip6_hdr *)abuf; + ip6 = (struct ip6_hdr *)abuf; + /* We really want libpcap to give us aligned packets */ + if (!didwarn) { + warning("compensating for unaligned libpcap packets"); + ++didwarn; + } } -#endif + if ((u_char *)(ip6 + 1) > snapend) { printf("[|ip6]"); return; |