Date: Thu, 9 Jul 1998 16:04:11 -0700 (PDT) From: rec@rcousins.com To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: kern/7230: problem with SIOCGIFCONF Message-ID: <199807092304.QAA03280@www.RCousins.com>
next in thread | raw e-mail | index | archive | help
>Number: 7230 >Category: kern >Synopsis: problem with SIOCGIFCONF >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jul 9 16:10:01 PDT 1998 >Last-Modified: >Originator: Robert Cousus >Organization: >Release: FreeBSD 2.2.6-RELEASE i386 >Environment: K6 cpu, 128 megs RAM, 15 gigs Disk, 2 LAN ifces. >Description: SIOCGIFCONF does not return an array of struct ifreq with one entry per network interface. >How-To-Repeat: Compile and run the attached program to demonstrate the problem. (Note: program runs correctly under Solaris 2.5.1.) ----------------- #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <net/if.h> #include <sys/ioctl.h> char buffer[1<<12]; int main(int argc, char *argv[]) { int res; /* result from call */ int sock; /* socket file descriptor */ int i; /* loop variable */ struct ifconf ifconf; /* used in test below */ struct ifreq *ptr; /* pointer to walk buffer */ sock = socket(PF_INET, SOCK_DGRAM, 0); if (sock < 0) { perror("socket(PF_INET, SOCK_DGRAM, 0)"); exit(1); } ifconf.ifc_len = sizeof(buffer); /* establish size of buffer */ ifconf.ifc_buf = buffer; /* point to buffer */ res = ioctl(sock, SIOCGIFCONF, &ifconf); if (res < 0) { perror("ioctl(sock, SIOCGIFCONF, &ifconf)"); exit(1); } /* * At this point, the ifconf.ifc_len should tell how many bytes consumed * in the buffer and ifconf.ifc_req should point to an array of ifreq * structures. * /* * Test 1: The return value should be a multiple of sizeof(ifreq). */ if (ifconf.ifc_len % sizeof(struct ifreq)) { printf("Failed test1: %d %% %d = %d\n", ifconf.ifc_len, sizeof(struct ifreq), ifconf.ifc_len % sizeof(struct ifreq)); } /* * Test 2: We should be able to print out the names of all * interfaces by looping through the array. */ ptr = ifconf.ifc_req; /* point to beginning of array */ for (i = 0; i < (ifconf.ifc_len/sizeof(struct ifreq)); i++, ptr++) printf("Interface %d: %s\n", i, ptr->ifr_name); exit(0); } ----------------- >Fix: Unknown. >Audit-Trail: >Unformatted: Robert Cousins To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199807092304.QAA03280>