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 * @file
andrewbonney 0:ec559500a63f 3 * Implementation of raw protocol PCBs for low-level handling of
andrewbonney 0:ec559500a63f 4 * different types of protocols besides (or overriding) those
andrewbonney 0:ec559500a63f 5 * already available in lwIP.
andrewbonney 0:ec559500a63f 6 *
andrewbonney 0:ec559500a63f 7 */
andrewbonney 0:ec559500a63f 8
andrewbonney 0:ec559500a63f 9 /*
andrewbonney 0:ec559500a63f 10 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
andrewbonney 0:ec559500a63f 11 * All rights reserved.
andrewbonney 0:ec559500a63f 12 *
andrewbonney 0:ec559500a63f 13 * Redistribution and use in source and binary forms, with or without modification,
andrewbonney 0:ec559500a63f 14 * are permitted provided that the following conditions are met:
andrewbonney 0:ec559500a63f 15 *
andrewbonney 0:ec559500a63f 16 * 1. Redistributions of source code must retain the above copyright notice,
andrewbonney 0:ec559500a63f 17 * this list of conditions and the following disclaimer.
andrewbonney 0:ec559500a63f 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
andrewbonney 0:ec559500a63f 19 * this list of conditions and the following disclaimer in the documentation
andrewbonney 0:ec559500a63f 20 * and/or other materials provided with the distribution.
andrewbonney 0:ec559500a63f 21 * 3. The name of the author may not be used to endorse or promote products
andrewbonney 0:ec559500a63f 22 * derived from this software without specific prior written permission.
andrewbonney 0:ec559500a63f 23 *
andrewbonney 0:ec559500a63f 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
andrewbonney 0:ec559500a63f 25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
andrewbonney 0:ec559500a63f 26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
andrewbonney 0:ec559500a63f 27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
andrewbonney 0:ec559500a63f 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
andrewbonney 0:ec559500a63f 29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
andrewbonney 0:ec559500a63f 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
andrewbonney 0:ec559500a63f 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
andrewbonney 0:ec559500a63f 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
andrewbonney 0:ec559500a63f 33 * OF SUCH DAMAGE.
andrewbonney 0:ec559500a63f 34 *
andrewbonney 0:ec559500a63f 35 * This file is part of the lwIP TCP/IP stack.
andrewbonney 0:ec559500a63f 36 *
andrewbonney 0:ec559500a63f 37 * Author: Adam Dunkels <adam@sics.se>
andrewbonney 0:ec559500a63f 38 *
andrewbonney 0:ec559500a63f 39 */
andrewbonney 0:ec559500a63f 40
andrewbonney 0:ec559500a63f 41 #include "lwip/opt.h"
andrewbonney 0:ec559500a63f 42
andrewbonney 0:ec559500a63f 43 #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
andrewbonney 0:ec559500a63f 44
andrewbonney 0:ec559500a63f 45 #include "lwip/def.h"
andrewbonney 0:ec559500a63f 46 #include "lwip/memp.h"
andrewbonney 0:ec559500a63f 47 #include "lwip/ip_addr.h"
andrewbonney 0:ec559500a63f 48 #include "lwip/netif.h"
andrewbonney 0:ec559500a63f 49 #include "lwip/raw.h"
andrewbonney 0:ec559500a63f 50 #include "lwip/stats.h"
andrewbonney 0:ec559500a63f 51 #include "arch/perf.h"
andrewbonney 0:ec559500a63f 52
andrewbonney 0:ec559500a63f 53 #include <string.h>
andrewbonney 0:ec559500a63f 54
andrewbonney 0:ec559500a63f 55 /** The list of RAW PCBs */
andrewbonney 0:ec559500a63f 56 static struct raw_pcb *raw_pcbs;
andrewbonney 0:ec559500a63f 57
andrewbonney 0:ec559500a63f 58 /**
andrewbonney 0:ec559500a63f 59 * Determine if in incoming IP packet is covered by a RAW PCB
andrewbonney 0:ec559500a63f 60 * and if so, pass it to a user-provided receive callback function.
andrewbonney 0:ec559500a63f 61 *
andrewbonney 0:ec559500a63f 62 * Given an incoming IP datagram (as a chain of pbufs) this function
andrewbonney 0:ec559500a63f 63 * finds a corresponding RAW PCB and calls the corresponding receive
andrewbonney 0:ec559500a63f 64 * callback function.
andrewbonney 0:ec559500a63f 65 *
andrewbonney 0:ec559500a63f 66 * @param p pbuf to be demultiplexed to a RAW PCB.
andrewbonney 0:ec559500a63f 67 * @param inp network interface on which the datagram was received.
andrewbonney 0:ec559500a63f 68 * @return - 1 if the packet has been eaten by a RAW PCB receive
andrewbonney 0:ec559500a63f 69 * callback function. The caller MAY NOT not reference the
andrewbonney 0:ec559500a63f 70 * packet any longer, and MAY NOT call pbuf_free().
andrewbonney 0:ec559500a63f 71 * @return - 0 if packet is not eaten (pbuf is still referenced by the
andrewbonney 0:ec559500a63f 72 * caller).
andrewbonney 0:ec559500a63f 73 *
andrewbonney 0:ec559500a63f 74 */
andrewbonney 0:ec559500a63f 75 u8_t
andrewbonney 0:ec559500a63f 76 raw_input(struct pbuf *p, struct netif *inp)
andrewbonney 0:ec559500a63f 77 {
andrewbonney 0:ec559500a63f 78 struct raw_pcb *pcb, *prev;
andrewbonney 0:ec559500a63f 79 struct ip_hdr *iphdr;
andrewbonney 0:ec559500a63f 80 s16_t proto;
andrewbonney 0:ec559500a63f 81 u8_t eaten = 0;
andrewbonney 0:ec559500a63f 82
andrewbonney 0:ec559500a63f 83 LWIP_UNUSED_ARG(inp);
andrewbonney 0:ec559500a63f 84
andrewbonney 0:ec559500a63f 85 iphdr = (struct ip_hdr *)p->payload;
andrewbonney 0:ec559500a63f 86 proto = IPH_PROTO(iphdr);
andrewbonney 0:ec559500a63f 87
andrewbonney 0:ec559500a63f 88 prev = NULL;
andrewbonney 0:ec559500a63f 89 pcb = raw_pcbs;
andrewbonney 0:ec559500a63f 90 /* loop through all raw pcbs until the packet is eaten by one */
andrewbonney 0:ec559500a63f 91 /* this allows multiple pcbs to match against the packet by design */
andrewbonney 0:ec559500a63f 92 while ((eaten == 0) && (pcb != NULL)) {
andrewbonney 0:ec559500a63f 93 if ((pcb->protocol == proto) &&
andrewbonney 0:ec559500a63f 94 (ip_addr_isany(&pcb->local_ip) ||
andrewbonney 0:ec559500a63f 95 ip_addr_cmp(&(pcb->local_ip), &current_iphdr_dest))) {
andrewbonney 0:ec559500a63f 96 #if IP_SOF_BROADCAST_RECV
andrewbonney 0:ec559500a63f 97 /* broadcast filter? */
andrewbonney 0:ec559500a63f 98 if ((pcb->so_options & SOF_BROADCAST) || !ip_addr_isbroadcast(&current_iphdr_dest, inp))
andrewbonney 0:ec559500a63f 99 #endif /* IP_SOF_BROADCAST_RECV */
andrewbonney 0:ec559500a63f 100 {
andrewbonney 0:ec559500a63f 101 /* receive callback function available? */
andrewbonney 0:ec559500a63f 102 if (pcb->recv != NULL) {
andrewbonney 0:ec559500a63f 103 /* the receive callback function did not eat the packet? */
andrewbonney 0:ec559500a63f 104 if (pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr()) != 0) {
andrewbonney 0:ec559500a63f 105 /* receive function ate the packet */
andrewbonney 0:ec559500a63f 106 p = NULL;
andrewbonney 0:ec559500a63f 107 eaten = 1;
andrewbonney 0:ec559500a63f 108 if (prev != NULL) {
andrewbonney 0:ec559500a63f 109 /* move the pcb to the front of raw_pcbs so that is
andrewbonney 0:ec559500a63f 110 found faster next time */
andrewbonney 0:ec559500a63f 111 prev->next = pcb->next;
andrewbonney 0:ec559500a63f 112 pcb->next = raw_pcbs;
andrewbonney 0:ec559500a63f 113 raw_pcbs = pcb;
andrewbonney 0:ec559500a63f 114 }
andrewbonney 0:ec559500a63f 115 }
andrewbonney 0:ec559500a63f 116 }
andrewbonney 0:ec559500a63f 117 /* no receive callback function was set for this raw PCB */
andrewbonney 0:ec559500a63f 118 }
andrewbonney 0:ec559500a63f 119 /* drop the packet */
andrewbonney 0:ec559500a63f 120 }
andrewbonney 0:ec559500a63f 121 prev = pcb;
andrewbonney 0:ec559500a63f 122 pcb = pcb->next;
andrewbonney 0:ec559500a63f 123 }
andrewbonney 0:ec559500a63f 124 return eaten;
andrewbonney 0:ec559500a63f 125 }
andrewbonney 0:ec559500a63f 126
andrewbonney 0:ec559500a63f 127 /**
andrewbonney 0:ec559500a63f 128 * Bind a RAW PCB.
andrewbonney 0:ec559500a63f 129 *
andrewbonney 0:ec559500a63f 130 * @param pcb RAW PCB to be bound with a local address ipaddr.
andrewbonney 0:ec559500a63f 131 * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
andrewbonney 0:ec559500a63f 132 * bind to all local interfaces.
andrewbonney 0:ec559500a63f 133 *
andrewbonney 0:ec559500a63f 134 * @return lwIP error code.
andrewbonney 0:ec559500a63f 135 * - ERR_OK. Successful. No error occured.
andrewbonney 0:ec559500a63f 136 * - ERR_USE. The specified IP address is already bound to by
andrewbonney 0:ec559500a63f 137 * another RAW PCB.
andrewbonney 0:ec559500a63f 138 *
andrewbonney 0:ec559500a63f 139 * @see raw_disconnect()
andrewbonney 0:ec559500a63f 140 */
andrewbonney 0:ec559500a63f 141 err_t
andrewbonney 0:ec559500a63f 142 raw_bind(struct raw_pcb *pcb, ip_addr_t *ipaddr)
andrewbonney 0:ec559500a63f 143 {
andrewbonney 0:ec559500a63f 144 ip_addr_set(&pcb->local_ip, ipaddr);
andrewbonney 0:ec559500a63f 145 return ERR_OK;
andrewbonney 0:ec559500a63f 146 }
andrewbonney 0:ec559500a63f 147
andrewbonney 0:ec559500a63f 148 /**
andrewbonney 0:ec559500a63f 149 * Connect an RAW PCB. This function is required by upper layers
andrewbonney 0:ec559500a63f 150 * of lwip. Using the raw api you could use raw_sendto() instead
andrewbonney 0:ec559500a63f 151 *
andrewbonney 0:ec559500a63f 152 * This will associate the RAW PCB with the remote address.
andrewbonney 0:ec559500a63f 153 *
andrewbonney 0:ec559500a63f 154 * @param pcb RAW PCB to be connected with remote address ipaddr and port.
andrewbonney 0:ec559500a63f 155 * @param ipaddr remote IP address to connect with.
andrewbonney 0:ec559500a63f 156 *
andrewbonney 0:ec559500a63f 157 * @return lwIP error code
andrewbonney 0:ec559500a63f 158 *
andrewbonney 0:ec559500a63f 159 * @see raw_disconnect() and raw_sendto()
andrewbonney 0:ec559500a63f 160 */
andrewbonney 0:ec559500a63f 161 err_t
andrewbonney 0:ec559500a63f 162 raw_connect(struct raw_pcb *pcb, ip_addr_t *ipaddr)
andrewbonney 0:ec559500a63f 163 {
andrewbonney 0:ec559500a63f 164 ip_addr_set(&pcb->remote_ip, ipaddr);
andrewbonney 0:ec559500a63f 165 return ERR_OK;
andrewbonney 0:ec559500a63f 166 }
andrewbonney 0:ec559500a63f 167
andrewbonney 0:ec559500a63f 168
andrewbonney 0:ec559500a63f 169 /**
andrewbonney 0:ec559500a63f 170 * Set the callback function for received packets that match the
andrewbonney 0:ec559500a63f 171 * raw PCB's protocol and binding.
andrewbonney 0:ec559500a63f 172 *
andrewbonney 0:ec559500a63f 173 * The callback function MUST either
andrewbonney 0:ec559500a63f 174 * - eat the packet by calling pbuf_free() and returning non-zero. The
andrewbonney 0:ec559500a63f 175 * packet will not be passed to other raw PCBs or other protocol layers.
andrewbonney 0:ec559500a63f 176 * - not free the packet, and return zero. The packet will be matched
andrewbonney 0:ec559500a63f 177 * against further PCBs and/or forwarded to another protocol layers.
andrewbonney 0:ec559500a63f 178 *
andrewbonney 0:ec559500a63f 179 * @return non-zero if the packet was free()d, zero if the packet remains
andrewbonney 0:ec559500a63f 180 * available for others.
andrewbonney 0:ec559500a63f 181 */
andrewbonney 0:ec559500a63f 182 void
andrewbonney 0:ec559500a63f 183 raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)
andrewbonney 0:ec559500a63f 184 {
andrewbonney 0:ec559500a63f 185 /* remember recv() callback and user data */
andrewbonney 0:ec559500a63f 186 pcb->recv = recv;
andrewbonney 0:ec559500a63f 187 pcb->recv_arg = recv_arg;
andrewbonney 0:ec559500a63f 188 }
andrewbonney 0:ec559500a63f 189
andrewbonney 0:ec559500a63f 190 /**
andrewbonney 0:ec559500a63f 191 * Send the raw IP packet to the given address. Note that actually you cannot
andrewbonney 0:ec559500a63f 192 * modify the IP headers (this is inconsistent with the receive callback where
andrewbonney 0:ec559500a63f 193 * you actually get the IP headers), you can only specify the IP payload here.
andrewbonney 0:ec559500a63f 194 * It requires some more changes in lwIP. (there will be a raw_send() function
andrewbonney 0:ec559500a63f 195 * then.)
andrewbonney 0:ec559500a63f 196 *
andrewbonney 0:ec559500a63f 197 * @param pcb the raw pcb which to send
andrewbonney 0:ec559500a63f 198 * @param p the IP payload to send
andrewbonney 0:ec559500a63f 199 * @param ipaddr the destination address of the IP packet
andrewbonney 0:ec559500a63f 200 *
andrewbonney 0:ec559500a63f 201 */
andrewbonney 0:ec559500a63f 202 err_t
andrewbonney 0:ec559500a63f 203 raw_sendto(struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr)
andrewbonney 0:ec559500a63f 204 {
andrewbonney 0:ec559500a63f 205 err_t err;
andrewbonney 0:ec559500a63f 206 struct netif *netif;
andrewbonney 0:ec559500a63f 207 ip_addr_t *src_ip;
andrewbonney 0:ec559500a63f 208 struct pbuf *q; /* q will be sent down the stack */
andrewbonney 0:ec559500a63f 209
andrewbonney 0:ec559500a63f 210 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_sendto\n"));
andrewbonney 0:ec559500a63f 211
andrewbonney 0:ec559500a63f 212 /* not enough space to add an IP header to first pbuf in given p chain? */
andrewbonney 0:ec559500a63f 213 if (pbuf_header(p, IP_HLEN)) {
andrewbonney 0:ec559500a63f 214 /* allocate header in new pbuf */
andrewbonney 0:ec559500a63f 215 q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
andrewbonney 0:ec559500a63f 216 /* new header pbuf could not be allocated? */
andrewbonney 0:ec559500a63f 217 if (q == NULL) {
andrewbonney 0:ec559500a63f 218 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("raw_sendto: could not allocate header\n"));
andrewbonney 0:ec559500a63f 219 return ERR_MEM;
andrewbonney 0:ec559500a63f 220 }
andrewbonney 0:ec559500a63f 221 /* chain header q in front of given pbuf p */
andrewbonney 0:ec559500a63f 222 pbuf_chain(q, p);
andrewbonney 0:ec559500a63f 223 /* { first pbuf q points to header pbuf } */
andrewbonney 0:ec559500a63f 224 LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
andrewbonney 0:ec559500a63f 225 } else {
andrewbonney 0:ec559500a63f 226 /* first pbuf q equals given pbuf */
andrewbonney 0:ec559500a63f 227 q = p;
andrewbonney 0:ec559500a63f 228 if(pbuf_header(q, -IP_HLEN)) {
andrewbonney 0:ec559500a63f 229 LWIP_ASSERT("Can't restore header we just removed!", 0);
andrewbonney 0:ec559500a63f 230 return ERR_MEM;
andrewbonney 0:ec559500a63f 231 }
andrewbonney 0:ec559500a63f 232 }
andrewbonney 0:ec559500a63f 233
andrewbonney 0:ec559500a63f 234 if ((netif = ip_route(ipaddr)) == NULL) {
andrewbonney 0:ec559500a63f 235 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
andrewbonney 0:ec559500a63f 236 ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr)));
andrewbonney 0:ec559500a63f 237 /* free any temporary header pbuf allocated by pbuf_header() */
andrewbonney 0:ec559500a63f 238 if (q != p) {
andrewbonney 0:ec559500a63f 239 pbuf_free(q);
andrewbonney 0:ec559500a63f 240 }
andrewbonney 0:ec559500a63f 241 return ERR_RTE;
andrewbonney 0:ec559500a63f 242 }
andrewbonney 0:ec559500a63f 243
andrewbonney 0:ec559500a63f 244 #if IP_SOF_BROADCAST
andrewbonney 0:ec559500a63f 245 /* broadcast filter? */
andrewbonney 0:ec559500a63f 246 if (((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(ipaddr, netif)) {
andrewbonney 0:ec559500a63f 247 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
andrewbonney 0:ec559500a63f 248 /* free any temporary header pbuf allocated by pbuf_header() */
andrewbonney 0:ec559500a63f 249 if (q != p) {
andrewbonney 0:ec559500a63f 250 pbuf_free(q);
andrewbonney 0:ec559500a63f 251 }
andrewbonney 0:ec559500a63f 252 return ERR_VAL;
andrewbonney 0:ec559500a63f 253 }
andrewbonney 0:ec559500a63f 254 #endif /* IP_SOF_BROADCAST */
andrewbonney 0:ec559500a63f 255
andrewbonney 0:ec559500a63f 256 if (ip_addr_isany(&pcb->local_ip)) {
andrewbonney 0:ec559500a63f 257 /* use outgoing network interface IP address as source address */
andrewbonney 0:ec559500a63f 258 src_ip = &(netif->ip_addr);
andrewbonney 0:ec559500a63f 259 } else {
andrewbonney 0:ec559500a63f 260 /* use RAW PCB local IP address as source address */
andrewbonney 0:ec559500a63f 261 src_ip = &(pcb->local_ip);
andrewbonney 0:ec559500a63f 262 }
andrewbonney 0:ec559500a63f 263
andrewbonney 0:ec559500a63f 264 #if LWIP_NETIF_HWADDRHINT
andrewbonney 0:ec559500a63f 265 netif->addr_hint = &(pcb->addr_hint);
andrewbonney 0:ec559500a63f 266 #endif /* LWIP_NETIF_HWADDRHINT*/
andrewbonney 0:ec559500a63f 267 err = ip_output_if (q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif);
andrewbonney 0:ec559500a63f 268 #if LWIP_NETIF_HWADDRHINT
andrewbonney 0:ec559500a63f 269 netif->addr_hint = NULL;
andrewbonney 0:ec559500a63f 270 #endif /* LWIP_NETIF_HWADDRHINT*/
andrewbonney 0:ec559500a63f 271
andrewbonney 0:ec559500a63f 272 /* did we chain a header earlier? */
andrewbonney 0:ec559500a63f 273 if (q != p) {
andrewbonney 0:ec559500a63f 274 /* free the header */
andrewbonney 0:ec559500a63f 275 pbuf_free(q);
andrewbonney 0:ec559500a63f 276 }
andrewbonney 0:ec559500a63f 277 return err;
andrewbonney 0:ec559500a63f 278 }
andrewbonney 0:ec559500a63f 279
andrewbonney 0:ec559500a63f 280 /**
andrewbonney 0:ec559500a63f 281 * Send the raw IP packet to the address given by raw_connect()
andrewbonney 0:ec559500a63f 282 *
andrewbonney 0:ec559500a63f 283 * @param pcb the raw pcb which to send
andrewbonney 0:ec559500a63f 284 * @param p the IP payload to send
andrewbonney 0:ec559500a63f 285 *
andrewbonney 0:ec559500a63f 286 */
andrewbonney 0:ec559500a63f 287 err_t
andrewbonney 0:ec559500a63f 288 raw_send(struct raw_pcb *pcb, struct pbuf *p)
andrewbonney 0:ec559500a63f 289 {
andrewbonney 0:ec559500a63f 290 return raw_sendto(pcb, p, &pcb->remote_ip);
andrewbonney 0:ec559500a63f 291 }
andrewbonney 0:ec559500a63f 292
andrewbonney 0:ec559500a63f 293 /**
andrewbonney 0:ec559500a63f 294 * Remove an RAW PCB.
andrewbonney 0:ec559500a63f 295 *
andrewbonney 0:ec559500a63f 296 * @param pcb RAW PCB to be removed. The PCB is removed from the list of
andrewbonney 0:ec559500a63f 297 * RAW PCB's and the data structure is freed from memory.
andrewbonney 0:ec559500a63f 298 *
andrewbonney 0:ec559500a63f 299 * @see raw_new()
andrewbonney 0:ec559500a63f 300 */
andrewbonney 0:ec559500a63f 301 void
andrewbonney 0:ec559500a63f 302 raw_remove(struct raw_pcb *pcb)
andrewbonney 0:ec559500a63f 303 {
andrewbonney 0:ec559500a63f 304 struct raw_pcb *pcb2;
andrewbonney 0:ec559500a63f 305 /* pcb to be removed is first in list? */
andrewbonney 0:ec559500a63f 306 if (raw_pcbs == pcb) {
andrewbonney 0:ec559500a63f 307 /* make list start at 2nd pcb */
andrewbonney 0:ec559500a63f 308 raw_pcbs = raw_pcbs->next;
andrewbonney 0:ec559500a63f 309 /* pcb not 1st in list */
andrewbonney 0:ec559500a63f 310 } else {
andrewbonney 0:ec559500a63f 311 for(pcb2 = raw_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
andrewbonney 0:ec559500a63f 312 /* find pcb in raw_pcbs list */
andrewbonney 0:ec559500a63f 313 if (pcb2->next != NULL && pcb2->next == pcb) {
andrewbonney 0:ec559500a63f 314 /* remove pcb from list */
andrewbonney 0:ec559500a63f 315 pcb2->next = pcb->next;
andrewbonney 0:ec559500a63f 316 }
andrewbonney 0:ec559500a63f 317 }
andrewbonney 0:ec559500a63f 318 }
andrewbonney 0:ec559500a63f 319 memp_free(MEMP_RAW_PCB, pcb);
andrewbonney 0:ec559500a63f 320 }
andrewbonney 0:ec559500a63f 321
andrewbonney 0:ec559500a63f 322 /**
andrewbonney 0:ec559500a63f 323 * Create a RAW PCB.
andrewbonney 0:ec559500a63f 324 *
andrewbonney 0:ec559500a63f 325 * @return The RAW PCB which was created. NULL if the PCB data structure
andrewbonney 0:ec559500a63f 326 * could not be allocated.
andrewbonney 0:ec559500a63f 327 *
andrewbonney 0:ec559500a63f 328 * @param proto the protocol number of the IPs payload (e.g. IP_PROTO_ICMP)
andrewbonney 0:ec559500a63f 329 *
andrewbonney 0:ec559500a63f 330 * @see raw_remove()
andrewbonney 0:ec559500a63f 331 */
andrewbonney 0:ec559500a63f 332 struct raw_pcb *
andrewbonney 0:ec559500a63f 333 raw_new(u8_t proto)
andrewbonney 0:ec559500a63f 334 {
andrewbonney 0:ec559500a63f 335 struct raw_pcb *pcb;
andrewbonney 0:ec559500a63f 336
andrewbonney 0:ec559500a63f 337 LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_new\n"));
andrewbonney 0:ec559500a63f 338
andrewbonney 0:ec559500a63f 339 pcb = (struct raw_pcb *)memp_malloc(MEMP_RAW_PCB);
andrewbonney 0:ec559500a63f 340 /* could allocate RAW PCB? */
andrewbonney 0:ec559500a63f 341 if (pcb != NULL) {
andrewbonney 0:ec559500a63f 342 /* initialize PCB to all zeroes */
andrewbonney 0:ec559500a63f 343 memset(pcb, 0, sizeof(struct raw_pcb));
andrewbonney 0:ec559500a63f 344 pcb->protocol = proto;
andrewbonney 0:ec559500a63f 345 pcb->ttl = RAW_TTL;
andrewbonney 0:ec559500a63f 346 pcb->next = raw_pcbs;
andrewbonney 0:ec559500a63f 347 raw_pcbs = pcb;
andrewbonney 0:ec559500a63f 348 }
andrewbonney 0:ec559500a63f 349 return pcb;
andrewbonney 0:ec559500a63f 350 }
andrewbonney 0:ec559500a63f 351
andrewbonney 0:ec559500a63f 352 #endif /* LWIP_RAW */