I have a nonblocking socket created as:
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
fcntl(sockfd, F_SETFL, O_NONBLOCK);
It is then connected to the server via:
struct sockaddr_in addr = {};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = address;
addr.sin_port = port;
int retval = connect(sockfd,
(struct sockaddr *)&addr,
sizeof(addr));
I am attempting to simulate a network failure by setting the interface this socket is communicating on down via sudo ip link set <interface> down
. The socket should be tied to this interface specifically since I have set the IP address directly.
However, after setting the interface down, I do not receive any errors on subsequent calls to sendto
and recvfrom
. I am calling both of these with no flags.
I would expect to receive one of the error codes from these functions (like maybe ENOTCONN) since, with the interface down, the local machine should be able to tell that the function will fail. Why am I seeing no errors?