Date: Tue, 10 Aug 2010 22:41:20 +0200 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: "M. Warner Losh" <imp@bsdimp.com> Cc: src-committers@FreeBSD.org, jilles@stack.nl, svn-src-all@FreeBSD.org, olli@fromme.com, olli@FreeBSD.org, svn-src-head@FreeBSD.org Subject: Re: svn commit: r211023 - head/usr.sbin/syslogd Message-ID: <8639ump5e7.fsf@ds4.des.no> In-Reply-To: <20100810.120103.69891821625677670.imp@bsdimp.com> (M. Warner Losh's message of "Tue, 10 Aug 2010 12:01:03 -0600 (MDT)") References: <201008101623.o7AGNs7I042679@haluter.fromme.com> <20100810.110642.335141733495090585.imp@bsdimp.com> <86sk2m1hsj.fsf@ds4.des.no> <20100810.120103.69891821625677670.imp@bsdimp.com>
next in thread | previous in thread | raw e-mail | index | archive | help
"M. Warner Losh" <imp@bsdimp.com> writes: > Dag-Erling Sm=C3=B8rgrav <des@des.no> writes: > > "M. Warner Losh" <imp@bsdimp.com> writes: > > > /* > > > * Macros to cast a struct sockaddr, or parts thereof. > > > * On architectures with strict alignment requirements, the compiler > > > * can bogusly warn about alignment problems since its static analysis > > > * is insufficient for it to know that with the APIs used, there > > > * really is no alignment issue. > > > */ > > That's a bit harsh on the compiler, don't you think? It never pays to > > hurt the compiler's feelings :) > > /* > * Macros to cast a struct sockaddr, or parts thereof. struct > * sockaddr's alginment is loose to later be cast to a sockaddr_in or > * sockaddr_in6. On architectures with strict alignment requirements, > * this leads to compiler warnings because the compiler doesn't know > * the ABI guarantees proper alignment. > */ That sounds more like what I had in mind (my point being that the compiler is *right* to not make any such assumptions unless we say it's safe to do so) > But this leads me to think that the right fix might be: > > /* > * Structure used by kernel to store most > * addresses. > */ > struct sockaddr { > unsigned char sa_len; /* total length */ > sa_family_t sa_family; /* address family */ > char sa_data[14]; /* actually longer; address value */ > } __aligned(4); > > since that's what the ABI defines.... Yes, unfortunately that's not portable. I like the way it's done in sockaddr_storage, but we can't do that here except possibly using anonymous unions, which aren't portable either. > > > Why 16 and 4 here? What's so magical about them? > > 4 =3D bytes in a uint32_t, 16 =3D bytes in an ipv6 address. > Isn't that better served by 'sizeof(uint32_t)' and > 'sizeof(ipv6_addr_t)'? Probably... DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8639ump5e7.fsf>