From owner-freebsd-net@FreeBSD.ORG Tue May 11 08:18:09 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A995D16A4CF; Tue, 11 May 2004 08:18:09 -0700 (PDT) Received: from smtp03.uc3m.es (smtp03.uc3m.es [163.117.136.123]) by mx1.FreeBSD.org (Postfix) with ESMTP id 910B943D54; Tue, 11 May 2004 08:18:08 -0700 (PDT) (envelope-from jrh@it.uc3m.es) Received: from smtp03.uc3m.es (localhost [127.0.0.1]) by localhost.uc3m.es (Postfix) with ESMTP id 4090129447; Tue, 11 May 2004 17:18:07 +0200 (CEST) Received: from [163.117.139.95] (cimborrio.it.uc3m.es [163.117.139.95]) by smtp03.uc3m.es (Postfix) with ESMTP id 2C7892942D; Tue, 11 May 2004 17:18:07 +0200 (CEST) From: Juan Rodriguez Hervella Organization: UC3M To: freebsd-net@freebsd.org Date: Tue, 11 May 2004 17:17:46 +0200 User-Agent: KMail/1.6 References: <200405102102.51399.jrh@it.uc3m.es> <20040511082121.GA64972@ip.net.ua> In-Reply-To: <20040511082121.GA64972@ip.net.ua> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200405111717.47794.jrh@it.uc3m.es> Subject: Re: How to use the RTM_IFINFO message of a Routing Socket X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2004 15:18:09 -0000 Hello, I've made several things: 1. Add a simple "rt_ifmsg(ifp)" function call inside /dev/wi/if_wi.c, at function: wi_update_stats (FreeBSD-4.9) 2. Then I try to get those notifications with the small program that follows, but I can not get anything. Where could the problem be ? Thanks a lot! #include #include #include #include #include #include #include #include #include #include #include #include struct if_msghdr msg; int main () { int len, s, i, wi_index; struct if_nameindex *ifnames; time_t t; s = socket(PF_ROUTE, SOCK_RAW, 0); start: msg.ifm_type = RTM_IFINFO; msg.ifm_version = RTM_VERSION; ifnames = if_nameindex(); i=0; while( ifnames[i].if_index != NULL ) { printf("index: %d, name %s\n", ifnames[i].if_index, ifnames[i].if_name ); if( strcmp("wi0", ifnames[i].if_name ) == 0 ) wi_index = ifnames[i].if_index; i++; } if_freenameindex( ifnames ); do { if( (len = read(s, (char *)&msg, sizeof(msg))) < 0 ) { err(1, "reading from routing socket"); return -1; } } while ( (msg.ifm_type != RTM_IFINFO) || (msg.ifm_index != wi_index) ); t= time( NULL ); printf("notification time: %s", ctime(&t) ); goto start; /* never reached */ return 0; } On Tuesday 11 May 2004 10:21, Ruslan Ermilov wrote: > On Mon, May 10, 2004 at 09:02:51PM +0200, Juan Rodriguez Hervella wrote: > > Hello, > > > > I dont understand, looking at "man 4 route", how to use the RTM_IFINFO > > message of a Routing Socket. > > > > I mean, do I have to make a "write" on the socket with a > > "struct if_msghdr" of type = RTM_IFINFO and later on a "read" with > > the same data structure ? > > > > Or can I just open the PF_ROUTE socket and then make a "read" with > > a "struct if_msghdr" data structure, w/out doing a "write" ? > > > > I'm really lost, and I haven't found documentation about this topic, so > > please if somebody can give me an example or pointing me to > > somewhere to learn to use this, I'd be delighted. Looking at > > "usr/src/bin/route.c" is simple another big mess for me. > > > > I'm looking forward to your answers, net-people ! > > A kernel emits the RTM_IFINFO message on a routing socket by ether > reacting to the NET_RT_IFLIST sysctl(3), or when the interface's > status changes (see "route monitor" for one such example). > > > Cheers, -- ****** JFRH ****** Avoid Quiet and Placid persons unless you are in Need of Sleep. -- National Lampoon, "Deteriorata"