diff --git a/mongoose.c b/mongoose.c index 81e5adaf..a0ea0cda 100644 --- a/mongoose.c +++ b/mongoose.c @@ -8324,6 +8324,15 @@ void mg_connect_resolved(struct mg_connection *c) { MG_DEBUG(("%lu ARP lookup...", c->id)); arp_ask(ifp, c->rem.ip); c->is_arplooking = 1; + } else if (c->rem.ip == (ifp->ip | ~ifp->mask)) { + struct connstate *s = (struct connstate *) (c + 1); + memset(s->mac, 0xFF, sizeof(s->mac)); // local broadcast + } else if ((*((uint8_t *) &c->rem.ip) & 0xE0) == 0xE0) { + struct connstate *s = (struct connstate *) (c + 1); // 224 to 239, E0 to EF + uint8_t mcastp[3] = {0x01, 0x00, 0x5E}; // multicast group + memcpy(s->mac, mcastp, 3); + memcpy(s->mac + 3, ((uint8_t *) &c->rem.ip) + 1, 3); // 23 LSb + s->mac[3] &= 0x7F; } else { struct connstate *s = (struct connstate *) (c + 1); memcpy(s->mac, ifp->gwmac, sizeof(ifp->gwmac)); diff --git a/src/tcpip/tcpip.c b/src/tcpip/tcpip.c index 40d9f18e..c43cf7de 100644 --- a/src/tcpip/tcpip.c +++ b/src/tcpip/tcpip.c @@ -878,6 +878,15 @@ void mg_connect_resolved(struct mg_connection *c) { MG_DEBUG(("%lu ARP lookup...", c->id)); arp_ask(ifp, c->rem.ip); c->is_arplooking = 1; + } else if (c->rem.ip == (ifp->ip | ~ifp->mask)) { + struct connstate *s = (struct connstate *) (c + 1); + memset(s->mac, 0xFF, sizeof(s->mac)); // local broadcast + } else if ((*((uint8_t *) &c->rem.ip) & 0xE0) == 0xE0) { + struct connstate *s = (struct connstate *) (c + 1); // 224 to 239, E0 to EF + uint8_t mcastp[3] = {0x01, 0x00, 0x5E}; // multicast group + memcpy(s->mac, mcastp, 3); + memcpy(s->mac + 3, ((uint8_t *) &c->rem.ip) + 1, 3); // 23 LSb + s->mac[3] &= 0x7F; } else { struct connstate *s = (struct connstate *) (c + 1); memcpy(s->mac, ifp->gwmac, sizeof(ifp->gwmac));