Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(netbios): Return interface address for NetBIOS name lookup #9885

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion libraries/NetBIOS/src/NetBIOS.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "NetBIOS.h"
#include <functional>
extern "C" {
#include <lwip/netif.h>
}; // extern "C"

#define NBNS_PORT 137
#define NBNS_MAX_HOSTNAME_LEN 32
Expand Down Expand Up @@ -91,7 +94,16 @@ 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();
nbnsa.addr = packet.localIP(); // By default, should be overridden below
// Iterate over all netifs, see if the incoming address matches one of the netmaskes networks
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;
}
}
_udp.writeTo((uint8_t *)&nbnsa, sizeof(nbnsa), packet.remoteIP(), NBNS_PORT);
}
}
Expand Down
Loading