File libpcap-0.9.8-socket-timeout.diff of Package libpcap

Index: pcap-linux.c
===================================================================
--- pcap-linux.c.orig
+++ pcap-linux.c
@@ -1811,6 +1811,18 @@ activate_new(pcap_t *handle)
 	}
 	handle->bufsize = handle->snapshot;
 
+	if (to_ms > 0) {
+	    struct timeval timeout;
+	    timeout.tv_sec = to_ms / 1000;
+	    timeout.tv_usec = (to_ms * 1000) % 1000000;
+	    if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO,
+			    &timeout, sizeof(timeout)) == -1) {
+		snprintf(ebuf, PCAP_ERRBUF_SIZE,
+			 "setsockopt: %s", pcap_strerror(errno));
+		break;
+	    };
+	}
+
 	/* Save the socket FD in the pcap structure */
 	handle->fd = sock_fd;