face: put the pcap handle in non-blocking mode
This prevents NFD from getting stuck in pcap_next_ex()
when the network interface goes down
Change-Id: I5760fcc7c950b46aecb7619bd889508ee24133aa
diff --git a/daemon/face/pcap-helper.cpp b/daemon/face/pcap-helper.cpp
index 637faaf..230e5af 100644
--- a/daemon/face/pcap-helper.cpp
+++ b/daemon/face/pcap-helper.cpp
@@ -69,6 +69,10 @@
NDN_THROW(Error("pcap_activate: " + std::string(pcap_statustostr(ret))));
});
+ char errbuf[PCAP_ERRBUF_SIZE] = {};
+ if (pcap_setnonblock(m_pcap, 1, errbuf) < 0)
+ NDN_THROW(Error("pcap_setnonblock: " + std::string(errbuf)));
+
if (pcap_set_datalink(m_pcap, dlt) < 0)
NDN_THROW(Error("pcap_set_datalink: " + getLastError()));
@@ -136,7 +140,7 @@
if (ret < 0)
return {span<uint8_t>{}, getLastError()};
else if (ret == 0)
- return {span<uint8_t>{}, "timed out"};
+ return {span<uint8_t>{}, "Nothing to read"};
else
return {{packet, header->caplen}, ""};
}