First step: AutoIP compiled in and working

Dependencies:   mbed

Committer:
darran
Date:
Fri Jun 18 15:54:21 2010 +0000
Revision:
1:4218cacaf696
Parent:
0:55a05330f8cc

        

Who changed what in which revision?

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