From 4c58c62cfe9a6aa73508b7598e32276cfe83c523 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Wed, 26 Apr 2023 15:09:27 -0300 Subject: [PATCH] Fix UDP listeners --- mongoose.c | 4 +++- src/tcpip/tcpip.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index 1cc814e4..5e544ad8 100644 --- a/mongoose.c +++ b/mongoose.c @@ -7848,9 +7848,11 @@ static void rx_udp(struct mg_tcpip_if *ifp, struct pkt *pkt) { struct mg_connection *c = getpeer(ifp->mgr, pkt, true); if (c == NULL) { // No UDP listener on this port. Should send ICMP, but keep silent. - } else if (c != NULL) { + } else { c->rem.port = pkt->udp->sport; c->rem.ip = pkt->ip->src; + struct connstate *s = (struct connstate *) (c + 1); + memcpy(s->mac, pkt->eth->src, sizeof(s->mac)); if (c->recv.len >= MG_MAX_RECV_SIZE) { mg_error(c, "max_recv_buf_size reached"); } else if (c->recv.size - c->recv.len < pkt->pay.len && diff --git a/src/tcpip/tcpip.c b/src/tcpip/tcpip.c index d6649861..904d57f5 100644 --- a/src/tcpip/tcpip.c +++ b/src/tcpip/tcpip.c @@ -404,9 +404,11 @@ static void rx_udp(struct mg_tcpip_if *ifp, struct pkt *pkt) { struct mg_connection *c = getpeer(ifp->mgr, pkt, true); if (c == NULL) { // No UDP listener on this port. Should send ICMP, but keep silent. - } else if (c != NULL) { + } else { c->rem.port = pkt->udp->sport; c->rem.ip = pkt->ip->src; + struct connstate *s = (struct connstate *) (c + 1); + memcpy(s->mac, pkt->eth->src, sizeof(s->mac)); if (c->recv.len >= MG_MAX_RECV_SIZE) { mg_error(c, "max_recv_buf_size reached"); } else if (c->recv.size - c->recv.len < pkt->pay.len &&