|
||||
Warning, cross-references for /kernel/lwip/core/ipv4/ip_addr.c need to be fixed.
0001 /** 0002 * @file 0003 * This is the IPv4 address tools implementation. 0004 * 0005 */ 0006 0007 /* 0008 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 0009 * All rights reserved. 0010 * 0011 * Redistribution and use in source and binary forms, with or without modification, 0012 * are permitted provided that the following conditions are met: 0013 * 0014 * 1. Redistributions of source code must retain the above copyright notice, 0015 * this list of conditions and the following disclaimer. 0016 * 2. Redistributions in binary form must reproduce the above copyright notice, 0017 * this list of conditions and the following disclaimer in the documentation 0018 * and/or other materials provided with the distribution. 0019 * 3. The name of the author may not be used to endorse or promote products 0020 * derived from this software without specific prior written permission. 0021 * 0022 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 0023 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 0024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 0025 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 0026 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 0027 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0028 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0029 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 0030 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 0031 * OF SUCH DAMAGE. 0032 * 0033 * This file is part of the lwIP TCP/IP stack. 0034 * 0035 * Author: Adam Dunkels <adam@sics.se> 0036 * 0037 */ 0038 0039 #include "lwip/opt.h" 0040 #include "lwip/ip_addr.h" 0041 #include "lwip/inet.h" 0042 #include "lwip/netif.h" 0043 0044 #define IP_ADDR_ANY_VALUE 0x00000000UL 0045 #define IP_ADDR_BROADCAST_VALUE 0xffffffffUL 0046 0047 /* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */ 0048 const struct ip_addr ip_addr_any = { IP_ADDR_ANY_VALUE }; 0049 const struct ip_addr ip_addr_broadcast = { IP_ADDR_BROADCAST_VALUE }; 0050 0051 /** 0052 * Determine if an address is a broadcast address on a network interface 0053 * 0054 * @param addr address to be checked 0055 * @param netif the network interface against which the address is checked 0056 * @return returns non-zero if the address is a broadcast address 0057 */ 0058 u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif) 0059 { 0060 u32_t addr2test; 0061 0062 addr2test = addr->addr; 0063 /* all ones (broadcast) or all zeroes (old skool broadcast) */ 0064 if ((~addr2test == IP_ADDR_ANY_VALUE) || 0065 (addr2test == IP_ADDR_ANY_VALUE)) 0066 return 1; 0067 /* no broadcast support on this network interface? */ 0068 else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0) 0069 /* the given address cannot be a broadcast address 0070 * nor can we check against any broadcast addresses */ 0071 return 0; 0072 /* address matches network interface address exactly? => no broadcast */ 0073 else if (addr2test == netif->ip_addr.addr) 0074 return 0; 0075 /* on the same (sub) network... */ 0076 else if (ip_addr_netcmp(addr, &(netif->ip_addr), &(netif->netmask)) 0077 /* ...and host identifier bits are all ones? =>... */ 0078 && ((addr2test & ~netif->netmask.addr) == 0079 (IP_ADDR_BROADCAST_VALUE & ~netif->netmask.addr))) 0080 /* => network broadcast address */ 0081 return 1; 0082 else 0083 return 0; 0084 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 1.2.0 LXR engine. |