How to add a gateway address using ioctl in C in linux ?
Hi,
I want to add a default gateway address using ioctl instead of system call.
In c, using system call in main(), it works fine.
but I want to use ioctl SIOCADDRT to add gateway.
So I used the following code.
if ((r = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
return EXIT_FAILURE;
}
route_gateway = (struct sockaddr_in *)&rtentry.rt_gateway;
route_gateway->sin_family = AF_INET;
route_gateway->sin_addr.s_addr = inet_addr("192.168.6.1");
if (ioctl(r, SIOCADDRT, &rtentry) == -1) {
perror("ioctl");
return ;
}
It gives me following error from ioctl :
Address family is not supported by this protocol.
Can anyone help me out to figure out what I m missing ?
Thanks in advance.
Last edited by sweta; 12-20-2006 at 05:47 AM.
|