tcpdump mailing list archives
[PATCH 01/04]: pcap-linux: convert to recvmsg()
From: Patrick McHardy <kaber () trash net>
Date: Fri, 18 Jul 2008 20:07:17 +0200
pcap-linux: convert to recvmsg()
From: Patrick McHardy <kaber () trash net>
Convert pcap-linux to use recvmsg() as preparation for using PACKET_AUXDATA
cmsgs.
---
pcap-linux.c | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/pcap-linux.c b/pcap-linux.c
index d9f9f10..8d9d302 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -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 */
- This is the tcpdump-workers list. Visit https://cod.sandelman.ca/ to unsubscribe.
Current thread:
- [PATCH 00/04]: libpcap: VLAN acceleration support Patrick McHardy (Jul 18)
- [PATCH 01/04]: pcap-linux: convert to recvmsg() Patrick McHardy (Jul 18)
- Re: [PATCH 01/04]: pcap-linux: convert to recvmsg() Guy Harris (Aug 06)
- [PATCH 04/04]: pcap-linux: reconstruct VLAN headers from tpacket2_hdr Patrick McHardy (Jul 18)
- Re: [PATCH 04/04]: pcap-linux: reconstruct VLAN headers from tpacket2_hdr Guy Harris (Aug 06)
- [PATCH 02/04]: pcap-linux: reconstruct VLAN header from PACKET_AUXDATA Patrick McHardy (Jul 18)
- Re: [PATCH 02/04]: pcap-linux: reconstruct VLAN header from PACKET_AUXDATA Guy Harris (Aug 06)
- [PATCH 03/04]: pcap-linux: support new tpacket frame header format Patrick McHardy (Jul 18)
- Re: [PATCH 03/04]: pcap-linux: support new tpacket frame header format Guy Harris (Aug 06)
- Re: [PATCH 00/04]: libpcap: VLAN acceleration support Guy Harris (Aug 06)
- [PATCH 01/04]: pcap-linux: convert to recvmsg() Patrick McHardy (Jul 18)
