cancel
Showing results for 
Search instead for 
Did you mean: 

LwIP example sending UDP packets 50 bytes larger than expected

szbrozek9
Associate II
Posted on April 17, 2013 at 00:21

I'm using the STM32F4x7 + LwIP example code, modified to work with RMII and a LAN8720 PHY. I can send and receive Ethernet data - great!

Unfortunately whenever I send a UDP packet, it has 50 bytes more payload than I expect. My anticipated payload is there, unmolested, but the additional data is undesired.


struct
udp_pcb* upcb = udp_new();

struct
pbuf* p = pbuf_alloc(PBUF_TRANSPORT, 
sizeof
(DataFrame), PBUF_RAM);

struct
ip_addr destAddr;

DataFrame data;


IP4_ADDR(&destAddr, 192, 168, 1, 55);

printf
(
''p->len: %u\r\n''
, p->len);

printf
(
''p->tot_len: %u\r\n''
, p->tot_len);

printf
(
''sizeof(DataFrame): %u\r\n''
, 
sizeof
(DataFrame));


char
* ptr = (
char
*)(&data);

for
(
int
a = 0; a < 
sizeof
(DataFrame); a++)

ptr[a] = a;


memcpy
(p->payload, &data, 
sizeof
(DataFrame));

udp_sendto(upcb, p, &destAddr, 4444);

The result from printf is 460, 460, and 4 In Wireshark I see that my data is 510 bytes. I can increase or decrease the size of my DataFrame struct, but the payload is always exactly fifty bytes more. Thoughts? -Sasha
1 REPLY 1
christian23
Associate
Posted on May 21, 2014 at 13:03

Hi.

Try to alloc the pbuf, send the udp message and then dealloc the pbuf.
p = pbuf_alloc(PBUF_TRANSPORT,
sizeof
(DataFrame), PBUF_RAM);
memcpy
(p->payload, &data,
sizeof
(DataFrame));

udp_sendto(upcb, p, &destAddr, 4444);

pbuf_free(p);