diff mbox series

[2/4] monitor: track current PCAP size

Message ID 20241127173328.158354-2-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [1/4] monitor: add --time-format,-t option | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood Nov. 27, 2024, 5:33 p.m. UTC
This will come into play when support for rolling captures is
added to iwmon.
---
 monitor/pcap.c | 10 ++++++++++
 monitor/pcap.h |  1 +
 2 files changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/monitor/pcap.c b/monitor/pcap.c
index fb29eea8..b13a29f3 100644
--- a/monitor/pcap.c
+++ b/monitor/pcap.c
@@ -60,6 +60,7 @@  struct pcap {
 	bool closed;
 	uint32_t type;
 	uint32_t snaplen;
+	size_t size;
 };
 
 struct pcap *pcap_open(const char *pathname)
@@ -152,6 +153,8 @@  struct pcap *pcap_create(const char *pathname)
 		goto failed;
 	}
 
+	pcap->size += len;
+
 	return pcap;
 
 failed:
@@ -188,6 +191,11 @@  uint32_t pcap_get_snaplen(struct pcap *pcap)
 	return pcap->snaplen;
 }
 
+size_t pcap_get_size(struct pcap *pcap)
+{
+	return pcap->size;
+}
+
 bool pcap_read(struct pcap *pcap, struct timeval *tv,
 		void *data, uint32_t size, uint32_t *len, uint32_t *real_len)
 {
@@ -279,5 +287,7 @@  bool pcap_write(struct pcap *pcap, const struct timeval *tv,
 		return false;
 	}
 
+	pcap->size += written;
+
 	return true;
 }
diff --git a/monitor/pcap.h b/monitor/pcap.h
index 1705b33d..5b797cf3 100644
--- a/monitor/pcap.h
+++ b/monitor/pcap.h
@@ -36,6 +36,7 @@  void pcap_close(struct pcap *pcap);
 
 uint32_t pcap_get_type(struct pcap *pcap);
 uint32_t pcap_get_snaplen(struct pcap *pcap);
+size_t pcap_get_size(struct pcap *pcap);
 
 bool pcap_read(struct pcap *pcap, struct timeval *tv,
 		void *data, uint32_t size, uint32_t *len, uint32_t *real_len);