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