ESP8266_RTOS_SDK: [TW#24230] lwip raw UDP sendto not working as expected

Using lwip raw udp API, notice that only one UDP echo works then the device echoes back improperly after that (UDP packet seems to be malformed, missing payload)

#include "lwip/api.h"
#include "lwip/udp.h"

void udp_echo_recv(void *arg, 
    struct udp_pcb *pcb, struct pbuf *p,  
    const ip_addr_t *addr, u16_t port)
{
    if (p != NULL) {
        /* send received packet back to sender */
        udp_sendto(pcb, p, addr, port);
        /* free the pbuf */
        pbuf_free(p);
    }
}


void udp_echo_init(void)
{
    struct udp_pcb * pcb;

    /* get new pcb */
    pcb = udp_new();
    if (pcb == NULL) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_new failed!\n"));
        return;
    }

    /* bind to any IP address on port 7 */
    if (udp_bind(pcb, IP_ADDR_ANY, 7) != ERR_OK) {
        LWIP_DEBUGF(UDP_DEBUG, ("udp_bind failed!\n"));
        return;
    }

    /* set udp_echo_recv() as callback function
       for received packets */
    udp_recv(pcb, udp_echo_recv, NULL);
}

tcpdump after asking to echo ‘123’:

00:09:21.434673 IP (tos 0x0, ttl 64, id 11414, offset 0, flags [none], proto UDP (17), length 32)
    192.168.2.2.49738 > 192.168.2.179.echo: [udp sum ok] UDP, length 4
	0x0000:  5ccf 7f3a 08ba 58b0 3561 d381 0800 4500  \..:..X.5a....E.
	0x0010:  0020 2c96 0000 4011 c831 c0a8 0202 c0a8  ..,...@..1......
	0x0020:  02b3 c24a 0007 000c 5342 3132 330a       ...J....SB123.
00:09:21.636659 IP truncated-ip - 4 bytes missing! (tos 0x0, ttl 255, id 5, offset 0, flags [none], proto UDP (17), length 32)
    192.168.2.179.echo > 192.168.2.2.49738: UDP, length 4
	0x0000:  58b0 3561 d381 5ccf 7f3a 08ba 0800 4500  X.5a..\..:....E.
	0x0010:  0020 0005 0000 ff11 35c2 c0a8 02b3 c0a8  ........5.......
	0x0020:  0202 0007 c24a 000c 5342  

Full code here

Any thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18

Most upvoted comments

Hi @malachib

I have tested and have not reproduced this problem.

Could you use wireshark or omnipeek to capture packets?

Thank you!

11:47:02.769376 IP (tos 0x0, ttl 64, id 24157, offset 0, flags [DF], proto UDP (17), length 34)
    192.168.3.150.39281 > 192.168.3.153.echo: [bad udp cksum 0x889f -> 0x265b!] UDP, length 6
	0x0000:  4500 0022 5e5d 4000 4011 53ee c0a8 0396  E.."^]@.@.S.....
	0x0010:  c0a8 0399 9971 0007 000e 889f 5342 3132  .....q......SB12
	0x0020:  330a                                     3.
11:47:02.772754 IP (tos 0x0, ttl 255, id 3, offset 0, flags [none], proto UDP (17), length 34)
    192.168.3.153.echo > 192.168.3.150.39281: [udp sum ok] UDP, length 6
	0x0000:  4500 0022 0003 0000 ff11 3348 c0a8 0399  E.."......3H....
	0x0010:  c0a8 0396 0007 9971 000e 265b 5342 3132  .......q..&[SB12
	0x0020:  330a 0000 0000 0000 0000 0000 0000       3.............