Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 2001 16:34:54 -0600 (CST)
From:      daved@tamu.edu
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   ports/24580: cfengine
Message-ID:  <200101232234.f0NMYsg16600@greywolf.tamu.edu>

next in thread | raw e-mail | index | archive | help

>Number:         24580
>Category:       ports
>Synopsis:       cfengine giving errors when invoked
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 23 14:40:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     David J Duchscher
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
Texas A&M University
>Environment:

	Clean install of 4.2-RELEASE.

>Description:

	cfengine produces the following errors when invoked:
	
	<hostname>: No such network device
	<hostname>: ioctl: Device not configured

>How-To-Repeat:

	Just have to run the command.  Does not matter what is in the
	configuration file.

>Fix:

	I peaked at the code and it looks like it is not handling the
	scanning of the ifconf list that is returned by the ioctl call.
	It is assuming that all the ifrec structures are a fixed size
	that is determined by the size of the ifrec structure.  This 
	seems not to be the case.  Below is a patach that I whipped up.
	It definately needs review and some more clean up.  It should
	probably also test for HAVE_SOCKADDR_SA_LEN but it doesn't 
	seem to exist in 4.2-RELEASE.  Hope this helps someone.

--- src/misc.c.orig	Fri Dec 15 16:33:05 2000
+++ src/misc.c	Tue Jan 23 11:33:40 2001
@@ -279,10 +279,11 @@
 void GetInterfaceInfo(void)
 
 { int fd,len,i,j;
-  struct ifreq ifbuf[64],ifr;
+  struct ifreq *ifr;
   struct ifconf list;
   struct sockaddr_in *sin;
   struct hostent *hp;
+  char *ifbuf, *ptr;
 
 if ((fd=socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    {
@@ -290,8 +291,10 @@
    exit(1);
    }
 
-list.ifc_len = sizeof(ifbuf);
-list.ifc_req = ifbuf;
+len = 64 * sizeof(struct ifreq);
+ifbuf = malloc(len);
+list.ifc_len = len;
+list.ifc_req = (struct ifreq *) ifbuf;
 
 if (ioctl(fd, SIOCGIFCONF, &list) == -1 || (list.ifc_len < (sizeof(struct ifreq))))
    {
@@ -299,23 +302,23 @@
    exit(1);
    }
 
-len=list.ifc_len/sizeof(struct ifreq);
-Debug("Found: %d interfaces\n",len);
-
-for (j=0;j<len;j++)
+for (ptr = ifbuf; ptr < ifbuf + list.ifc_len;) 
    {
-   Debug("Interface %d: %s\n", j+1, ifbuf[j].ifr_name);
+   ifr = (struct ifreq *) ptr;
+
+   Debug("Interface %s\n", ifr->ifr_name);
+
+   ptr += sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
 
-   strncpy(ifr.ifr_name,ifbuf[j].ifr_name,sizeof(ifbuf[j].ifr_name));
-   if (ioctl(fd,SIOCGIFFLAGS,&ifr) == -1)
+   if (ioctl(fd,SIOCGIFFLAGS,ifr) == -1)
       {
       CfLog(cferror,"No such network device","ioctl");
       return;
       }
 
-   if ((ifr.ifr_flags & IFF_UP) && !(ifr.ifr_flags & IFF_LOOPBACK))
+   if ((ifr->ifr_flags & IFF_UP) && !(ifr->ifr_flags & IFF_LOOPBACK) && (ifr->ifr_addr.sa_family == AF_INET))
       {
-      sin=(struct sockaddr_in *)&ifbuf[j].ifr_addr;
+      sin=(struct sockaddr_in *)&ifr->ifr_addr;
 
       if ((hp=gethostbyaddr((char *)&(sin->sin_addr.s_addr),sizeof(sin->sin_addr.s_addr),AF_INET)) == NULL)
          {


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




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