Reputation: 511
The man pages don't cover the state of the sockaddr variable passed by reference into the accept() function in case of an error.
Is it safe to assume that if something goes wrong between the time the client connects and the time you accept it, resulting in a return value of less than 0 from accept(), that the sockaddr struct is still populated and the IP information is valid?
Upvotes: 0
Views: 63
Reputation: 311039
Is it safe to assume that if something goes wrong between the time the client connects and the time you accept it, resulting in a return value of less than 0 from accept(), that the sockaddr struct is still populated and the IP information is valid?
No. If accept()
failed, there is no guarantee stated anywhere that anything has happened to the sockaddr
struct or length word at all, or that if anything has happened to it, it now means anything. Specifically, man accept says:
This structure is filled in with the address of the peer socket
If there has been a failure, there is no peer socket, ergo no peer socket address, ergo no filling in.
Upvotes: 2