Replaced ip_addr_isbroadcast() macro by function.

Overrides patch #2679, as this must be solved inside ip_addr_isbroadcast(), inspired by BSD.
This commit is contained in:
likewise
2004-03-11 21:20:10 +00:00
parent 6434f7efad
commit 10d42c6fa3
8 changed files with 26 additions and 29 deletions

View File

@@ -72,9 +72,8 @@ icmp_input(struct pbuf *p, struct netif *inp)
code = *(((u8_t *)p->payload)+1);
switch (type) {
case ICMP_ECHO:
if (((inp->flags & NETIF_FLAG_BROADCAST) &&
ip_addr_isbroadcast(&iphdr->dest, &inp->netmask)) ||
ip_addr_ismulticast(&iphdr->dest)) {
/* broadcast or multicast destination address? */
if (ip_addr_isbroadcast(&iphdr->dest, inp) || ip_addr_ismulticast(&iphdr->dest)) {
LWIP_DEBUGF(ICMP_DEBUG, ("Smurf.\n"));
ICMP_STATS_INC(icmp.err);
pbuf_free(p);

View File

@@ -241,7 +241,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
/* unicast to this interface address? */
if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
/* or broadcast matching this interface network address? */
(ip_addr_isbroadcast(&(iphdr->dest), &(netif->netmask)) &&
(ip_addr_isbroadcast(&(iphdr->dest), netif) &&
ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) ||
/* or restricted broadcast? */
ip_addr_cmp(&(iphdr->dest), IP_ADDR_BROADCAST)) {
@@ -274,7 +274,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
LWIP_DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n"));
#if IP_FORWARD
/* non-broadcast packet? */
if (!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) {
if (!ip_addr_isbroadcast(&(iphdr->dest), inp)) {
/* try to forward IP packet on (other) interfaces */
ip_forward(p, iphdr, inp);
}
@@ -349,8 +349,8 @@ ip_input(struct pbuf *p, struct netif *inp) {
break;
default:
/* send ICMP destination protocol unreachable unless is was a broadcast */
if (!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) &&
!ip_addr_ismulticast(&(iphdr->dest))) {
if (!ip_addr_isbroadcast(&(iphdr->dest), inp) &&
!ip_addr_ismulticast(&(iphdr->dest))) {
p->payload = iphdr;
icmp_dest_unreach(p, ICMP_DUR_PROTO);
}

View File

@@ -41,27 +41,25 @@ const struct ip_addr ip_addr_broadcast = { 0xffffffffUL };
* as it does not support non-broadcast interfaces.
* lwip-devel 18-2-2004
*/
#if 0
#if 1 /* replaces macro in ip_addr.h */
#include "lwip/netif.h"
bool ip_addr_isbroadcast(ip_addr *addr1, struct netif *netif)
bool ip_addr_isbroadcast(addr1, netif)
u8_t ip_addr_isbroadcast(struct ip_addr *addr, netif)
{
/* all ones (broadcast) or all zeroes (old skool broadcast) */
if (addr1->addr == ip_addr_broadcast.ip_addr) ||
addr1->addr == ip_addr_any.ip_addr))
if (addr->addr == ip_addr_broadcast.ip_addr) ||
addr->addr == ip_addr_any.ip_addr))
return 1;
/* no broadcast support on this network interface
* we cannot proceed matching against broadcast addresses */
else if (netif->flags &= NETIF_FLAG_BROADCAST == 0)
return 0;
/* address matches network interface address exactly? */
else if (netif->ip_addr.addr == addr1->addr)
/* address matches network interface address exactly? => no broadcast */
else if (addr->addr == netif->ip_addr.addr)
return 0;
/* host identifier bits are all ones? => broadcast address */
else if (~netif->netmask.addr & addr1->addr ==
~netif->netmask.addr & ip_addr_broadcast.ip_addr)
/* host identifier bits are all ones? => network broadcast address */
else if (addr->addr & ~netif->netmask.addr ==
ip_addr_broadcast.ip_addr & ~netif->netmask.addr)
return 1;
else
return 0;