On Sat, Oct 10, 2015 at 04:11:07PM -0400, Ted Unangst wrote:
> The program below, when run without arguments, prints connect failed, invalid
> argumemt. Apparently connect() does not expect to be passed a full sized
> sockaddr_storage.
>
> 1. This is annoying. The sin_len has already been filled in, etc. Why does it
> care if some extra gets passed along?
>
> 2. The man page makes no mention of this error. In fact, it advises "namelen
> indicates the amount of space pointed to by name, in bytes" which sounds like
> it *should* be the full amount.
>
> 3. The only documented EINVAL for connect concerns TCP, which this is not, and
> multicast addresses, which this is not.
This is however, accepted and documented by POSIX
The connect() function shall fail if:
[...]
The connect() function may fail if:
[...]
[EINVAL]
The address_len argument is not a valid length for the address
family; or invalid address family in the sockaddr structure.
http://pubs.opengroup.org/onlinepubs/009695399/functions/connect.html
Please also notice that non-BSD system don't have sin_len (or sun_len).
Linux' behavior of ignoring the extra fluff for fixed size addresses
may be OK, but any program relying on that is broken -- even on linux
connect() will EINVAL if addrlen is larger than some (undocumented) value