TwitterExample with newer library (2012Aug)

Dependencies:   EthernetNetIf HTTPClient mbed

Committer:
nxpfan
Date:
Wed Aug 29 03:50:19 2012 +0000
Revision:
0:075157567b0c
simple twitter example with newer library

Who changed what in which revision?

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