Bonjour/Zerconf library

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:54:31 2010 +0000
Revision:
5:8e53abda9900
Parent:
0:355018f44c9f

        

Who changed what in which revision?

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