Reputation: 1443
In the following partial code:
addrlen = sizeof(addr);
accept(sk, (struct sockaddr *)&addr, &addrlen);
If accept fails, is it possible for addrlen to be 0 or otherwise != sizeof(addr)?
Upvotes: 1
Views: 70
Reputation: 60843
POSIX was not clear on this, and reportedly FreeBSD did set *address_len
to 0 on some error conditions, although most systems leave it unchanged on error. The next POSIX revision will clarify that *address_len
shall not be modified on error. At least until the next POSIX revision becomes ubiquitous, applications would be wise not to assume anything about the value of *address_len
if an error is returned.
Upvotes: 3
Reputation: 1836
It shouldn't, but I seem to remember a recently fixed bug where that actually happened.
Upvotes: 2
Reputation: 310885
I doubt you can rely on it, and I can't see any reason why you would want to either. The first thing you should examine is the return code, which is -1 on error, and only examine the address/address length on success.
Upvotes: 1