[ECOS] Re: Retrieving default gateway?
Grant Edwards
grante@visi.com
Wed Oct 24 08:18:00 GMT 2001
On Tue, Oct 23, 2001 at 01:58:14PM -0500, Grant Edwards wrote:
> How does an application get info out of the routing table?
>
> I'm using ioctl(s,SIOCGIFxxxx,...) to find out the IP address
> and network mask, but I can't figure how to find out the
> default gateway.
Since it really bugs me when I search an archive and find my
question but no answer, what I came up with is shown below. I'm
still trying to decide whether I should call RTFREE(). Since
this routine gets called many times, not calling RTFREE should
result in less work on subsequent calls. I think. Maybe.
#include <network.h>
#include <net/route.h>
extern struct rtentry *rtalloc1(struct sockaddr *dst, int report);
unsigned long myIpGate(void)
{
struct rtentry *rt;
struct sockaddr dst;
memset(&dst,0,sizeof dst);
dst.sa_family = PF_INET;
rt = rtalloc1(&dst,0);
if (rt && rt->rt_gateway)
return ((struct sockaddr_in*)(rt->rt_gateway))->sin_addr.s_addr;
else
return 0;
}
--
Grant Edwards
grante@visi.com
More information about the Ecos-discuss
mailing list