Date: Thu, 7 Jun 2018 20:15:56 +0000 From: Rick Macklem <rmacklem@uoguelph.ca> To: FreeBSD Net <freebsd-net@freebsd.org> Subject: alignment of ai_addr in struct addrinfo Message-ID: <YTOPR0101MB0953922F5E99D2A8F433B054DD640@YTOPR0101MB0953.CANPRD01.PROD.OUTLOOK.COM>
next in thread | raw e-mail | index | archive | help
I have been doing "make universe" for the first time in a long time and
I ran into an interesting one.
I had code that looked like:
struct sockaddr_in *sin;
struct addrinfo *res;
- did a getaddrinfo() and then after this I had:
...
sin = (struct sockaddr_in *)res->ai_addr;
For mips, it complained that the alignment requirement for "struct sockaddr_in"
is different than "struct sockaddr" related to the type cast.
I've worked around this by:
struct sockaddr_in sin;
...
memcpy(&sin, res->ai_addr, sizeof(sin));
Is this a real problem or a compiler quirk?
If it is real, it seems to me it would be nice if the alignment requirement for
"struct sockaddr" was the same as "struct sockaddr_in" and "struct sockaddr_in6".
Is there a "trick" that could be applied to "struct sockaddr" to force good alignment?
rick
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YTOPR0101MB0953922F5E99D2A8F433B054DD640>
