NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

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