This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Routing table
- From: "C. Snider" <snider at efe-gmbh dot de>
- To: ecos-discuss at sources dot redhat dot com
- Date: Wed, 03 Sep 2008 11:13:03 +0200
- Subject: [ECOS] Routing table
- Reply-to: snider at efe-gmbh dot de
Hi,
I am trying to add manual entries to the routing table and it just
doesn't work. I tried everything I can think of and maybe somebody can
help me :-) I have a board with two NICs and want to build a small
routing table with maybe ten or twenty host entries. The NICs get
initialized successfully and sent out an ARP response. During startup
initnet is called with different Ips, the default route is added and
bound to the corresponding interface, but I cannot add more.
When I try to use the ioctl call SIOCADDR with a route bound to the
second NIC (eth1) the call succeeds, but the routing table shows, that
the entry is added to the first interface instead to the second one. I
tried various flags, adresses and also a cyg_route_reinit before adding
a new route. The result is always the same, the added route is always
bound to eth0.
Also the ioctl call SIOCADDR with the flag RTF_HOST doesn't work. The
route doesn't appear in the routing table and when I try to sent
something to the added host, I don't get an error but also no output on
eth0 or eth1.
I used the exact code from the inetnet, so I have no idea why it doesn't
work or what I did wrong. Attached to this post is my code and the output.
Hope somebody can help me.
C. Snider
cyg_bool add_route()
{
diag_printf("Start ... \n");
struct sockaddr_in *addrp;
struct ifreq ifr;
struct ecos_rtentry route;
int s;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s<0) {
perror ("Error creating socket");
return false;
}
show_network_tables(printf);
addrp = (struct sockaddr_in *) &ifr.ifr_addr;
memset(addrp, 0, sizeof(*addrp));
strcpy(ifr.ifr_name, eth1_name);
memset(&route, 0, sizeof(route));
addrp->sin_family = AF_INET;
addrp->sin_port = 0;
addrp->sin_len = sizeof(*addrp);
addrp->sin_addr.s_addr = inet_addr("192.165.4.0");
memset(&route, 0, sizeof(route));
memcpy(&route.rt_dst, addrp, sizeof(*addrp));
addrp->sin_addr.s_addr = inet_addr("255.255.255.0");
memcpy(&route.rt_genmask, addrp, sizeof(*addrp));
addrp->sin_addr.s_addr = 0;
memcpy(&route.rt_gateway, addrp, sizeof(*addrp));
route.rt_dev = ifr.ifr_name;
route.rt_flags = RTF_UP;
route.rt_metric = 0;
diag_printf("Adding new route over %s.\n",route.rt_dev );
if ((ioctl(s, SIOCADDRT, &route))!=-1) {
diag_printf("Route - dst: %s",
inet_ntoa(((struct sockaddr_in *)&route.rt_dst)->sin_addr));
diag_printf(", mask: %s",
inet_ntoa(((struct sockaddr_in *)&route.rt_genmask)->sin_addr));
diag_printf(", gateway: %s",
inet_ntoa(((struct sockaddr_in *)&route.rt_gateway)->sin_addr));
diag_printf(", device: %s\n", route.rt_dev);}
else
{
perror("SIOCADDRT 3");
return false;
}
show_network_tables(printf);
diag_printf("End ... \n");
close(s);
return true;
}
Output:
Start ...
Routing tables
Destination Gateway Mask Flags Interface
0.0.0.0 192.168.0.1 0.0.0.0 UG eth0
127.0.0.0 127.0.0.1 255.0.0.0 UG lo0
192.168.0.0 192.168.0.0 255.255.255.0 U eth0
192.168.1.0 192.168.1.0 255.255.255.0 U eth1
Interface statistics
eth0 IP: 192.168.0.51, Broadcast: 192.168.0.255, Netmask: 255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
eth1 IP: 192.168.1.52, Broadcast: 192.168.0.255, Netmask: 255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
lo0 IP: 127.0.0.1, Broadcast: 127.0.0.1, Netmask: 255.0.0.0
UP LOOPBACK RUNNING MULTICAST MTU: 16384, Metric: 0
Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
Adding new route over eth1.
Route - dst: 192.165.4.0, mask: 255.255.255.0, gateway: 0.0.0.0, device:
eth1
Routing tables
Destination Gateway Mask Flags Interface
0.0.0.0 192.168.0.1 0.0.0.0 UG eth0
127.0.0.0 127.0.0.1 255.0.0.0 UG lo0
192.165.4.0 192.165.4.0 255.255.255.0 U eth0
192.168.0.0 192.168.0.0 255.255.255.0 U eth0
192.168.1.0 192.168.1.0 255.255.255.0 U eth1
Interface statistics
eth0 IP: 192.168.0.51, Broadcast: 192.168.0.255, Netmask: 255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
eth1 IP: 192.168.1.52, Broadcast: 192.168.0.255, Netmask: 255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: 1500, Metric: 0
Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
lo0 IP: 127.0.0.1, Broadcast: 127.0.0.1, Netmask: 255.0.0.0
UP LOOPBACK RUNNING MULTICAST MTU: 16384, Metric: 0
Rx - Packets: 0, Bytes: 0, Tx - Packets: 0, Bytes: 0
End ...
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss