lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] raw api recv callback - procedure to (temporarily)refus


From: Atte Kojo
Subject: Re: [lwip-users] raw api recv callback - procedure to (temporarily)refuse data?
Date: Tue, 10 May 2005 08:52:06 +0300
User-agent: KMail/1.8

On Tuesday 10 May 2005 06:29, Karl Kobel wrote:
> The follow2ing is the code that executes when a complete packet is
> received:
>
>       p = pbuf_alloc(PBUF_RAW, recved, PBUF_POOL);
>       if (p != NULL)
>       {
>               memcpy(p->payload, SlipBuff, recved);
>               p->len = recved;
>               LWIP_DEBUGF(SLIP_DEBUG, ("slipif: Got packet\n"));
>               recved = 0;
>               return p;
>       }
>
> SlipBuff has the data,
> Recved has the length.
>
> Small packets are handled correctly. However larger packets (around 300
> bytes) the TCP checksum fails. The following is the portion of tcp_input
> that fails.

This is because the pbufs are alloc'ed as a linked list of data chunks. When 
you receive more data than is the predefined size of the chunks in the pbuf 
pool, you get trouble. You need to copy the data out of all the pbufs in the 
pbuf chain, not just the first one. Something like this:

offset = 0;
buf = alloc(p->tot_len);

for (q = p; q != NULL; q = q->next) {
  memcpy(buf + offset, q->payload, q->len);
  offset += q->len;
}

tot_len tells the total size of data in the pbuf chain starting from current 
pbuf. len tells the size of data in current pbuf.

Hope this helps

                - Atte




reply via email to

[Prev in Thread] Current Thread [Next in Thread]