title: Getting gateway to use for a given ip in ANSI C
body: <p>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.</p>
  
  <p>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 <code>AF_ROUTE</code> socket and the <code>rtm_type RTM_GET</code>.
  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 <code>AF_ROUTE</code> socket get's it info from (but via the kernel I guess).</p>
  
  <p>Thanx in advance</p>
  
  <p>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 ;)</p>