aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--pcap.c18
-rw-r--r--pcap.h2
-rw-r--r--tcp.c3
3 files changed, 12 insertions, 11 deletions
diff --git a/pcap.c b/pcap.c
index 0c6dc89..7dca599 100644
--- a/pcap.c
+++ b/pcap.c
@@ -105,10 +105,12 @@ void pcap(const char *pkt, size_t len)
}
/**
- * pcapm() - Capture multiple frames from message header to pcap file
- * @mh: Pointer to sendmsg() message header buffer
+ * pcap_multiple() - Capture multiple frames
+ * @iov: Array of iovecs, one entry per frame
+ * @n: Number of frames to capture
+ * @offset: Offset of the frame within each iovec buffer
*/
-void pcapm(const struct msghdr *mh)
+void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offset)
{
struct timeval tv;
unsigned int i;
@@ -118,13 +120,11 @@ void pcapm(const struct msghdr *mh)
gettimeofday(&tv, NULL);
- for (i = 0; i < mh->msg_iovlen; i++) {
- const struct iovec *iov = &mh->msg_iov[i];
-
- if (pcap_frame((char *)iov->iov_base + 4,
- iov->iov_len - 4, &tv) != 0) {
+ for (i = 0; i < n; i++) {
+ if (pcap_frame((char *)iov[i].iov_base + offset,
+ iov[i].iov_len - offset, &tv) != 0) {
debug("Cannot log packet, length %lu",
- iov->iov_len - 4);
+ iov->iov_len - offset);
return;
}
}
diff --git a/pcap.h b/pcap.h
index 9e1736c..eafc89b 100644
--- a/pcap.h
+++ b/pcap.h
@@ -7,7 +7,7 @@
#define PCAP_H
void pcap(const char *pkt, size_t len);
-void pcapm(const struct msghdr *mh);
+void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offset);
void pcapmm(const struct mmsghdr *mmh, unsigned int vlen);
void pcap_init(struct ctx *c);
diff --git a/tcp.c b/tcp.c
index 4744ac5..95db256 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1472,7 +1472,8 @@ static void tcp_l2_buf_flush(struct ctx *c, struct msghdr *mh,
}
}
*buf_used = *buf_bytes = 0;
- pcapm(mh);
+
+ pcap_multiple(mh->msg_iov, mh->msg_iovlen, sizeof(uint32_t));
}
/**