Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

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