#include
#include
#include
#include
#include
#include
It would be interesting to compare the equivalent code using sendto()
rather than connect()
and send()
.
Does the code shown fail in the same way if you leave a period of time between each send, i.e. is the ICMP error state being kept in the socket for a period of time, or would it still fail the second send()
if you left it, say, an hour?
I expect that your assumption is correct, the network stack is trying to be clever. There's no other point when it could return 'connection refused' as nothing is sent when the connect()
call is issued it simply stores the address given so that the socket is 'logically' connected and calls to send()
can then work.