[PATCH] Unix datagram socket messaging

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Apr 17 00:52:19 MDT 2014


On Thu, Apr 17, 2014 at 10:28:21AM +1200, Andrew Bartlett wrote:
> On Wed, 2014-04-16 at 12:00 +0200, Stefan (metze) Metzmacher wrote:
> > In
> > https://git.samba.org/?p=vl/samba.git/.git;a=commitdiff;h=777954434bb7404659fbb7f519a4069b1100c400
> > we have
> > 
> > +       struct sockaddr_un addr = { 0, };
> > 
> > ...
> > 
> > +               ret = bind(ctx->sock, (struct sockaddr *)&addr,
> > sizeof(addr));
> > 
> > I think we should cast with (struct sockaddr *)(void *)&addr, in order
> > to avoid
> > strict aliasing warnings on some systems.
> 
> When this breaks, hasn't all the of Samba and all the other software
> written for BSD sockets also broken?  

That's why I was asking how this is supposed to work.

My understanding of the C standard snippets that I pasted
indicates that all of this depends upon undefined C
behaviour. In theory, a highly optimized compiler could
break a lot of socket code in the future. It is unlikely to
happen, so the void * cast is probably fine for the majority
of cases right now.

Apart from that, I would really like to know how this is
supposed to work without depending on behaviour that
compilers might break without us knowing. I'm doing C coding
for more than 20 years now, and I still don't understand the
corner cases of the language. That's why I am interested in
this purely academic question :-)

Volker


> 
> Andrew Bartlett
> 
> -- 
> Andrew Bartlett
> http://samba.org/~abartlet/
> Authentication Developer, Samba Team  http://samba.org
> Samba Developer, Catalyst IT          http://catalyst.net.nz/services/samba
> 
> 
> 
> 

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de


More information about the samba-technical mailing list