lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] OT: Binding UDP in WinXP


From: David Empson
Subject: Re: [lwip-users] OT: Binding UDP in WinXP
Date: Thu, 16 Jul 2009 10:32:37 +1200

You can't. :-)
 
Looking at the BSD socket API in general, the point of bind() is to specify a local "name" (family, address and port) for the socket. It doesn't say anything about the remote IP address or port.
 
With TCP, you must bind() the listening socket (since it requires a well known port) but typically don't bind the connecting socket unless it also needs to use a fixed port.
 
With UDP, you typically bind() any socket which needs to receive data on a well known port, but don't bother for one that is just sending data (or one which will remain open for receive, and other devices find out which port you are using due to receiving data from you or through other means).
 
The address in the bind() call must be one of your own IP addresses, typically that of a specific network interface. You can use IP_ADDRANY to leave your socket able to communicate via any network interface.
 
An unbound socket will use IP_ADDRANY and a randomly assigned port number.
 
If you are receiving UDP data from two devices on the same socket (i.e. both are sending data to the same port), you call recvfrom() and use the address passed back via the "from" parameter to distinguish them.
 
----- Original Message -----
Sent: Thursday, July 16, 2009 6:53 AM
Subject: [lwip-users] OT: Binding UDP in WinXP

After half a day at this problem that I can’t solve, I figure someone here might say the answer is, “You can’t” and I’ll know I have a big problem. J

I can send UDP data from WinXP to lwIP using SentTo no problem.  I can receive from lwIP if I use the port and IP_ADDRANY.  I realized with 2 of my devices connected I have a problem so I tried to bind the UDP socket in WinXP to the IP address and port of the lwIP device (I know it from a prior UDP “here I am” broadcast).  WinXP refuses to bind (or connect) to a specific IP address.  I know I’m missing something and spent half the day not finding it.  How do you bind a WinXP SOCK_DGRAM socket to a remote IP address and port?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]