diff --git a/firmware/lib/net.cpp b/firmware/lib/net.cpp index f032f87..7ae6412 100644 --- a/firmware/lib/net.cpp +++ b/firmware/lib/net.cpp @@ -44,6 +44,14 @@ static bool ip_match(const uint8_t* dst) { return memcmp(dst, state.ip.data(), 4) == 0; } +static bool ip_match_or_broadcast(const uint8_t* dst) { + static constexpr uint8_t bcast_all[4] = {255, 255, 255, 255}; + static constexpr uint8_t bcast_subnet[4] = {169, 254, 255, 255}; + return ip_match(dst) || + memcmp(dst, bcast_all, 4) == 0 || + memcmp(dst, bcast_subnet, 4) == 0; +} + static void send_raw(const uint8_t* data, size_t len) { dlog_if_slow("send_raw", 1000, [&]{ w6300::ip_address dummy = {}; @@ -88,7 +96,7 @@ static void handle_icmp(const uint8_t* frame, size_t len) { if (14 + ip_total_len > len) return; if (ip[9] != IP_PROTO_ICMP) return; - if (!ip_match(ip + 16)) return; + if (!ip_match_or_broadcast(ip + 16)) return; const uint8_t* icmp = ip + ip_hdr_len; size_t icmp_len = ip_total_len - ip_hdr_len; @@ -106,7 +114,7 @@ static void handle_icmp(const uint8_t* frame, size_t len) { uint8_t* rip = reply + 14; memcpy(rip, ip, ip_hdr_len); - memcpy(rip + 12, ip + 16, 4); + memcpy(rip + 12, state.ip.data(), 4); memcpy(rip + 16, ip + 12, 4); rip[8] = 64; memset(rip + 10, 0, 2);