|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 -----
|[Prev in Thread]||Current Thread||[Next in Thread]|