This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
gateway
- From: "Eduardo Sabaj" <esabaj at gmail dot com>
- To: ecos-discuss at ecos dot sourceware dot org
- Cc: esabaj at hasar dot com
- Date: Fri, 15 Aug 2008 08:25:28 -0300
- Subject: [ECOS] gateway
I need to change the gateway address of the "eth0" interface on
runtime, so I would like to know if what I'm doing is correct:
int
SetGateway (const char *interface, const char *address)
{
int test_sock;
struct ecos_rtentry route;
test_sock = socket (PF_INET, SOCK_DGRAM, 0);
if ( test_sock == -1 )
return -1;
struct sockaddr_in a;
struct sockaddr_in *addrp = &a;
memset (&route, 0, sizeof(route));
addrp->sin_family = AF_INET;
addrp->sin_port = 0;
addrp->sin_len = sizeof(*addrp);
inet_pton (AF_INET, address, (char *)&addrp->sin_addr.s_addr);
memcpy (&route.rt_dst, addrp, sizeof(*addrp));
memcpy (&route.rt_gateway, addrp, sizeof(*addrp));
route.rt_dev = (char *)interface;
route.rt_flags = RTF_UP|RTF_GATEWAY;
if ( ioctl (test_sock, SIOCADDRT, &route) == -1 )
{
diag_printf ("Imposible fijar gateway");
close (test_sock);
return -1;
}
close (test_sock);
return 0;
}
Two more doubts:
1) Which is the way to obtain the gateway address on runtime? I didn't
find the ioctl to do this..
2) Is it possible to work without a gateway ? Nowadays I'm programming
the gateway with the same ip address configured for eth0.
Thank you in advance ..
Eduardo
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss