A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Committer:
root@mbed.org
Date:
Tue May 08 15:32:10 2012 +0100
Revision:
0:5e1631496985
initial commit

Who changed what in which revision?

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