Port of LwIP performed by Ralf in 2010. Not recommended for use with recent mbed libraries, but good demos of raw LwIP possible

Dependents:   LwIP_raw_API_serverExample tiny-dtls

Committer:
RodColeman
Date:
Tue Sep 18 14:41:24 2012 +0000
Revision:
0:0791c1fece8e
[mbed] converted /Eth_TCP_Wei_Server/lwip

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:0791c1fece8e 1 /**
RodColeman 0:0791c1fece8e 2 * @file
RodColeman 0:0791c1fece8e 3 * This is the IPv4 address tools implementation.
RodColeman 0:0791c1fece8e 4 *
RodColeman 0:0791c1fece8e 5 */
RodColeman 0:0791c1fece8e 6
RodColeman 0:0791c1fece8e 7 /*
RodColeman 0:0791c1fece8e 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
RodColeman 0:0791c1fece8e 9 * All rights reserved.
RodColeman 0:0791c1fece8e 10 *
RodColeman 0:0791c1fece8e 11 * Redistribution and use in source and binary forms, with or without modification,
RodColeman 0:0791c1fece8e 12 * are permitted provided that the following conditions are met:
RodColeman 0:0791c1fece8e 13 *
RodColeman 0:0791c1fece8e 14 * 1. Redistributions of source code must retain the above copyright notice,
RodColeman 0:0791c1fece8e 15 * this list of conditions and the following disclaimer.
RodColeman 0:0791c1fece8e 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
RodColeman 0:0791c1fece8e 17 * this list of conditions and the following disclaimer in the documentation
RodColeman 0:0791c1fece8e 18 * and/or other materials provided with the distribution.
RodColeman 0:0791c1fece8e 19 * 3. The name of the author may not be used to endorse or promote products
RodColeman 0:0791c1fece8e 20 * derived from this software without specific prior written permission.
RodColeman 0:0791c1fece8e 21 *
RodColeman 0:0791c1fece8e 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
RodColeman 0:0791c1fece8e 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
RodColeman 0:0791c1fece8e 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
RodColeman 0:0791c1fece8e 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
RodColeman 0:0791c1fece8e 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
RodColeman 0:0791c1fece8e 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
RodColeman 0:0791c1fece8e 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
RodColeman 0:0791c1fece8e 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
RodColeman 0:0791c1fece8e 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
RodColeman 0:0791c1fece8e 31 * OF SUCH DAMAGE.
RodColeman 0:0791c1fece8e 32 *
RodColeman 0:0791c1fece8e 33 * This file is part of the lwIP TCP/IP stack.
RodColeman 0:0791c1fece8e 34 *
RodColeman 0:0791c1fece8e 35 * Author: Adam Dunkels <adam@sics.se>
RodColeman 0:0791c1fece8e 36 *
RodColeman 0:0791c1fece8e 37 */
RodColeman 0:0791c1fece8e 38
RodColeman 0:0791c1fece8e 39 #include "lwip/opt.h"
RodColeman 0:0791c1fece8e 40 #include "lwip/ip_addr.h"
RodColeman 0:0791c1fece8e 41 #include "lwip/inet.h"
RodColeman 0:0791c1fece8e 42 #include "lwip/netif.h"
RodColeman 0:0791c1fece8e 43
RodColeman 0:0791c1fece8e 44 #define IP_ADDR_ANY_VALUE 0x00000000UL
RodColeman 0:0791c1fece8e 45 #define IP_ADDR_BROADCAST_VALUE 0xffffffffUL
RodColeman 0:0791c1fece8e 46
RodColeman 0:0791c1fece8e 47 /* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */
RodColeman 0:0791c1fece8e 48 const struct ip_addr ip_addr_any = { IP_ADDR_ANY_VALUE };
RodColeman 0:0791c1fece8e 49 const struct ip_addr ip_addr_broadcast = { IP_ADDR_BROADCAST_VALUE };
RodColeman 0:0791c1fece8e 50
RodColeman 0:0791c1fece8e 51 /**
RodColeman 0:0791c1fece8e 52 * Determine if an address is a broadcast address on a network interface
RodColeman 0:0791c1fece8e 53 *
RodColeman 0:0791c1fece8e 54 * @param addr address to be checked
RodColeman 0:0791c1fece8e 55 * @param netif the network interface against which the address is checked
RodColeman 0:0791c1fece8e 56 * @return returns non-zero if the address is a broadcast address
RodColeman 0:0791c1fece8e 57 */
RodColeman 0:0791c1fece8e 58 u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif)
RodColeman 0:0791c1fece8e 59 {
RodColeman 0:0791c1fece8e 60 u32_t addr2test;
RodColeman 0:0791c1fece8e 61
RodColeman 0:0791c1fece8e 62 addr2test = addr->addr;
RodColeman 0:0791c1fece8e 63 /* all ones (broadcast) or all zeroes (old skool broadcast) */
RodColeman 0:0791c1fece8e 64 if ((~addr2test == IP_ADDR_ANY_VALUE) ||
RodColeman 0:0791c1fece8e 65 (addr2test == IP_ADDR_ANY_VALUE))
RodColeman 0:0791c1fece8e 66 return 1;
RodColeman 0:0791c1fece8e 67 /* no broadcast support on this network interface? */
RodColeman 0:0791c1fece8e 68 else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0)
RodColeman 0:0791c1fece8e 69 /* the given address cannot be a broadcast address
RodColeman 0:0791c1fece8e 70 * nor can we check against any broadcast addresses */
RodColeman 0:0791c1fece8e 71 return 0;
RodColeman 0:0791c1fece8e 72 /* address matches network interface address exactly? => no broadcast */
RodColeman 0:0791c1fece8e 73 else if (addr2test == netif->ip_addr.addr)
RodColeman 0:0791c1fece8e 74 return 0;
RodColeman 0:0791c1fece8e 75 /* on the same (sub) network... */
RodColeman 0:0791c1fece8e 76 else if (ip_addr_netcmp(addr, &(netif->ip_addr), &(netif->netmask))
RodColeman 0:0791c1fece8e 77 /* ...and host identifier bits are all ones? =>... */
RodColeman 0:0791c1fece8e 78 && ((addr2test & ~netif->netmask.addr) ==
RodColeman 0:0791c1fece8e 79 (IP_ADDR_BROADCAST_VALUE & ~netif->netmask.addr)))
RodColeman 0:0791c1fece8e 80 /* => network broadcast address */
RodColeman 0:0791c1fece8e 81 return 1;
RodColeman 0:0791c1fece8e 82 else
RodColeman 0:0791c1fece8e 83 return 0;
RodColeman 0:0791c1fece8e 84 }