Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1 /*
hlipka 0:8b387bed54c2 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
hlipka 0:8b387bed54c2 3 * All rights reserved.
hlipka 0:8b387bed54c2 4 *
hlipka 0:8b387bed54c2 5 * Redistribution and use in source and binary forms, with or without modification,
hlipka 0:8b387bed54c2 6 * are permitted provided that the following conditions are met:
hlipka 0:8b387bed54c2 7 *
hlipka 0:8b387bed54c2 8 * 1. Redistributions of source code must retain the above copyright notice,
hlipka 0:8b387bed54c2 9 * this list of conditions and the following disclaimer.
hlipka 0:8b387bed54c2 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
hlipka 0:8b387bed54c2 11 * this list of conditions and the following disclaimer in the documentation
hlipka 0:8b387bed54c2 12 * and/or other materials provided with the distribution.
hlipka 0:8b387bed54c2 13 * 3. The name of the author may not be used to endorse or promote products
hlipka 0:8b387bed54c2 14 * derived from this software without specific prior written permission.
hlipka 0:8b387bed54c2 15 *
hlipka 0:8b387bed54c2 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hlipka 0:8b387bed54c2 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hlipka 0:8b387bed54c2 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hlipka 0:8b387bed54c2 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hlipka 0:8b387bed54c2 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hlipka 0:8b387bed54c2 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hlipka 0:8b387bed54c2 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hlipka 0:8b387bed54c2 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hlipka 0:8b387bed54c2 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hlipka 0:8b387bed54c2 25 * OF SUCH DAMAGE.
hlipka 0:8b387bed54c2 26 *
hlipka 0:8b387bed54c2 27 * This file is part of the lwIP TCP/IP stack.
hlipka 0:8b387bed54c2 28 *
hlipka 0:8b387bed54c2 29 * Author: Adam Dunkels <adam@sics.se>
hlipka 0:8b387bed54c2 30 *
hlipka 0:8b387bed54c2 31 */
hlipka 0:8b387bed54c2 32 #ifndef __LWIP_IP_ADDR_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_IP_ADDR_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36 #include "lwip/def.h"
hlipka 0:8b387bed54c2 37
hlipka 0:8b387bed54c2 38 #ifdef __cplusplus
hlipka 0:8b387bed54c2 39 extern "C" {
hlipka 0:8b387bed54c2 40 #endif
hlipka 0:8b387bed54c2 41
hlipka 0:8b387bed54c2 42 /* This is the aligned version of ip_addr_t,
hlipka 0:8b387bed54c2 43 used as local variable, on the stack, etc. */
hlipka 0:8b387bed54c2 44 struct ip_addr {
hlipka 0:8b387bed54c2 45 u32_t addr;
hlipka 0:8b387bed54c2 46 };
hlipka 0:8b387bed54c2 47
hlipka 0:8b387bed54c2 48 /* This is the packed version of ip_addr_t,
hlipka 0:8b387bed54c2 49 used in network headers that are itself packed */
hlipka 0:8b387bed54c2 50 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 51 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 52 #endif
hlipka 0:8b387bed54c2 53 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 54 struct ip_addr_packed {
hlipka 0:8b387bed54c2 55 PACK_STRUCT_FIELD(u32_t addr);
hlipka 0:8b387bed54c2 56 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 57 PACK_STRUCT_END
hlipka 0:8b387bed54c2 58 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 59 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 60 #endif
hlipka 0:8b387bed54c2 61
hlipka 0:8b387bed54c2 62 /** ip_addr_t uses a struct for convenience only, so that the same defines can
hlipka 0:8b387bed54c2 63 * operate both on ip_addr_t as well as on ip_addr_p_t. */
hlipka 0:8b387bed54c2 64 typedef struct ip_addr ip_addr_t;
hlipka 0:8b387bed54c2 65 typedef struct ip_addr_packed ip_addr_p_t;
hlipka 0:8b387bed54c2 66
hlipka 0:8b387bed54c2 67 /*
hlipka 0:8b387bed54c2 68 * struct ipaddr2 is used in the definition of the ARP packet format in
hlipka 0:8b387bed54c2 69 * order to support compilers that don't have structure packing.
hlipka 0:8b387bed54c2 70 */
hlipka 0:8b387bed54c2 71 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 72 # include "arch/bpstruct.h"
hlipka 0:8b387bed54c2 73 #endif
hlipka 0:8b387bed54c2 74 PACK_STRUCT_BEGIN
hlipka 0:8b387bed54c2 75 struct ip_addr2 {
hlipka 0:8b387bed54c2 76 PACK_STRUCT_FIELD(u16_t addrw[2]);
hlipka 0:8b387bed54c2 77 } PACK_STRUCT_STRUCT;
hlipka 0:8b387bed54c2 78 PACK_STRUCT_END
hlipka 0:8b387bed54c2 79 #ifdef PACK_STRUCT_USE_INCLUDES
hlipka 0:8b387bed54c2 80 # include "arch/epstruct.h"
hlipka 0:8b387bed54c2 81 #endif
hlipka 0:8b387bed54c2 82
hlipka 0:8b387bed54c2 83 /* Forward declaration to not include netif.h */
hlipka 0:8b387bed54c2 84 struct netif;
hlipka 0:8b387bed54c2 85
hlipka 0:8b387bed54c2 86 extern const ip_addr_t ip_addr_any;
hlipka 0:8b387bed54c2 87 extern const ip_addr_t ip_addr_broadcast;
hlipka 0:8b387bed54c2 88
hlipka 0:8b387bed54c2 89 /** IP_ADDR_ can be used as a fixed IP address
hlipka 0:8b387bed54c2 90 * for the wildcard and the broadcast address
hlipka 0:8b387bed54c2 91 */
hlipka 0:8b387bed54c2 92 #define IP_ADDR_ANY ((ip_addr_t *)&ip_addr_any)
hlipka 0:8b387bed54c2 93 #define IP_ADDR_BROADCAST ((ip_addr_t *)&ip_addr_broadcast)
hlipka 0:8b387bed54c2 94
hlipka 0:8b387bed54c2 95 /** 255.255.255.255 */
hlipka 0:8b387bed54c2 96 #define IPADDR_NONE ((u32_t)0xffffffffUL)
hlipka 0:8b387bed54c2 97 /** 127.0.0.1 */
hlipka 0:8b387bed54c2 98 #define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
hlipka 0:8b387bed54c2 99 /** 0.0.0.0 */
hlipka 0:8b387bed54c2 100 #define IPADDR_ANY ((u32_t)0x00000000UL)
hlipka 0:8b387bed54c2 101 /** 255.255.255.255 */
hlipka 0:8b387bed54c2 102 #define IPADDR_BROADCAST ((u32_t)0xffffffffUL)
hlipka 0:8b387bed54c2 103
hlipka 0:8b387bed54c2 104 /* Definitions of the bits in an Internet address integer.
hlipka 0:8b387bed54c2 105
hlipka 0:8b387bed54c2 106 On subnets, host and network parts are found according to
hlipka 0:8b387bed54c2 107 the subnet mask, not these masks. */
hlipka 0:8b387bed54c2 108 #define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0)
hlipka 0:8b387bed54c2 109 #define IP_CLASSA_NET 0xff000000
hlipka 0:8b387bed54c2 110 #define IP_CLASSA_NSHIFT 24
hlipka 0:8b387bed54c2 111 #define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
hlipka 0:8b387bed54c2 112 #define IP_CLASSA_MAX 128
hlipka 0:8b387bed54c2 113
hlipka 0:8b387bed54c2 114 #define IP_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
hlipka 0:8b387bed54c2 115 #define IP_CLASSB_NET 0xffff0000
hlipka 0:8b387bed54c2 116 #define IP_CLASSB_NSHIFT 16
hlipka 0:8b387bed54c2 117 #define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET)
hlipka 0:8b387bed54c2 118 #define IP_CLASSB_MAX 65536
hlipka 0:8b387bed54c2 119
hlipka 0:8b387bed54c2 120 #define IP_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
hlipka 0:8b387bed54c2 121 #define IP_CLASSC_NET 0xffffff00
hlipka 0:8b387bed54c2 122 #define IP_CLASSC_NSHIFT 8
hlipka 0:8b387bed54c2 123 #define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET)
hlipka 0:8b387bed54c2 124
hlipka 0:8b387bed54c2 125 #define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
hlipka 0:8b387bed54c2 126 #define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */
hlipka 0:8b387bed54c2 127 #define IP_CLASSD_NSHIFT 28 /* net and host fields, but */
hlipka 0:8b387bed54c2 128 #define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */
hlipka 0:8b387bed54c2 129 #define IP_MULTICAST(a) IP_CLASSD(a)
hlipka 0:8b387bed54c2 130
hlipka 0:8b387bed54c2 131 #define IP_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
hlipka 0:8b387bed54c2 132 #define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
hlipka 0:8b387bed54c2 133
hlipka 0:8b387bed54c2 134 #define IP_LOOPBACKNET 127 /* official! */
hlipka 0:8b387bed54c2 135
hlipka 0:8b387bed54c2 136
hlipka 0:8b387bed54c2 137 #if BYTE_ORDER == BIG_ENDIAN
hlipka 0:8b387bed54c2 138 /** Set an IP address given by the four byte-parts */
hlipka 0:8b387bed54c2 139 #define IP4_ADDR(ipaddr, a,b,c,d) \
hlipka 0:8b387bed54c2 140 (ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \
hlipka 0:8b387bed54c2 141 ((u32_t)((b) & 0xff) << 16) | \
hlipka 0:8b387bed54c2 142 ((u32_t)((c) & 0xff) << 8) | \
hlipka 0:8b387bed54c2 143 (u32_t)((d) & 0xff)
hlipka 0:8b387bed54c2 144 #else
hlipka 0:8b387bed54c2 145 /** Set an IP address given by the four byte-parts.
hlipka 0:8b387bed54c2 146 Little-endian version that prevents the use of htonl. */
hlipka 0:8b387bed54c2 147 #define IP4_ADDR(ipaddr, a,b,c,d) \
hlipka 0:8b387bed54c2 148 (ipaddr)->addr = ((u32_t)((d) & 0xff) << 24) | \
hlipka 0:8b387bed54c2 149 ((u32_t)((c) & 0xff) << 16) | \
hlipka 0:8b387bed54c2 150 ((u32_t)((b) & 0xff) << 8) | \
hlipka 0:8b387bed54c2 151 (u32_t)((a) & 0xff)
hlipka 0:8b387bed54c2 152 #endif
hlipka 0:8b387bed54c2 153
hlipka 0:8b387bed54c2 154 /** MEMCPY-like copying of IP addresses where addresses are known to be
hlipka 0:8b387bed54c2 155 * 16-bit-aligned if the port is correctly configured (so a port could define
hlipka 0:8b387bed54c2 156 * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */
hlipka 0:8b387bed54c2 157 #ifndef IPADDR2_COPY
hlipka 0:8b387bed54c2 158 #define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip_addr_t))
hlipka 0:8b387bed54c2 159 #endif
hlipka 0:8b387bed54c2 160
hlipka 0:8b387bed54c2 161 /** Copy IP address - faster than ip_addr_set: no NULL check */
hlipka 0:8b387bed54c2 162 #define ip_addr_copy(dest, src) ((dest).addr = (src).addr)
hlipka 0:8b387bed54c2 163 /** Safely copy one IP address to another (src may be NULL) */
hlipka 0:8b387bed54c2 164 #define ip_addr_set(dest, src) ((dest)->addr = \
hlipka 0:8b387bed54c2 165 ((src) == NULL ? 0 : \
hlipka 0:8b387bed54c2 166 (src)->addr))
hlipka 0:8b387bed54c2 167 /** Set complete address to zero */
hlipka 0:8b387bed54c2 168 #define ip_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
hlipka 0:8b387bed54c2 169 /** Set address to IPADDR_ANY (no need for htonl()) */
hlipka 0:8b387bed54c2 170 #define ip_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
hlipka 0:8b387bed54c2 171 /** Set address to loopback address */
hlipka 0:8b387bed54c2 172 #define ip_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
hlipka 0:8b387bed54c2 173 /** Safely copy one IP address to another and change byte order
hlipka 0:8b387bed54c2 174 * from host- to network-order. */
hlipka 0:8b387bed54c2 175 #define ip_addr_set_hton(dest, src) ((dest)->addr = \
hlipka 0:8b387bed54c2 176 ((src) == NULL ? 0:\
hlipka 0:8b387bed54c2 177 htonl((src)->addr)))
hlipka 0:8b387bed54c2 178 /** IPv4 only: set the IP address given as an u32_t */
hlipka 0:8b387bed54c2 179 #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
hlipka 0:8b387bed54c2 180 /** IPv4 only: get the IP address as an u32_t */
hlipka 0:8b387bed54c2 181 #define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
hlipka 0:8b387bed54c2 182
hlipka 0:8b387bed54c2 183 /** Get the network address by combining host address with netmask */
hlipka 0:8b387bed54c2 184 #define ip_addr_get_network(target, host, netmask) ((target)->addr = ((host)->addr) & ((netmask)->addr))
hlipka 0:8b387bed54c2 185
hlipka 0:8b387bed54c2 186 /**
hlipka 0:8b387bed54c2 187 * Determine if two address are on the same network.
hlipka 0:8b387bed54c2 188 *
hlipka 0:8b387bed54c2 189 * @arg addr1 IP address 1
hlipka 0:8b387bed54c2 190 * @arg addr2 IP address 2
hlipka 0:8b387bed54c2 191 * @arg mask network identifier mask
hlipka 0:8b387bed54c2 192 * @return !0 if the network identifiers of both address match
hlipka 0:8b387bed54c2 193 */
hlipka 0:8b387bed54c2 194 #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
hlipka 0:8b387bed54c2 195 (mask)->addr) == \
hlipka 0:8b387bed54c2 196 ((addr2)->addr & \
hlipka 0:8b387bed54c2 197 (mask)->addr))
hlipka 0:8b387bed54c2 198 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
hlipka 0:8b387bed54c2 199
hlipka 0:8b387bed54c2 200 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
hlipka 0:8b387bed54c2 201
hlipka 0:8b387bed54c2 202 #define ip_addr_isbroadcast(ipaddr, netif) ip4_addr_isbroadcast((ipaddr)->addr, (netif))
hlipka 0:8b387bed54c2 203 u8_t ip4_addr_isbroadcast(u32_t addr, const struct netif *netif);
hlipka 0:8b387bed54c2 204
hlipka 0:8b387bed54c2 205 #define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
hlipka 0:8b387bed54c2 206 u8_t ip4_addr_netmask_valid(u32_t netmask);
hlipka 0:8b387bed54c2 207
hlipka 0:8b387bed54c2 208 #define ip_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
hlipka 0:8b387bed54c2 209
hlipka 0:8b387bed54c2 210 #define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
hlipka 0:8b387bed54c2 211
hlipka 0:8b387bed54c2 212 #define ip_addr_debug_print(debug, ipaddr) \
hlipka 0:8b387bed54c2 213 LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
hlipka 0:8b387bed54c2 214 ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
hlipka 0:8b387bed54c2 215 ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
hlipka 0:8b387bed54c2 216 ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \
hlipka 0:8b387bed54c2 217 ipaddr != NULL ? ip4_addr4_16(ipaddr) : 0))
hlipka 0:8b387bed54c2 218
hlipka 0:8b387bed54c2 219 /* Get one byte from the 4-byte address */
hlipka 0:8b387bed54c2 220 #define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0])
hlipka 0:8b387bed54c2 221 #define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1])
hlipka 0:8b387bed54c2 222 #define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2])
hlipka 0:8b387bed54c2 223 #define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3])
hlipka 0:8b387bed54c2 224 /* These are cast to u16_t, with the intent that they are often arguments
hlipka 0:8b387bed54c2 225 * to printf using the U16_F format from cc.h. */
hlipka 0:8b387bed54c2 226 #define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
hlipka 0:8b387bed54c2 227 #define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
hlipka 0:8b387bed54c2 228 #define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
hlipka 0:8b387bed54c2 229 #define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
hlipka 0:8b387bed54c2 230
hlipka 0:8b387bed54c2 231 /** For backwards compatibility */
hlipka 0:8b387bed54c2 232 #define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr)
hlipka 0:8b387bed54c2 233
hlipka 0:8b387bed54c2 234 u32_t ipaddr_addr(const char *cp);
hlipka 0:8b387bed54c2 235 int ipaddr_aton(const char *cp, ip_addr_t *addr);
hlipka 0:8b387bed54c2 236 /** returns ptr to static buffer; not reentrant! */
hlipka 0:8b387bed54c2 237 char *ipaddr_ntoa(const ip_addr_t *addr);
hlipka 0:8b387bed54c2 238 char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen);
hlipka 0:8b387bed54c2 239
hlipka 0:8b387bed54c2 240 #ifdef __cplusplus
hlipka 0:8b387bed54c2 241 }
hlipka 0:8b387bed54c2 242 #endif
hlipka 0:8b387bed54c2 243
hlipka 0:8b387bed54c2 244 #endif /* __LWIP_IP_ADDR_H__ */