On Sat, 10 Oct 2015, 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?
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. (There a partial exception for uses of sockaddr_in6: because the IETF kept fucking with the additional members in it, itojun@ got a requirement that userspace zero it before use, so you can expect it to either be correct, or zero. While that may be useful in IPv6-specific parts of code, since it is not a rule for *all* sockaddr types, it's not generally useful.) > 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. "Define 'full'..." > 3. The only documented EINVAL for connect concerns TCP, which this is > not, and multicast addresses, which this is not. Per [email protected]'s reply, that's a manpage bug. Please work together to generate a diff. Philip
