Setting option SO_SNDTIMEO to the socket cause connect() return with EINPROGRESS errno after timeout, but this nonstandard feature is not described in man pages of socket(7) and connect(2). Sample: int main(int argc, char *argv[]) { int sockfd, n; struct sockaddr_in serv_addr; struct timeval timeout; timeout.tv_sec = 4; timeout.tv_usec = 0; if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); return -1; } if( setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) == -1 ) { perror("setsockopt"); return -1; } bzero (&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(9999); if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr) < 1) { printf("Invalid IP address value. Exit.\n"); return -1; } if(connect(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) { printf("errno = %d\n", errno); perror("connect()"); return -1; } close(sockfd); return 0; } $ time ./client 88.88.88.88 errno = 115 connect(): Operation now in progress real 0m4.001s user 0m0.000s sys 0m0.000s # tcpdump -i ppp0 -n port 9999 -ttt tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ppp0, link-type LINUX_SLL (Linux cooked), capture size 96 bytes 000000 IP 81.25.50.166.47087 > 88.88.88.88.9999: S 3574453598:3574453598(0) win 5840 <mss 1460,sackOK,timestamp 207409345 0,nop,wscale 6> 2. 997721 IP 81.25.50.166.47087 > 88.88.88.88.9999: S 3574453598:3574453598(0) win 5840 <mss 1460,sackOK,timestamp 207410245 0,nop,wscale 6>
From man-pages-3.51 socket(7): SO_RCVTIMEO and SO_SNDTIMEO Specify the receiving or sending timeouts until reporting an error. The argument is a struct timeval. If an input or output function blocks for this period of time, and data has been sent or received, the return value of that function will be the amount of data transferred; if no data has been transferred and the timeout has been reached then -1 is returned with errno set to EAGAIN or EWOULDBLOCK, or EINPROGRESS (for connect(2)) just as if the socket was specified to be nonblocking. If the timeout is set to zero (the default) then the operation will never timeout. Timeouts only have effect for system calls that perform socket I/O (e.g., read(2), recvmsg(2), send(2), sendmsg(2)); timeouts have no effect for select(2), poll(2), epoll_wait(2), and so on. I think this bug can be closed.