Reputation: 3222
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)
Upvotes: 1
Views: 2122
Reputation: 3222
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
Upvotes: 1
Reputation: 399703
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.
Upvotes: 2