On Wed, Apr 26, 2006 at 11:58:00PM +1000, Herbert Xu wrote:

> > I had spent time trying to write something which
> > uses RTA_SRC and RTA_DST and got some problems.
> > (I probably made something stupid.)
> > I googled for such examples and did not get much.
> > I saw that the zebra project and iproute uses
> > netlinks but it is complex.,
> 
> Have a look at
> 
> http://gondor.apana.org.au/~herbert/findsaddr-linux.c
> 
> which I wrote for traceroute some years back.

A fragile and ugly but easier/shorter way of getting the source address
(which I've used a couple of times in the past) is to open a SOCK_DGRAM
socket, connect() it to the intended destination, and then do
getsockname().

(That doesn't give you the interface, though.)


--L
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to