From bfc294b90dc46d132a56dc0a2ae118f2bea5a266 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 18 Sep 2024 20:44:05 +1000 Subject: util: Add helper to write() all of a buffer write(2) might not write all the data it is given. Add a write_all_buf() helper to keep calling it until all the given data is written, or we get an error. Currently we use write_remainder() to do this operation in pcap_frame(). That's a little awkward since it requires constructing an iovec, and future changes we want to make to write_remainder() will be easier in terms of this single buffer helper. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- pcap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pcap.c') diff --git a/pcap.c b/pcap.c index 46cc4b0..e6b5ced 100644 --- a/pcap.c +++ b/pcap.c @@ -86,9 +86,8 @@ static void pcap_frame(const struct iovec *iov, size_t iovcnt, .caplen = l2len, .len = l2len }; - struct iovec hiov = { &h, sizeof(h) }; - if (write_remainder(pcap_fd, &hiov, 1, 0) < 0 || + if (write_all_buf(pcap_fd, &h, sizeof(h)) < 0 || write_remainder(pcap_fd, iov, iovcnt, offset) < 0) debug_perror("Cannot log packet, length %zu", l2len); } -- cgit v1.2.3