Use built-in LWIP call to determine NetBIOS IP (#2235)
Instead of manually iterating over netifs to find the one a packet came in over for NetBIOS name lookup, use a built-in LWIP macro that's available for udp_recv callbacks. Shrinks and simplifies NetBIOS code.
This commit is contained in:
parent
2297d61d92
commit
7df8c35e81
1 changed files with 2 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "NetBIOS.h"
|
||||
#include <functional>
|
||||
#include <lwip/ip.h>
|
||||
#include <lwip/netif.h>
|
||||
|
||||
#define NBNS_PORT 137
|
||||
|
|
@ -92,17 +93,7 @@ void NetBIOS::_onPacket(AsyncUDPPacket &packet) {
|
|||
append_32((void *)&nbnsa.ttl, 300000);
|
||||
append_16((void *)&nbnsa.data_len, 6);
|
||||
append_16((void *)&nbnsa.flags, 0);
|
||||
nbnsa.addr = packet.localIP(); // Wrong, but better than nothing
|
||||
// Iterate over all netifs, see if the incoming address matches one of the netmaskes networks
|
||||
// TODO - is there an easier way of seeing whicn netif produced a packet?
|
||||
for (auto netif = netif_list; netif; netif = netif->next) {
|
||||
auto maskedip = ip4_addr_get_u32(netif_ip4_addr(netif)) & ip4_addr_get_u32(netif_ip4_netmask(netif));
|
||||
auto maskedin = ((uint32_t)packet.localIP()) & ip4_addr_get_u32(netif_ip4_netmask(netif));
|
||||
if (maskedip == maskedin) {
|
||||
nbnsa.addr = ip4_addr_get_u32(netif_ip4_addr(netif));
|
||||
break;
|
||||
}
|
||||
}
|
||||
nbnsa.addr = ip4_addr_get_u32(&ip_current_netif()->ip_addr);
|
||||
_udp.writeTo((uint8_t *)&nbnsa, sizeof(nbnsa), packet.remoteIP(), NBNS_PORT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue