From owner-freebsd-questions Wed Aug 29 0:14:59 2001 Delivered-To: freebsd-questions@freebsd.org Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by hub.freebsd.org (Postfix) with ESMTP id DC97137B406 for ; Wed, 29 Aug 2001 00:14:45 -0700 (PDT) (envelope-from ru@whale.sunbay.crimea.ua) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.11.2/8.11.2) id f7T7EGC73535; Wed, 29 Aug 2001 10:14:16 +0300 (EEST) (envelope-from ru) Date: Wed, 29 Aug 2001 10:14:16 +0300 From: Ruslan Ermilov To: Anuranjan Cc: questions@FreeBSD.ORG Subject: Re: very urgent : trying to add a route to kernel table Message-ID: <20010829101416.B70541@sunbay.com> References: <001901c13026$f0aaf230$f64545d8@ntt27f48otgmw8> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <001901c13026$f0aaf230$f64545d8@ntt27f48otgmw8>; from anu@nttmcl.com on Tue, Aug 28, 2001 at 06:07:13PM -0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Your program is equivalent of doing: # route add 4.5.6.7 route: writing to routing socket: Invalid argument add host 4.5.6.7: Invalid argument When adding a route, you should also specify a gateway (RTA_GATEWAY). On Tue, Aug 28, 2001 at 06:07:13PM -0700, Anuranjan wrote: > 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 -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message