[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [lwip-users] raw api recv callback - procedure to(temporarily)refuse
From: |
Jan Ulvesten |
Subject: |
RE: [lwip-users] raw api recv callback - procedure to(temporarily)refuse data? |
Date: |
Tue, 10 May 2005 12:16:27 +0200 |
When you allocated a pbuf using PBUF_POOL, you are actually allocating a
chain og buffers linked together. The length of each is p->len(and then
p->next->len and so on). The total length is p->tot_len
memcpy(p->payload, SlipBuff, recved);
The above line will fail if recved > p->len. You might do something like
this:
struct pbuf *make_pbuf (BYTE *packet, int packet_len)
{
struct pbuf *p, *q;
int left = packet_len;
p = pbuf_alloc(PBUF_TRANSPORT, left, PBUF_POOL);
if (!p) return NULL;
q = p;
while (left > 0)
{
int chunk_size = min (left, q->len);
memcpy (q->payload, packet, chunk_size);
packet += chunk_size;
left -= chunk_size;
q = q->next;
}
return p;
}
Jan Ulvesten
Senior Software Engineer
SICOM AS
-----Original Message-----
From: Karl Kobel [mailto:address@hidden
Sent: 10. mai 2005 05:29
To: 'Mailing list for lwIP users'
Subject: RE: [lwip-users] raw api recv callback - procedure
to(temporarily)refuse data?
All,
I'm stuck. I'm nearly done with a single threaded version of slip. I
will add it to contrib when I complete it.
The problem stems most likely from my lack of understanding of pbufs.
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.
/* Verify TCP checksum. */
if (inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src),
(struct ip_addr *)&(iphdr->dest),
IP_PROTO_TCP, p->tot_len) != 0) {
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packet discarded due to
failing checksum 0x%04x\n",
inet_chksum_pseudo(p, (struct ip_addr *)&(iphdr->src), (struct
ip_addr *)&(iphdr->dest),
IP_PROTO_TCP, p->tot_len)));
The pbuf that fails has the next pointer pointing to another pbuf (four
total in the one I trapped), but the payload and len are correct for the
entire packet in the first pbuf. Also if I jump past the code after the
first pbuf checksum is totaled, the packet checksum is correct and the
packet is received correctly.
This has to be a result of me doing something wrong. Do I need to do
something different when I allocate the pbuf in the slip driver? I tried
PBUF_LINK as the first argument with the same results. Do I have to set
the next pointer to NULL?
Thanks,
Karl
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users
- RE: [lwip-users] raw api recv callback - procedure to(temporarily)refuse data?,
Jan Ulvesten <=