My fork of the HTTPServer (working)

Dependents:   DGWWebServer LAN2

Committer:
screamer
Date:
Mon Aug 06 09:23:14 2012 +0000
Revision:
0:7a64fbb4069d
[mbed] converted /DGWWebServer/HTTPServer

Who changed what in which revision?

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