Portable capture of destination interface and IP address

Use recvmsg() and control messages IP_PKTINFO (Linux, OSX, Windows)
or IP_ORIGDSTADDR and IP_RECVIF (RTEMS w/ libbsd) to find the
index of the logical interface through which a UDP packet was received,
and the destination address from the IPv4 header.

Also, clear IP_MULTICAST_ALL on Linux to disable non-compliant legacy brokenness
and receive only those multicasts we are interested in.
This commit is contained in:
Michael Davidsaver
2021-07-26 10:13:40 -07:00
parent fe6974025a
commit f67f27e96b
12 changed files with 723 additions and 142 deletions
+5 -6
View File
@@ -750,14 +750,13 @@ bool ContextImpl::onSearch()
{
searchMsg.resize(0x10000);
SockAddr src;
uint32_t ndrop = 0u;
osiSocklen_t alen = src.size();
const int nrx = recvfromx(searchTx.sock, (char*)&searchMsg[0], searchMsg.size()-1, &src->sa, &alen, &ndrop);
recvfromx rx{searchTx.sock, (char*)&searchMsg[0], searchMsg.size()-1, &src};
const int nrx = rx.call();
if(nrx>=0 && ndrop!=0 && prevndrop!=ndrop) {
log_debug_printf(io, "UDP search reply buffer overflow %u -> %u\n", unsigned(prevndrop), unsigned(ndrop));
prevndrop = ndrop;
if(nrx>=0 && rx.ndrop!=0 && prevndrop!=rx.ndrop) {
log_debug_printf(io, "UDP search reply buffer overflow %u -> %u\n", unsigned(prevndrop), unsigned(rx.ndrop));
prevndrop = rx.ndrop;
}
if(nrx<0) {