[Top] [All Lists]

How to determine source ip address

To: netdev@xxxxxxxxxxx
Subject: How to determine source ip address
From: Padraig Brady <padraig@xxxxxxxxxxxxx>
Date: Mon, 10 Sep 2001 20:23:17 +0100
Newsgroups: comp.os.linux.networking
Sender: owner-netdev@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.3) Gecko/20010808

I'm writing a network app (currently on linux 2.2.18,
but soon moving to 2.4) that needs to build up ip &
tcp packets manually. So my question is how do I determine
the source ip address to use for a given destination
ip address. I.E. take account of multiple interfaces/routes/

Could I create a temporary UDP socket and connect() it.
If indeed the kernel fills in the appropriate info when
"connecting" a UDP socket (source ip/port), how do I read
this info?

If a port number is not allocated with the above connect(),
how do I manually allocate a source port, bind()?

Or do I have to resort to ioctl()?


(I'm not on netdev).

<Prev in Thread] Current Thread [Next in Thread>