From owner-freebsd-questions Tue Aug 28 18:27:53 2001 Delivered-To: freebsd-questions@freebsd.org Received: from alicia.nttmcl.com (alicia.nttmcl.com [216.69.69.10]) by hub.freebsd.org (Postfix) with ESMTP id 128AF37B401 for ; Tue, 28 Aug 2001 18:27:48 -0700 (PDT) (envelope-from anu@nttmcl.com) Received: from ntt27f48otgmw8 (dhcp246.nttmcl.com [216.69.69.246]) by alicia.nttmcl.com (8.10.1/8.10.1) with SMTP id f7T1Rcv23091; Tue, 28 Aug 2001 18:27:38 -0700 (PDT) Reply-To: From: "Anuranjan" To: "'Kory Hamzeh'" Cc: Subject: RE: very urgent : trying to add a route to kernel table Date: Tue, 28 Aug 2001 18:27:31 -0700 Message-ID: <001a01c13029$c6a59fa0$f64545d8@ntt27f48otgmw8> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 In-Reply-To: <007901c13028$75eee4a0$14ce21c7@avatar.com> Importance: Normal 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 Hi Kory, THanks a lot for pointing my mistake out !! It was quite foolish on my part .. but fortunately it's not the problem in this case .... the call to calloc is succeeding .. only the code simply gives EINVAL when i try adding any route (i tried using ioctl with SIOCADDRT command and it ends up giving me EOPNOTSUPP). As I mentioned , RTM_DELETE works bug ADD doesn't... totally baffled :( -----Original Message----- From: Kory Hamzeh [mailto:kory@avatar.com] Sent: Tuesday, August 28, 2001 6:18 PM To: anu@nttmcl.com Subject: RE: very urgent : trying to add a route to kernel table Not quite sure why it is not working, but I think you should know that calloc returns 0 on error, not a negative number. > -----Original Message----- > From: owner-freebsd-questions@FreeBSD.ORG > [mailto:owner-freebsd-questions@FreeBSD.ORG]On Behalf Of Anuranjan > Sent: Tuesday, August 28, 2001 6:07 PM > To: questions@FreeBSD.ORG > Subject: very urgent : trying to add a route to kernel table > > > 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 > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message