Merge pull request #2173 from cesanta/arp

Add multicast and local broadcast MAC resolution
This commit is contained in:
Sergey Lyubka 2023-04-29 12:01:01 +01:00 committed by GitHub
commit 5cebce3f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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));

View File

@ -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));