Getting gateway to use for a given ip in ANSI C

Viewed 25200

I have looked around like crazy but don't get a real answer. I got one example, but that depended on the individuals own library so not much good.

At first I wanted to get the default gateway of an interface, but since different IP's could be routed differently I quickly understood that what I want it get the gateway to use for a given destination IP by using an AF_ROUTE socket and the rtm_type RTM_GET. Does anyone have an example where I actually end up with a string containing the gateways IP (or mac address)? The gateway entry seem to be in hex but also encoded in /proc/net/route, where I guess the AF_ROUTE socket get's it info from (but via the kernel I guess).

Thanx in advance

and p.s. I just started using stack overflow and I must say, all of you guys are great! Fast replies and good ones! You are my new best friends ;)

3 Answers
Related