Net stack with AutoIP enabled

Dependencies:   mbed

Committer:
darran
Date:
Fri Jul 02 17:21:58 2010 +0000
Revision:
0:ac21159e27f4

        

Who changed what in which revision?

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