sockaddr_storage

Eric S. Raymond esr at thyrsus.com
Mon Jan 23 04:23:39 UTC 2017


Hal Murray <hmurray at megapathdsl.net>:
> 
> > First, to eliminate a union from our source code. Second, to move from a
> > private type to a POSIX-standardized one that is likely to have a binding in
> > any language we move to. 
> 
> Just because it's POSIX doesn't mean it's any good.  Unless there is stylized 
> code for using sockaddr_storage, I would try hard to avoid it.  There is 
> nothing in there to help the type checker.

Good point.

> If the only problem with space is in the mrulist, we can fix that easily.  
> All the MRU list needs is a flag to specify if the IP address is 4 or 6, the 
> address, and the port number.  There is extra cruft in the sockaddr_in6 so it 
> wouldn't cost any space to use a non-union there.  We could save the space of 
> the IPv4 address with a bit of kludgery.

This might be worth doing for space-reduction reasons.  I'll poke at it.

> Barf.  The example URL you provided looked horrible to me.

This is me not arguing with your revulsion. :-)

> I forget what they called it, but Mesa had a sane way of handling things like 
> network packets.  The basic idea is that there was a way to select which 
> branch of the union you wanted to use, and you told the compiler about it.  
> Then you could do a select and each branch of the select could only access 
> the appropriate fields.

It's called a tagged union.  Rust has these. Go doesn't.
-- 
		<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>


More information about the devel mailing list