Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

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