This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Retrieving default gateway?
- To: ecos-discuss at sources dot redhat dot com
- Subject: [ECOS] Re: Retrieving default gateway?
- From: Grant Edwards <grante at visi dot com>
- Date: Wed, 24 Oct 2001 10:21:31 -0500
- References: <20011023135811.A6769@visi.com>
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