pbuf->payload question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

pbuf->payload question

Toshiyasu Morita
I have lwIP mostly up and running on my target.
I can see the following:

o gratuitous ARP
o ARP request
o ARP reply
o UDP test packet sent

However, the UDP test packet has a garbage payload.

My test code looks something like this:


uint8_t test_data[10] = {0, 1, 2, 4, 5, 6, 7, 8, 9};
..
p = pbuf_alloc(PBUF_RAW, 10, PBUF_POOL);
p->payload = test_data;

udp_send(pcb, p);

I have traced through lwIP, and it seems to do subtraction on the payload pointer to add the UDP header:

static u8_t
pbuf_add_header_impl(struct pbuf *p, size_t header_size_increment, u8_t force)
{
...
    /* hide a header in the payload? */
    if (force) {
      payload = (u8_t *)p->payload - header_size_increment;
...

So it seems like the p->payload needs to be a special buffer that has space reserved for a packet header. This doesn't seem to be documented in the header file for pbuf.

What is the proper procedure to allocate a buffer for the payload which is compatible with pbuf_add_header_impl()?

Toshi








_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: pbuf->payload question

Toshiyasu Morita
Ok, just realized I need to copy data to the pbuf->payload.
However, when I do this, the packet comes out with the entire payload as zeroes.
So the problem is elsewhere, apparently.

Toshi

On Thu, Dec 5, 2019 at 1:23 PM Toshiyasu Morita <[hidden email]> wrote:
I have lwIP mostly up and running on my target.
I can see the following:

o gratuitous ARP
o ARP request
o ARP reply
o UDP test packet sent

However, the UDP test packet has a garbage payload.

My test code looks something like this:


uint8_t test_data[10] = {0, 1, 2, 4, 5, 6, 7, 8, 9};
..
p = pbuf_alloc(PBUF_RAW, 10, PBUF_POOL);
p->payload = test_data;

udp_send(pcb, p);

I have traced through lwIP, and it seems to do subtraction on the payload pointer to add the UDP header:

static u8_t
pbuf_add_header_impl(struct pbuf *p, size_t header_size_increment, u8_t force)
{
...
    /* hide a header in the payload? */
    if (force) {
      payload = (u8_t *)p->payload - header_size_increment;
...

So it seems like the p->payload needs to be a special buffer that has space reserved for a packet header. This doesn't seem to be documented in the header file for pbuf.

What is the proper procedure to allocate a buffer for the payload which is compatible with pbuf_add_header_impl()?

Toshi








_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users