I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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