Getting destination address for UDP packets
Hi,
I'm working on a program which binds on all the available interfaces (0.0.0.0) and listens for/replies with UDP packets.
The problem is that I need to send back responses from the same IP address that the query arrived to, and this is not usually happening.
Example: supposing I have 1.1.1.2 and 1.1.1.3 aliased on the same interface, and a query arrives on 1.1.1.3, it's mandatory that the reply packet goes out from 1.1.1.3.
The question is: how do I get (from user space, if possible) the destination IP address of an UDP packet?
Thanks
Petru
Quoted 4 lines
I'm working on a program which binds on all the available interfaces (0.0.0.0)
and listens for/replies with UDP packets.
You need to bind to each interface *address*.
Quoted 3 lines
The problem is that I need to send back responses from the same IP address that
the query arrived to, and this is not usually happening.
Right, so bind each port to exactly one IP address.
Quoted 5 lines
Example: supposing I have 1.1.1.2 and 1.1.1.3 aliased on the same interface, and
a query arrives on 1.1.1.3, it's mandatory that the reply packet goes out from
1.1.1.3.
Then bind one socket to each IP and send the reply from the same socket
that received it.
Quoted 3 lines
The question is: how do I get (from user space, if possible) the destination
IP address of an UDP packet?
There are actually ways to do this, but the most portable way (and the way
NTP, bind, and others do it), is to bind to each IP that the program needs to listen on.
DS