On Mon, 12 Oct 2015, Philip Guenther wrote:
> Rule: standard APIs CANNOT assume userland has set s*_len correctly.
>
> This is simply fallout of the fact that s*_len were added late, in BSD
> 4.4. As a result, calls have to deal with the possibility that it may
> contain random stack garbage.
To rephrase: programs must pass as the 'socklen' argument the actual size
of the underlying sockaddr. So:
* if the involved code uses just one protocol family, then just pass the
sizeof that specific sockaddr_* type
* if the involved code needs or wants to handle multiple protocol
families, then it needs to have the size of the involved sockaddr.
* if the code needs to be portable to non-BSD OSes then it cannot rely
on the presence of a s*_len member: it should track or pass around
the socklen_t size that each (struct sockaddr *) points to
* if the code is BSD-specific, just use the s*_len in each sockaddr_*.
On BSDs you can rely on that being set in sockaddr_* values returned
by the kernel
Philip