From cd7b0b0a7b4fe266aa96248ef4726d002ff51575 Mon Sep 17 00:00:00 2001 From: Kyle Schwarz Date: Wed, 29 Mar 2023 00:51:38 -0400 Subject: [PATCH] Driver: PCAP: Properly handle RX timeout If res == 0 the header and data will not be populated because no message was RXed. --- platform/posix/pcap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/posix/pcap.cpp b/platform/posix/pcap.cpp index a43058c..451fe77 100644 --- a/platform/posix/pcap.cpp +++ b/platform/posix/pcap.cpp @@ -140,6 +140,8 @@ void PCAP::Find(std::vector& found) { struct pcap_pkthdr* header; const uint8_t* data; auto res = pcap_next_ex(iface.fp, &header, &data); + if(res == 0) + continue; if(res < 0 || !header || !data) { if (!warned) { warned = true; @@ -148,8 +150,6 @@ void PCAP::Find(std::vector& found) { } break; } - if(res == 0) - continue; // Keep waiting for that packet EthernetPacketizer ethPacketizer([](APIEvent::Type, APIEvent::Severity) {}); memcpy(ethPacketizer.hostMAC, iface.macAddress, sizeof(ethPacketizer.hostMAC));