diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index 1b0ea266..a317ae42 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -85,7 +85,7 @@ ip_route(struct ip_addr *dest) /* iterate through netifs */ for(netif = netif_list; netif != NULL; netif = netif->next) { /* network mask matches? */ - if (ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) { + if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) { /* return netif on which to forward IP packet */ return netif; } @@ -240,7 +240,7 @@ ip_input(struct pbuf *p, struct netif *inp) { if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) || /* or broadcast matching this interface network address? */ (ip_addr_isbroadcast(&(iphdr->dest), netif) && - ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) || + ip_addr_netcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) || /* or restricted broadcast? */ ip_addr_cmp(&(iphdr->dest), IP_ADDR_BROADCAST)) { LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n", diff --git a/src/core/ipv4/ip_addr.c b/src/core/ipv4/ip_addr.c index 9bf000ba..55c9b4f4 100644 --- a/src/core/ipv4/ip_addr.c +++ b/src/core/ipv4/ip_addr.c @@ -60,8 +60,10 @@ u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif) /* address matches network interface address exactly? => no broadcast */ else if (addr->addr == netif->ip_addr.addr) return 0; - /* host identifier bits are all ones? => network broadcast address */ - else if ((addr->addr & ~netif->netmask.addr) == + /* on the same (sub) network and + * host identifier bits are all ones? => network broadcast address */ + else if (ip_addr_netcmp(addr->addr, netif->ip_addr.addr, netif->netmask.addr)) + && ((addr->addr & ~netif->netmask.addr) == (ip_addr_broadcast.addr & ~netif->netmask.addr)) return 1; else diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 403e4de0..abce830c 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -77,7 +77,7 @@ ip_route(struct ip_addr *dest) struct netif *netif; for(netif = netif_list; netif != NULL; netif = netif->next) { - if (ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) { + if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) { return netif; } } diff --git a/src/core/ipv6/ip6_addr.c b/src/core/ipv6/ip6_addr.c index 3e11e07e..d1bc358a 100644 --- a/src/core/ipv6/ip6_addr.c +++ b/src/core/ipv6/ip6_addr.c @@ -35,7 +35,7 @@ int -ip_addr_maskcmp(struct ip_addr *addr1, struct ip_addr *addr2, +ip_addr_netcmp(struct ip_addr *addr1, struct ip_addr *addr2, struct ip_addr *mask) { return((addr1->addr[0] & mask->addr[0]) == (addr2->addr[0] & mask->addr[0]) && diff --git a/src/include/ipv4/lwip/ip_addr.h b/src/include/ipv4/lwip/ip_addr.h index 58820bdf..0ef99937 100644 --- a/src/include/ipv4/lwip/ip_addr.h +++ b/src/include/ipv4/lwip/ip_addr.h @@ -125,7 +125,7 @@ extern const struct ip_addr ip_addr_broadcast; * @arg mask network identifier mask * @return !0 if the network identifiers of both address match */ -#define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \ +#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ (mask)->addr) == \ ((addr2)->addr & \ (mask)->addr)) diff --git a/src/include/ipv6/lwip/ip_addr.h b/src/include/ipv6/lwip/ip_addr.h index 40c698ec..08e962dd 100644 --- a/src/include/ipv6/lwip/ip_addr.h +++ b/src/include/ipv6/lwip/ip_addr.h @@ -45,7 +45,7 @@ struct ip_addr { (ipaddr)->addr[2] = htonl(((e & 0xffff) << 16) | (f & 0xffff)); \ (ipaddr)->addr[3] = htonl(((g & 0xffff) << 16) | (h & 0xffff)); } while(0) -int ip_addr_maskcmp(struct ip_addr *addr1, struct ip_addr *addr2, +int ip_addr_netcmp(struct ip_addr *addr1, struct ip_addr *addr2, struct ip_addr *mask); int ip_addr_cmp(struct ip_addr *addr1, struct ip_addr *addr2); void ip_addr_set(struct ip_addr *dest, struct ip_addr *src);