This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Unable to add route using routing socket
- From: "aditya veer singh" <adityav at cdotd dot ernet dot in>
- To: ecos-discuss at sourceware dot org
- Date: Wed, 20 Dec 2006 16:32:15 +0530
- Subject: [ECOS] Unable to add route using routing socket
Hi,
I am using ecos taken from CVS branch of FEB 2006.
I want to add a route to BSD TCP/IP stacks IP route table
using routing sockets.
I have written the below code:
u_int32_t g,m,d;
int routes;
struct{
struct rt_msghdr hdr;
struct sockaddr_in dst;
struct sockaddr_in gway;
struct sockaddr_in mask;
}rtmsg;
if((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET) < 0)){
diag_printf("\nError route socket");
}
memset(&rtmsg, 0, sizeof(rtmsg));
rtmsg.hdr.rtm_msglen = sizeof(rtmsg);
rtmsg.hdr.rtm_version = RTM_VERSION;
rtmsg.hdr.rtm_type = RTM_ADD;
rtmsg.hdr.rtm_addrs = RTA_DST|RTA_GATEWAY|RTA_NETMASK;
rtmsg.hdr.rtm_flags = RTF_UP|RTF_HOST|RTF_STATIC;
rtmsg.dst.sin_len = sizeof(rtmsg.dst);
rtmsg.dst.sin_family = AF_INET;
inet_pton(AF_INET, "192.168.9.55",(char *)&rtmsg.dst.sin_addr);
rtmsg.gway.sin_len = sizeof(rtmsg.gway);
rtmsg.gway.sin_family = AF_INET;
inet_pton(AF_INET, "192.168.7.43",(char *)&rtmsg.gway.sin_addr);
rtmsg.mask.sin_len = sizeof(rtmsg.mask);
rtmsg.mask.sin_family = AF_INET;
inet_pton(AF_INET, "255.255.255.255",(char *)&rtmsg.mask.sin_addr);
if(write (routes, &rtmsg, sizeof(rtmsg)) < 0){
perror("write");
}
On executing it I get error in write "Bad file handle".
What needs to be done correct it?
Regards,
Aditya
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss