Very basic query regarding udp_sendto

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

Very basic query regarding udp_sendto

Hemant Kapoor
Hello,

I am a newbie to networking and managed to port lwip stack to LPC17xx
controller runninf freertos.
I have requirement to send UDP data to a static destination IP Address.

I have a task which tries to send a UDP Packet every one second.

When I send data via broadcast, it works.
udp_sendto(pcb, pb,IP_ADDR_BROADCAST,1235)

Also from my PC if I ping to my board it all works fine

But if I try to send data to a specific ip address (that of my PC) then it
doesn;t work
udp_sendto(pcb, pb,&destinationAddress,1235)

Also I niotice that ping stop working.




If I follow existing example of UDP Echo, i.e. connect to an IP and port for
UDP
udp_connect(pcb, &destinationAddress, pc_port);

and in callback of receive message, I send UDP packet it works.
udp_recv(pcb, udp_echo_recv, NULL);


In my call back
static void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p,
struct ip_addr *addr, u16_t port)
{
    udp_send(pcb, p);
    pbuf_free(p);
}


I thought UDP is connectionless and sending UDP Data to a given IP Address
and Port shuld simply work.
Can you please let me know what I am doing wrong here.



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

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

Re: Very basic query regarding udp_sendto

Patrick Klos-2
On 4/7/2020 8:15 AM, Hemant Kapoor wrote:

> Hello,
>
> I am a newbie to networking and managed to port lwip stack to LPC17xx
> controller runninf freertos.
> I have requirement to send UDP data to a static destination IP Address.
>
> I have a task which tries to send a UDP Packet every one second.
>
> When I send data via broadcast, it works.
> udp_sendto(pcb, pb,IP_ADDR_BROADCAST,1235)
>
> Also from my PC if I ping to my board it all works fine
>
> But if I try to send data to a specific ip address (that of my PC) then it
> doesn;t work
> udp_sendto(pcb, pb,&destinationAddress,1235)
>
> Also I niotice that ping stop working.

Not sure about the ping breaking after the bad send, but did you make
sure your destination address byte order is correct?  For instance, if
your target IP address is 192.168.1.1 (0xc0a80101), then you would set
destinationAddress like this:

         destinationAddress.addr = htonl(0xc0a80101);

Just a thought...

Patrick


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

Re: Very basic query regarding udp_sendto

Hemant Kapoor
Thanks for the response and sorry for late reply.

I have made sure that the Destination IP Address has correct ordering.
The way I ensured is following:

1. I introduced a delay of 15 seconds before sending udp_sendto command.
2. Before the initial 15 seconds expires, I send a Ping from my PC and I get
a response.
3. After 15 seconds expires, I an see UDP data on my PC using wire shark.


Now, if I reset my controller and skip step 2, i.e. donot send ping, then
after 15 seconds I cannot see any UDP Packets.

I have been stuck with this issue for quite a while.
Any help regarding this will be deeply appreciated.

Regards,
Hemant Kapoor



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

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