ip_addr.c

来自「这是基于TI公司的DSP TMS320DM642而开发的TCP/UDP协议」· C语言 代码 · 共 40 行

C
40
字号


#include "ip_addr.h"

#include "netif.h"

/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */
const struct ip_addr ip_addr_any = { 0x00000000UL };
const struct ip_addr ip_addr_broadcast = { 0xffffffffUL };

/* Determine if an address is a broadcast address on a network interface 
 * 
 * @param addr address to be checked
 * @param netif the network interface against which the address is checked
 * @return returns non-zero if the address is a broadcast address
 *
 */

u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif)
{
  /* all ones (broadcast) or all zeroes (old skool broadcast) */
  if ((addr->addr == ip_addr_broadcast.addr) ||
      (addr->addr == ip_addr_any.addr))
    return 1;
  /* no broadcast support on this network interface? */
  else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0)
    /* the given address cannot be a broadcast address
     * nor can we check against any broadcast addresses */
    return 0;
  /* address matches network interface address exactly? => no broadcast */
  else if (addr->addr == netif->ip_addr)
    return 0;
  /* host identifier bits are all ones? => network broadcast address */
  else if ((addr->addr & ~netif->netmask) ==
           (ip_addr_broadcast.addr & ~netif->netmask))
    return 1;
  else
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?