#include <sys/types.h>
#include <sys/socket.h>
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
设置接收超时
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
超时返回错误:Resource temporarily unavailable
UDP接收ICMP端口不可达
int optval = 1;
setsockopt(sockfd, IPPROTO_IP, IP_RECVERR, &optval, sizeof optval);