A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Committer:
root@mbed.org
Date:
Tue May 08 15:32:10 2012 +0100
Revision:
0:5e1631496985
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
root@mbed.org 0:5e1631496985 1 /*
root@mbed.org 0:5e1631496985 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
root@mbed.org 0:5e1631496985 3 * All rights reserved.
root@mbed.org 0:5e1631496985 4 *
root@mbed.org 0:5e1631496985 5 * Redistribution and use in source and binary forms, with or without modification,
root@mbed.org 0:5e1631496985 6 * are permitted provided that the following conditions are met:
root@mbed.org 0:5e1631496985 7 *
root@mbed.org 0:5e1631496985 8 * 1. Redistributions of source code must retain the above copyright notice,
root@mbed.org 0:5e1631496985 9 * this list of conditions and the following disclaimer.
root@mbed.org 0:5e1631496985 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
root@mbed.org 0:5e1631496985 11 * this list of conditions and the following disclaimer in the documentation
root@mbed.org 0:5e1631496985 12 * and/or other materials provided with the distribution.
root@mbed.org 0:5e1631496985 13 * 3. The name of the author may not be used to endorse or promote products
root@mbed.org 0:5e1631496985 14 * derived from this software without specific prior written permission.
root@mbed.org 0:5e1631496985 15 *
root@mbed.org 0:5e1631496985 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
root@mbed.org 0:5e1631496985 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
root@mbed.org 0:5e1631496985 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
root@mbed.org 0:5e1631496985 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
root@mbed.org 0:5e1631496985 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
root@mbed.org 0:5e1631496985 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
root@mbed.org 0:5e1631496985 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
root@mbed.org 0:5e1631496985 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
root@mbed.org 0:5e1631496985 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
root@mbed.org 0:5e1631496985 25 * OF SUCH DAMAGE.
root@mbed.org 0:5e1631496985 26 *
root@mbed.org 0:5e1631496985 27 * This file is part of the lwIP TCP/IP stack.
root@mbed.org 0:5e1631496985 28 *
root@mbed.org 0:5e1631496985 29 * Author: Adam Dunkels <adam@sics.se>
root@mbed.org 0:5e1631496985 30 *
root@mbed.org 0:5e1631496985 31 */
root@mbed.org 0:5e1631496985 32 #ifndef __LWIP_IP_ADDR_H__
root@mbed.org 0:5e1631496985 33 #define __LWIP_IP_ADDR_H__
root@mbed.org 0:5e1631496985 34
root@mbed.org 0:5e1631496985 35 #include "lwip/opt.h"
root@mbed.org 0:5e1631496985 36
root@mbed.org 0:5e1631496985 37 #include "lwip/inet.h"
root@mbed.org 0:5e1631496985 38
root@mbed.org 0:5e1631496985 39 #ifdef __cplusplus
root@mbed.org 0:5e1631496985 40 extern "C" {
root@mbed.org 0:5e1631496985 41 #endif
root@mbed.org 0:5e1631496985 42
root@mbed.org 0:5e1631496985 43 #ifdef PACK_STRUCT_USE_INCLUDES
root@mbed.org 0:5e1631496985 44 # include "arch/bpstruct.h"
root@mbed.org 0:5e1631496985 45 #endif
root@mbed.org 0:5e1631496985 46 PACK_STRUCT_BEGIN
root@mbed.org 0:5e1631496985 47 struct ip_addr {
root@mbed.org 0:5e1631496985 48 PACK_STRUCT_FIELD(u32_t addr);
root@mbed.org 0:5e1631496985 49 } PACK_STRUCT_STRUCT;
root@mbed.org 0:5e1631496985 50 PACK_STRUCT_END
root@mbed.org 0:5e1631496985 51 #ifdef PACK_STRUCT_USE_INCLUDES
root@mbed.org 0:5e1631496985 52 # include "arch/epstruct.h"
root@mbed.org 0:5e1631496985 53 #endif
root@mbed.org 0:5e1631496985 54
root@mbed.org 0:5e1631496985 55 /*
root@mbed.org 0:5e1631496985 56 * struct ipaddr2 is used in the definition of the ARP packet format in
root@mbed.org 0:5e1631496985 57 * order to support compilers that don't have structure packing.
root@mbed.org 0:5e1631496985 58 */
root@mbed.org 0:5e1631496985 59 #ifdef PACK_STRUCT_USE_INCLUDES
root@mbed.org 0:5e1631496985 60 # include "arch/bpstruct.h"
root@mbed.org 0:5e1631496985 61 #endif
root@mbed.org 0:5e1631496985 62 PACK_STRUCT_BEGIN
root@mbed.org 0:5e1631496985 63 struct ip_addr2 {
root@mbed.org 0:5e1631496985 64 PACK_STRUCT_FIELD(u16_t addrw[2]);
root@mbed.org 0:5e1631496985 65 } PACK_STRUCT_STRUCT;
root@mbed.org 0:5e1631496985 66 PACK_STRUCT_END
root@mbed.org 0:5e1631496985 67 #ifdef PACK_STRUCT_USE_INCLUDES
root@mbed.org 0:5e1631496985 68 # include "arch/epstruct.h"
root@mbed.org 0:5e1631496985 69 #endif
root@mbed.org 0:5e1631496985 70
root@mbed.org 0:5e1631496985 71 struct netif;
root@mbed.org 0:5e1631496985 72
root@mbed.org 0:5e1631496985 73 extern const struct ip_addr ip_addr_any;
root@mbed.org 0:5e1631496985 74 extern const struct ip_addr ip_addr_broadcast;
root@mbed.org 0:5e1631496985 75
root@mbed.org 0:5e1631496985 76 /** IP_ADDR_ can be used as a fixed IP address
root@mbed.org 0:5e1631496985 77 * for the wildcard and the broadcast address
root@mbed.org 0:5e1631496985 78 */
root@mbed.org 0:5e1631496985 79 #define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any)
root@mbed.org 0:5e1631496985 80 #define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast)
root@mbed.org 0:5e1631496985 81
root@mbed.org 0:5e1631496985 82 /* Definitions of the bits in an Internet address integer.
root@mbed.org 0:5e1631496985 83
root@mbed.org 0:5e1631496985 84 On subnets, host and network parts are found according to
root@mbed.org 0:5e1631496985 85 the subnet mask, not these masks. */
root@mbed.org 0:5e1631496985 86
root@mbed.org 0:5e1631496985 87 #define IN_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0)
root@mbed.org 0:5e1631496985 88 #define IN_CLASSA_NET 0xff000000
root@mbed.org 0:5e1631496985 89 #define IN_CLASSA_NSHIFT 24
root@mbed.org 0:5e1631496985 90 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
root@mbed.org 0:5e1631496985 91 #define IN_CLASSA_MAX 128
root@mbed.org 0:5e1631496985 92
root@mbed.org 0:5e1631496985 93 #define IN_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
root@mbed.org 0:5e1631496985 94 #define IN_CLASSB_NET 0xffff0000
root@mbed.org 0:5e1631496985 95 #define IN_CLASSB_NSHIFT 16
root@mbed.org 0:5e1631496985 96 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
root@mbed.org 0:5e1631496985 97 #define IN_CLASSB_MAX 65536
root@mbed.org 0:5e1631496985 98
root@mbed.org 0:5e1631496985 99 #define IN_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
root@mbed.org 0:5e1631496985 100 #define IN_CLASSC_NET 0xffffff00
root@mbed.org 0:5e1631496985 101 #define IN_CLASSC_NSHIFT 8
root@mbed.org 0:5e1631496985 102 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
root@mbed.org 0:5e1631496985 103
root@mbed.org 0:5e1631496985 104 #define IN_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
root@mbed.org 0:5e1631496985 105 #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
root@mbed.org 0:5e1631496985 106 #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
root@mbed.org 0:5e1631496985 107 #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
root@mbed.org 0:5e1631496985 108 #define IN_MULTICAST(a) IN_CLASSD(a)
root@mbed.org 0:5e1631496985 109
root@mbed.org 0:5e1631496985 110 #define IN_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
root@mbed.org 0:5e1631496985 111 #define IN_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
root@mbed.org 0:5e1631496985 112
root@mbed.org 0:5e1631496985 113 #define IN_LOOPBACKNET 127 /* official! */
root@mbed.org 0:5e1631496985 114
root@mbed.org 0:5e1631496985 115 #define IP4_ADDR(ipaddr, a,b,c,d) \
root@mbed.org 0:5e1631496985 116 (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
root@mbed.org 0:5e1631496985 117 ((u32_t)((b) & 0xff) << 16) | \
root@mbed.org 0:5e1631496985 118 ((u32_t)((c) & 0xff) << 8) | \
root@mbed.org 0:5e1631496985 119 (u32_t)((d) & 0xff))
root@mbed.org 0:5e1631496985 120
root@mbed.org 0:5e1631496985 121 #define ip_addr_set(dest, src) (dest)->addr = \
root@mbed.org 0:5e1631496985 122 ((src) == NULL? 0:\
root@mbed.org 0:5e1631496985 123 (src)->addr)
root@mbed.org 0:5e1631496985 124 /**
root@mbed.org 0:5e1631496985 125 * Determine if two address are on the same network.
root@mbed.org 0:5e1631496985 126 *
root@mbed.org 0:5e1631496985 127 * @arg addr1 IP address 1
root@mbed.org 0:5e1631496985 128 * @arg addr2 IP address 2
root@mbed.org 0:5e1631496985 129 * @arg mask network identifier mask
root@mbed.org 0:5e1631496985 130 * @return !0 if the network identifiers of both address match
root@mbed.org 0:5e1631496985 131 */
root@mbed.org 0:5e1631496985 132 #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
root@mbed.org 0:5e1631496985 133 (mask)->addr) == \
root@mbed.org 0:5e1631496985 134 ((addr2)->addr & \
root@mbed.org 0:5e1631496985 135 (mask)->addr))
root@mbed.org 0:5e1631496985 136 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
root@mbed.org 0:5e1631496985 137
root@mbed.org 0:5e1631496985 138 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
root@mbed.org 0:5e1631496985 139
root@mbed.org 0:5e1631496985 140 u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
root@mbed.org 0:5e1631496985 141
root@mbed.org 0:5e1631496985 142 #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL))
root@mbed.org 0:5e1631496985 143
root@mbed.org 0:5e1631496985 144 #define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
root@mbed.org 0:5e1631496985 145
root@mbed.org 0:5e1631496985 146 #define ip_addr_debug_print(debug, ipaddr) \
root@mbed.org 0:5e1631496985 147 LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
root@mbed.org 0:5e1631496985 148 ipaddr != NULL ? \
root@mbed.org 0:5e1631496985 149 (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \
root@mbed.org 0:5e1631496985 150 ipaddr != NULL ? \
root@mbed.org 0:5e1631496985 151 (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \
root@mbed.org 0:5e1631496985 152 ipaddr != NULL ? \
root@mbed.org 0:5e1631496985 153 (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \
root@mbed.org 0:5e1631496985 154 ipaddr != NULL ? \
root@mbed.org 0:5e1631496985 155 (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
root@mbed.org 0:5e1631496985 156
root@mbed.org 0:5e1631496985 157 /* These are cast to u16_t, with the intent that they are often arguments
root@mbed.org 0:5e1631496985 158 * to printf using the U16_F format from cc.h. */
root@mbed.org 0:5e1631496985 159 #define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
root@mbed.org 0:5e1631496985 160 #define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
root@mbed.org 0:5e1631496985 161 #define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
root@mbed.org 0:5e1631496985 162 #define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)
root@mbed.org 0:5e1631496985 163
root@mbed.org 0:5e1631496985 164 /**
root@mbed.org 0:5e1631496985 165 * Same as inet_ntoa() but takes a struct ip_addr*
root@mbed.org 0:5e1631496985 166 */
root@mbed.org 0:5e1631496985 167 #define ip_ntoa(addr) ((addr != NULL) ? inet_ntoa(*((struct in_addr*)(addr))) : "NULL")
root@mbed.org 0:5e1631496985 168
root@mbed.org 0:5e1631496985 169 #ifdef __cplusplus
root@mbed.org 0:5e1631496985 170 }
root@mbed.org 0:5e1631496985 171 #endif
root@mbed.org 0:5e1631496985 172
root@mbed.org 0:5e1631496985 173 #endif /* __LWIP_IP_ADDR_H__ */