summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authormjacob <mjacob@FreeBSD.org>2001-07-07 05:01:06 +0000
committermjacob <mjacob@FreeBSD.org>2001-07-07 05:01:06 +0000
commitde06014a318c640a8b4a0d735f30c05067255c35 (patch)
treea684c548f8ea9dfdf59ee8094d76b8c4b8d6ec3e /sbin
parentbc02f9cebed6df8c5095c6a6ec7c4fa01e2a1c09 (diff)
downloadFreeBSD-src-de06014a318c640a8b4a0d735f30c05067255c35.zip
FreeBSD-src-de06014a318c640a8b4a0d735f30c05067255c35.tar.gz
Fix unaligned access faults on alpha.
This one is strange and goes against my rusty compiler knowledge. The global declaration struct sockaddr whereto; produces for both i386 && alpha: .comm whereto,16,1 which means common storage, byte aligned. Ahem. I though structs were supposed to be ALDOUBLE always? I mean, w/o pragma packed? Later on, this address is coerced to: to = (struct sockaddr_in *)&whereto; Up until now, we've been fine on alpha because the address just ended up aligned to a 4 byte boundary. Lately, though, it end up as: 0000000120027b0f B whereto And, tra la, you get unaligned access faults. The solution I picked, in lieu of understanding what the compiler was doing, is to put whereto as a union of a sockaddr and sockaddr_in. That's more formally correct if somewhat awkward looking.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ping/ping.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index a0117f4..8e111bb 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -146,7 +146,15 @@ int options;
int mx_dup_ck = MAX_DUP_CHK;
char rcvd_tbl[MAX_DUP_CHK / 8];
-struct sockaddr whereto; /* who to ping */
+/*
+ * Use a union to coerce alignment to at least sockaddr_in's alignment.
+ * This avoids unaligned access faults on alpha.
+ */
+union {
+ struct sockaddr _w2; /* who to ping */
+ struct sockaddr_in _w2_in; /* who to ping */
+} ww;
+#define whereto ww._w2
int datalen = DEFDATALEN;
int s; /* socket file descriptor */
u_char outpack[MAXPACKET];
OpenPOWER on IntegriCloud