Module Name:    src
Committed By:   christos
Date:           Wed Aug 17 10:48:02 UTC 2011

Modified Files:
        src/external/bsd/tcpdump/bin: Makefile
        src/external/bsd/tcpdump/dist: extract.h print-isakmp.c

Log Message:
fix strict aliasing issues.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/external/bsd/tcpdump/bin/Makefile
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/tcpdump/dist/extract.h
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/tcpdump/dist/print-isakmp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/tcpdump/bin/Makefile
diff -u src/external/bsd/tcpdump/bin/Makefile:1.6 src/external/bsd/tcpdump/bin/Makefile:1.7
--- src/external/bsd/tcpdump/bin/Makefile:1.6	Tue Jun 21 22:49:43 2011
+++ src/external/bsd/tcpdump/bin/Makefile	Wed Aug 17 06:48:02 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.6 2011/06/22 02:49:43 mrg Exp $	
+#	$NetBSD: Makefile,v 1.7 2011/08/17 10:48:02 christos Exp $	
 
 WARNS?=	1	# XXX: need to cleanup later
 
@@ -89,8 +89,3 @@
 	cp ${.ALLSRC} ${.TARGET}
 
 .include <bsd.prog.mk>
-
-# XXX
-.if ${HAVE_GCC} == 45
-COPTS+=	-fno-strict-aliasing
-.endif

Index: src/external/bsd/tcpdump/dist/extract.h
diff -u src/external/bsd/tcpdump/dist/extract.h:1.1.1.1 src/external/bsd/tcpdump/dist/extract.h:1.2
--- src/external/bsd/tcpdump/dist/extract.h:1.1.1.1	Sat Dec  4 22:15:01 2010
+++ src/external/bsd/tcpdump/dist/extract.h	Wed Aug 17 06:48:02 2011
@@ -21,6 +21,97 @@
  * @(#) Header: /tcpdump/master/tcpdump/extract.h,v 1.25 2006-01-30 16:20:07 hannes Exp (LBL)
  */
 
+#ifdef __NetBSD__
+#include <string.h>
+
+/*
+ * Do it the portable way and let the compiler optimize the code
+ */
+static inline uint16_t EXTRACT_16BITS(const void *p)
+{
+	uint16_t t;
+	memcpy(&t, p, sizeof(t));
+	return ntohs(t);
+}
+
+static inline uint32_t EXTRACT_24BITS(const void *p)
+{
+	uint8_t t[3];
+	memcpy(t, p, sizeof(t));
+	return
+	    ((uint32_t)t[0] << 16) |
+	    ((uint32_t)t[1] << 8) |
+	    t[2];
+}
+
+static inline uint32_t EXTRACT_32BITS(const void *p)
+{
+	uint32_t t;
+	memcpy(&t, p, sizeof(t));
+	return ntohl(t);
+}
+
+static inline uint64_t EXTRACT_64BITS(const void *p)
+{
+	uint32_t t[2];
+	memcpy(&t[0], p, sizeof(t[0]));
+	memcpy(&t[1], (const uint8_t *)p + sizeof(t[0]), sizeof(t[1]));
+	return ((uint64_t)ntohl(t[0]) << 32) | ntohl(t[1]);
+}
+
+static inline uint8_t EXTRACT_LE_8BITS(const void *p)
+{
+	uint8_t t[1];
+	memcpy(t, p, sizeof(t));
+	return t[0];
+}
+
+static inline uint16_t EXTRACT_LE_16BITS(const void *p)
+{
+	uint8_t t[2];
+	memcpy(t, p, sizeof(t));
+	return
+	    ((uint16_t)t[1] << 8) |
+	    t[0];
+}
+
+static inline uint32_t EXTRACT_LE_24BITS(const void *p)
+{
+	uint8_t t[3];
+	memcpy(t, p, sizeof(t));
+	return
+	    ((uint32_t)t[2] << 16) |
+	    ((uint32_t)t[1] << 8) |
+	    t[0];
+}
+
+static inline uint32_t EXTRACT_LE_32BITS(const void *p)
+{
+	uint8_t t[4];
+	memcpy(t, p, sizeof(t));
+	return
+	    ((uint32_t)t[3] << 24) |
+	    ((uint32_t)t[2] << 16) |
+	    ((uint32_t)t[1] << 8) |
+	    t[0];
+}
+
+static inline uint64_t EXTRACT_LE_64BITS(const void *p)
+{
+	uint8_t t[8];
+	memcpy(&t, p, sizeof(t));
+	return
+	    ((uint64_t)t[7] << 56) |
+	    ((uint64_t)t[6] << 48) |
+	    ((uint64_t)t[5] << 40) |
+	    ((uint64_t)t[4] << 32) |
+	    ((uint64_t)t[3] << 24) |
+	    ((uint64_t)t[2] << 16) |
+	    ((uint64_t)t[1] << 8) |
+	    t[0];
+}
+
+#else /* Fast & Loose */
 /*
  * Macros to extract possibly-unaligned big-endian integral values.
  */
@@ -128,3 +219,4 @@
 		     (u_int64_t)*((const u_int8_t *)(p) + 2) << 16 | \
 		     (u_int64_t)*((const u_int8_t *)(p) + 1) << 8 | \
 		     (u_int64_t)*((const u_int8_t *)(p) + 0)))
+#endif /* __NetBSD__ */

Index: src/external/bsd/tcpdump/dist/print-isakmp.c
diff -u src/external/bsd/tcpdump/dist/print-isakmp.c:1.2 src/external/bsd/tcpdump/dist/print-isakmp.c:1.3
--- src/external/bsd/tcpdump/dist/print-isakmp.c:1.2	Sun Dec  5 00:11:30 2010
+++ src/external/bsd/tcpdump/dist/print-isakmp.c	Wed Aug 17 06:48:02 2011
@@ -34,7 +34,7 @@
 static const char rcsid[] _U_ =
     "@(#) Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.61 2008-02-05 19:34:25 guy Exp (LBL)";
 #else
-__RCSID("$NetBSD: print-isakmp.c,v 1.2 2010/12/05 05:11:30 christos Exp $");
+__RCSID("$NetBSD: print-isakmp.c,v 1.3 2011/08/17 10:48:02 christos Exp $");
 #endif
 #endif
 
@@ -2229,11 +2229,13 @@
 	u_char np;
 	int i;
 	int phase;
+	uint32_t msgid;
 	
 	p = (const struct isakmp *)bp;
 	ep = ndo->ndo_snapend;
 	
-	phase = (*(u_int32_t *)base->msgid == 0) ? 1 : 2;
+	memcpy(&msgid, base->msgid, sizeof(msgid));
+	phase = (msgid == 0) ? 1 : 2;
 	if (phase == 1)
 		ND_PRINT((ndo," phase %d", phase));
 	else
@@ -2400,11 +2402,13 @@
 	const u_char *ep;
 	u_char np;
 	int phase;
+	uint32_t msgid;
 
 	p = (const struct isakmp *)bp;
 	ep = ndo->ndo_snapend;
 
-	phase = (*(u_int32_t *)base->msgid == 0) ? 1 : 2;
+	memcpy(&msgid, base->msgid, sizeof(msgid));
+	phase = (msgid == 0) ? 1 : 2;
 	if (phase == 1)
 		ND_PRINT((ndo, " parent_sa"));
 	else

Reply via email to