Subject: Re: ifstatus problems...
To: Brian Stark <bstark@siemens-psc.com>
From: Zdenek Salvet <salvet@ics.muni.cz>
List: netbsd-help
Date: 08/06/1998 21:41:25
> All,
> 
> Has anyone had any luck with getting ifstatus 2.1 to run properly on
> NetBSD 1.3.2?
> 
> Each time I try to run it I get the following:
> 
>   ./ifstatus: ioctl: SIOCGIFCONF: Device not configured.
> 
> The section of code that issues this message looks like this:
> 
>         struct ifconf ifc;
>         struct ifreq ifr, *ifrp;
> 
>         if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
>                 fatal("socket", NULL);
> 
>         ifc.ifc_buf = cbuf;
>         ifc.ifc_len = sizeof(cbuf);
> 
>         if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0)
>                 fatal("ioctl: SIOCGIFCONF", NULL);
> 
> ...it looks pretty straight forward, so I am wondering what I am missing.
> Even with the generic kernel I get the 'device not configured' message.
> Ideas anyone? (and yes, I did set the flags in the Makefile for a BSD 
> based OS).

Strange, in my copy of ifstatus sources SIOCGIFFLAGS part was wrong,
not SIOCGIFCONF. Here is patch:

diff -rc ifstatus/if-generic.c ifstatus.corr/if-generic.c
*** ifstatus/if-generic.c       Mon Jun 12 23:10:42 1995
--- ifstatus.corr/if-generic.c  Thu Aug  6 21:33:56 1998
***************
*** 32,42 ****
        close(s);
        ifrp = ifc.ifc_req;
  
!       for (n = ifc.ifc_len / sizeof(struct ifreq); n > 0; n--, ifrp++) {
                if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
                        fatal("socket", NULL);
- 
-               strcpy(ifr.ifr_name, ifrp->ifr_name);
  
                if (ioctl(s, SIOCGIFFLAGS, (char *) &ifr) < 0)
                        fatal("ioctl: SIOCGIFFLAGS", NULL);
--- 32,50 ----
        close(s);
        ifrp = ifc.ifc_req;
  
!       for (n = 0; n < ifc.ifc_len; ) {
!                 ifrp = (struct ifreq *)((caddr_t)ifc.ifc_req + n);
!                 n += sizeof(ifrp->ifr_name) +
!                         (ifrp->ifr_addr.sa_len > sizeof(struct sockaddr)
!                                 ? ifrp->ifr_addr.sa_len
!                                 : sizeof(struct sockaddr));
!                 if (!strncmp(ifr.ifr_name, ifrp->ifr_name,
!                              sizeof(ifrp->ifr_name)))
!                         continue;
!                 ifr = *ifrp;
! 
                if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
                        fatal("socket", NULL);
  
                if (ioctl(s, SIOCGIFFLAGS, (char *) &ifr) < 0)
                        fatal("ioctl: SIOCGIFFLAGS", NULL);


-- 
Zdenek Salvet                                              salvet@ics.muni.cz 
----------------------------------------------------------------------------
           If God had meant for us to be in the Army,
         we would have been born with green, baggy skin.