Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Aug 2001 18:07:13 -0700
From:      "Anuranjan" <anu@nttmcl.com>
To:        <questions@freeBSD.ORG>
Subject:   very urgent : trying to add a route to kernel table 
Message-ID:  <001901c13026$f0aaf230$f64545d8@ntt27f48otgmw8>

next in thread | raw e-mail | index | archive | help
Hi,
I'm trying to add an entry into the kernel routing table (my first time).
Don't know what I'm doing wrong ... but when I try "RTM_DELETE" it works ..
only RTM_ADD doesn't (errno says EINVAL) ... any suggestions ? Am attaching
the code snippet here..

--Anu

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

process_pkt_info(char *srcIPaddr, char *dstIPaddr, int src_if_id)
{
	int err;
	struct sockaddr_in *s;
	int sockfd, rtsockfd;
	char *buf;
	pid_t pid;
	ssize_t n;
	struct rt_msghdr *rtm;
	struct sockaddr *sa, rti_info[RTAX_MAX];


	rtsockfd = socket(AF_ROUTE, SOCK_RAW, 0);

	buf = (char *)calloc(1, BUFLEN);
	if(buf < 0)
	{
		printf("calloc failed");
		abort();
	}

	rtm = (struct rt_msghdr *)buf;
	rtm->rtm_msglen = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
rtm->rtm_version = RTM_VERSION;
	rtm->rtm_type = RTM_ADD;
	rtm->rtm_addrs = RTA_DST;
	rtm->rtm_pid = pid = getpid();
	rtm->rtm_seq = SEQ;

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

	fwd_enable(1);

	if(write(rtsockfd, rtm, rtm->rtm_msglen) < 0 )
	{
		printf ("error: %d\n", errno);
	}

}

int main (void)
{	
	process_pkt_info("4.5.6.7", NULL, 2);
	return(0);
}


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?001901c13026$f0aaf230$f64545d8>