empty source port with sending udp data (lwip, Cortex M3, Stellaris LM3S6965 Evaluation Board)

StackOverflow https://stackoverflow.com/questions/14214782

  •  14-01-2022
  •  | 
  •  

I'm working with Cortex M3, Stellaris® LM3S6965 Evaluation Board. I'm sending an UDP packet to my pc. That works because I checked it with wireshark. But what I do see is that I don't have a source port. And I have no clue how so solve this.

I call this function to sent the a udp packet

void send_udp(){
    RIT128x96x4Enable(1000000);
    RIT128x96x4StringDraw("UDP data verzonden..", 0, 40, 15);

    struct ip_addr  serverIp;
    IP4_ADDR(&serverIp,192,168,1,100);

    u16_t port;
    port = 64000;
    struct udp_pcb * pcb;
    pcb = udp_new();

    udp_bind(pcb, &serverIp, port);
    udp_recv(pcb, udp_echo_recv, NULL);
    struct pbuf *p;
    char msg[]="request";

    //Allocate packet buffer
    p = pbuf_alloc(PBUF_TRANSPORT,sizeof(msg),PBUF_RAM);
    memcpy (p->payload, msg, sizeof(msg));
    udp_sendto(pcb, p, &serverIp, port);
    pbuf_free(p); //De-allocate packet buffer
}

Wireshark example of packet: (click here to enlarge) here

有帮助吗?

解决方案 2

I also saw that "time to live" in the ipv4 pcb was 0. So I added this line,

pcb->ttl = UDP_TTL; // Time to live

This solved my issue

其他提示

The call to udp_bind() should assign the local port, but it seems to be failing for you.

The number you're using (64000) is in the range called dynamic, private or ephemeral ports, which might be why it's not working as expected.

From the documentation, udp_bind() supports port number 0 to get a dynamically assigned number; this is typically the way to go if the source port isn't important.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top