diff options
author | Matt Jacob <mjacob@FreeBSD.org> | 2001-07-07 05:01:06 +0000 |
---|---|---|
committer | Matt Jacob <mjacob@FreeBSD.org> | 2001-07-07 05:01:06 +0000 |
commit | c77eed5304a30c3fb1ee9edbe18b1254d6290c7b (patch) | |
tree | a684c548f8ea9dfdf59ee8094d76b8c4b8d6ec3e /sbin | |
parent | 0bada8603d59cf4f15ff6b20a27c4137b9c0abe6 (diff) | |
download | src-c77eed5304a30c3fb1ee9edbe18b1254d6290c7b.tar.gz src-c77eed5304a30c3fb1ee9edbe18b1254d6290c7b.zip |
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.
Notes
Notes:
svn path=/head/; revision=79381
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ping/ping.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index a0117f415f40..8e111bb415e9 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]; |