Article 562M9 Remove a route using ioctl

Remove a route using ioctl

by
getsoubl
from LinuxQuestions.org on (#562M9)
I try to remove a route from iptable using ioctl in a opensuse machine. I open the socket fd . But when try to remove the rule the error that I get is the following No such process , Errno 3

Below is the code that I run

#include <sys/socket.h>
#include <linux/route.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>
bool delNullRoute( long host )
{
int fd = socket( PF_INET, SOCK_DGRAM, IPPROTO_IP );

struct rtentry route;
memset( &route, 0, sizeof( route ) );

struct sockaddr_in *addr = (struct sockaddr_in *)&route.rt_gateway;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = 0;

addr = (struct sockaddr_in*) &route.rt_dst;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = (host);

addr = (struct sockaddr_in*) &route.rt_genmask;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = INADDR_ANY;

route.rt_flags = RTF_UP | RTF_HOST | RTF_REJECT;
route.rt_metric = 0;

// this time we are deleting the route:
if ( ioctl( fd, SIOCDELRT, &route ) )
{
close( fd );
return false;
}

close( fd );
return true;
}latest?d=yIl2AUoC8zA latest?i=YZfPJC4Ayzc:Wv7SduTEezA:F7zBnMy latest?i=YZfPJC4Ayzc:Wv7SduTEezA:V_sGLiP latest?d=qj6IDK7rITs latest?i=YZfPJC4Ayzc:Wv7SduTEezA:gIN9vFwYZfPJC4Ayzc
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments