From de06014a318c640a8b4a0d735f30c05067255c35 Mon Sep 17 00:00:00 2001 From: mjacob Date: Sat, 7 Jul 2001 05:01:06 +0000 Subject: 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. --- sbin/ping/ping.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sbin') 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]; -- cgit v1.1