This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Set route to interface
On Montag, 30. Dezember 2002 15:07, Gary Thomas wrote:
> On Mon, 2002-12-30 at 07:03, Roland Caßebohm wrote:
> > On Montag, 30. Dezember 2002 13:49, Gary Thomas wrote:
> > > On Mon, 2002-12-30 at 03:25, Roland Caßebohm wrote:
> > > > Hi,
> > > >
> > > > how can I set a route for a specific ip-address outside of the actual
> > > > configured network to a interface.
> > > >
> > > > For example eCos is configured as follows:
> > > >
> > > > ip-address: 192.168.50.100
> > > > netmask: 255.255.255.0
> > > > gateway: 192.168.50.1
> > > >
> > > > Now I want to send an udp-message to 192.168.1.30. I thought I could
> > > > just add a route for destination 192.168.1.30 to "eth0". If I try
> > > > this under linux it seems to work.
> > > > -> route add -host 192.168.1.30 dev eth0
> > > >
> > > > Under eCos I have tried the following (peer is 192.168.1.30):
> > > >
> > > > int addroute(struct sockaddr peer)
> > > > {
> > > > struct sockaddr *so_peer=&peer;
> > > > struct sockaddr_in *so_in_peer=(struct sockaddr_in *)&peer;
> > > > struct ecos_rtentry route;
> > > > struct sockaddr_in a;
> > > > struct sockaddr_in *addrp=&a;
> > > > char mask[4]={255,255,255,255};
> > > > char local[4]={192,168,50,100};
> > >
> > > These constructs are not portable at all. It would be much better to
> > > use one of the address conversion functions to set these fields.
> >
> > Yes, this was just to make a short test.
> >
> > > > int s;
> > > >
> > > > /* verify the destination is directly reachable */
> > > > if ((ifa_ifwithnet(so_peer)) == NULL) {
> > >
> > > Note: calling functions internal to the stack is very bad practice.
> > >
> > > > s = socket(AF_INET, SOCK_DGRAM, 0);
> > > > if (s < 0) {
> > > > VS_PERROR(1,"socket");
> > > > return VS_EERROR;
> > > > }
> > > >
> > > > memset(&route, 0, sizeof(route));
> > > > addrp->sin_family = AF_INET;
> > > > addrp->sin_port = 0;
> > > > addrp->sin_len = sizeof(*addrp);
> > > > addrp->sin_addr = so_in_peer->sin_addr;
> > > > memcpy(&route.rt_dst, addrp, sizeof(*addrp));
> > > > memcpy(&addrp->sin_addr.s_addr,mask,4);
> > > > memcpy(&route.rt_genmask, addrp, sizeof(*addrp));
> > > > /* use local ip as gateway to set route to "eth0" */
> > > > memcpy(&addrp->sin_addr.s_addr,local,4);
> > > > memcpy(&route.rt_gateway, addrp, sizeof(*addrp));
> > > >
> > > > route.rt_dev = "eth0";
> > > > route.rt_flags = RTF_UP;
> > >
> > > Have you tried this?
> > > route.rt_flags = RTF_UP|RTF_GATEWAY;
> >
> > Yes, but it doesn't work. In both cases the ioctl() call succeds, but
> > sendto() to 192.168.1.30 fails.
I have forgotten to set *addrp whith 0, so now sendto() succeds, but I can't
see anything on the network (tcpdump).
>
> How about RTF_STATIC instead?
Does not change anything.
>
> Also, have you tried printing out the routing tables, to see if they
> look correct? I added some functions which do that recently.
This was very helpfully, so I could see that somthing was wrong with addrp.
If I look at the routing table of my linux host, the host flag is set:
Kernel IP Routentabelle
Ziel Router Genmask Flags Metric Ref Use Iface
192.168.1.30 * 255.255.255.255 UH 0 0 0 eth0
192.168.50.0 * 255.255.255.0 U 0 0 0 eth0
default 192.168.50.1 0.0.0.0 UG 0 0 0 eth0
But if I use RTF_HOST with eCos, show_network_tables(printf) don't show this
entry, but the entry seems to be there, because if try to add the routing
entry again, I get EEXIST.
But there is no message on the network too.
I have althought tried it with netmask 255.255.255.0 instead of
255.255.255.255. Then it works. The routing table looks as follows:
Routing tables
Destination Gateway Mask Flags Interface
127.0.0.0 127.0.0.1 255.0.0.0 UG lo0
192.168.1.0 192.168.1.0 255.255.255.0 U eth0
192.168.50.0 192.168.50.0 255.255.255.0 U eth0
But this is not realy what I want, I want somthing like this:
Routing tables
Destination Gateway Mask Flags Interface
127.0.0.0 127.0.0.1 255.0.0.0 UG lo0
192.168.1.30 192.168.1.30 255.255.255.255 U eth0
192.168.50.0 192.168.50.0 255.255.255.0 U eth0
>
> > > > route.rt_metric = 0;
> > > >
> > > > if (ioctl(s, SIOCADDRT, &route)) {
> > > > perror("SIOCADDRT");
> > > > if (errno != EEXIST) {
> > > > close(s);
> > > > return -1;
> > > > }
> > > > }
> > > > }
> > > >
> > > > close(s);
> > > > return 0;
> > > > }
> > > >
> > > > Thank you,
> > > >
> > > > Roland
> > > >
> > > > --
> > > > Before posting, please read the FAQ:
> > > > http://sources.redhat.com/fom/ecos and search the list archive:
> > > > http://sources.redhat.com/ml/ecos-discuss
> >
> > --
> > Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
> > and search the list archive: http://sources.redhat.com/ml/ecos-discuss
--
___________________________________________________
VS Vision Systems GmbH, Industrial Image Processing
Roland Caßebohm
Aspelohe 27A, D-22848 Norderstedt, Germany
Mail: roland.cassebohm@visionsystems.de
http://www.visionsystems.de
___________________________________________________
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss