Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 May 2004 17:17:46 +0200
From:      Juan Rodriguez Hervella <jrh@it.uc3m.es>
To:        freebsd-net@freebsd.org
Subject:   Re: How to use the RTM_IFINFO message of a Routing Socket
Message-ID:  <200405111717.47794.jrh@it.uc3m.es>
In-Reply-To: <20040511082121.GA64972@ip.net.ua>
References:  <200405102102.51399.jrh@it.uc3m.es> <20040511082121.GA64972@ip.net.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/route.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <err.h>
#include <sys/time.h>
#include <net/if.h>
#include <time.h>

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"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200405111717.47794.jrh>