From: guy Date: Wed, 6 Aug 2008 07:40:20 +0000 (+0000) Subject: From Patrick McHardy: Convert pcap-linux to use recvmsg() as preparation X-Git-Tag: libpcap-1.0.0~56 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/83b51abcee9dffe2a58c564fb390ce3a3e772f1a From Patrick McHardy: Convert pcap-linux to use recvmsg() as preparation for using PACKET_AUXDATA cmsgs. --- diff --git a/CREDITS b/CREDITS index 796caf4e..29009963 100644 --- a/CREDITS +++ b/CREDITS @@ -84,8 +84,9 @@ Additional people who have contributed patches: Olaf Kirch Ollie Wild Onno van der Linden - Patrick Marie Paolo Abeni + Patrick Marie + Patrick McHardy Paul Mundt Pavel Kankovsky Pawel Pokrywka diff --git a/pcap-linux.c b/pcap-linux.c index 8e314271..bef5c437 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -34,7 +34,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.129.2.21 2008-07-01 08:04:03 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.129.2.22 2008-08-06 07:40:20 guy Exp $ (LBL)"; #endif /* @@ -625,10 +625,10 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) #else struct sockaddr from; #endif - socklen_t fromlen; int packet_len, caplen; struct pcap_pkthdr pcap_header; - + struct iovec iov; + struct msghdr msg; #ifdef HAVE_PF_PACKET_SOCKETS /* * If this is a cooked device, leave extra room for a @@ -662,6 +662,18 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) * get notified of "network down" events. */ bp = handle->buffer + handle->offset; + + msg.msg_name = &from; + msg.msg_namelen = sizeof(from); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = 0; + + iov.iov_len = handle->bufsize - offset; + iov.iov_base = bp + offset; + do { /* * Has "pcap_breakloop()" been called? @@ -675,11 +687,8 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata) handle->break_loop = 0; return -2; } - fromlen = sizeof(from); - packet_len = recvfrom( - handle->fd, bp + offset, - handle->bufsize - offset, MSG_TRUNC, - (struct sockaddr *) &from, &fromlen); + + packet_len = recvmsg(handle->fd, &msg, MSG_TRUNC); } while (packet_len == -1 && (errno == EINTR || errno == ENETDOWN)); /* Check if an error occured */