Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Aug 2001 14:11:29 -0700
From:      "Anuranjan" <anu@nttmcl.com>
To:        <questions@freeBSD.ORG>
Subject:   why wouldn't this code work :(
Message-ID:  <002001c13198$56e8c550$f64545d8@ntt27f48otgmw8>

next in thread | raw e-mail | index | archive | help
Hi,
Following is an attempt to add an entry into the kernel routing table using
ioctl ..... it give errno = EOPNOTSUPP. I understand that this means there's
some problem in the rtentry parameter I'm passing to ioctl ... but for the
world of me I can't understand how to make this work!!! Help greatly
appreciated..........
--A

----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------


add_entry(char *srcIPaddr)
{
	int err;
	struct rtentry *rt;
	struct sockaddr_in *s;
	int sockfd;

	struct sockaddr_in gway;

	srcIPaddr = "4.5.6.7";

	memset(&gway, 0, sizeof(struct sockaddr_in));
	gway.sin_family = AF_INET;
	gway.sin_addr.s_addr = inet_addr("2.3.4.1");

	s->sin_len = sizeof(struct sockaddr_in);
	s->sin_family = AF_INET;
	s->sin_addr.s_addr = inet_addr(srcIPaddr);

	rt = (struct rtentry*)malloc(sizeof(struct rtentry));
	memset(rt, 0, (sizeof(struct rtentry)));
	rt->rt_flags |= RTF_HOST;

	rt->rt_gateway = (struct sockaddr *)&gway;
	rt->rt_flags |= RTF_UP | RTF_GATEWAY;
	rt->rt_use = 0;

	rt_key(rt) = (struct sockaddr*)s;

	fwd_enable(1);

	sockfd = socket(AF_INET, SOCK_DGRAM, 0);

	if( ioctl(sockfd, SIOCADDRT, rt) < 0)
 	{
		if (errno != EINVAL)
		{
			printf ("ioctl error :%d\n", errno);
		}
	}
}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?002001c13198$56e8c550$f64545d8>