summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1995-12-07 19:21:53 +0000
committerwollman <wollman@FreeBSD.org>1995-12-07 19:21:53 +0000
commitff7271fe707305ee1b15f5b069fdf2510e58dbf9 (patch)
tree51cdb2f793aca3a4cb597ab93ccbb722cf91ae52 /sbin
parent0c73aecc0624bd2fad30af747d6657e89c433bf5 (diff)
downloadFreeBSD-src-ff7271fe707305ee1b15f5b069fdf2510e58dbf9.zip
FreeBSD-src-ff7271fe707305ee1b15f5b069fdf2510e58dbf9.tar.gz
Use a dynamically-sized buffer for SIOCGIFCONF so that `ifconfig -a'
actually retrieves all the information no matter how many interfaces there are. (Probably there are other utilities which need similar modification.) Submitted by: Andrew Webster <awebster@dataradio.com>
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ifconfig/ifconfig.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index c0b2905..9fc8da6 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -31,6 +31,11 @@
* SUCH DAMAGE.
*/
+/*
+ * 951109 - Andrew@pubnix.net - Changed to iterative buffer growing mechanism
+ * for ifconfig -a so all interfaces are queried.
+ *
+ */
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
@@ -216,22 +221,33 @@ main(argc, argv)
exit(1);
}
if (strstr(name, "-a")) {
+ char *buffer;
struct ifconf ifc;
-#define MAX_INTERFACES 50 /* Yeah right. */
- char buffer[MAX_INTERFACES * sizeof(struct ifreq)];
struct ifreq *ifptr, *end;
int ifflags, selectflag = -1;
+ int oldbufsize, bufsize = sizeof(struct ifreq);
if (strstr(name, "-au"))
selectflag = 1;
if (strstr(name, "-ad"))
selectflag = 0;
- ifc.ifc_len = sizeof(buffer);
- ifc.ifc_buf = buffer;
- if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
- perror("ifconfig (SIOCGIFCONF)");
- exit (1);
- }
+ buffer = malloc(bufsize); /* allocate first buffer */
+ ifc.ifc_len = bufsize; /* Initial setting */
+ /*
+ * Itterate through here until we don't get any more data
+ */
+ do {
+ oldbufsize = ifc.ifc_len;
+ bufsize += 1+sizeof(struct ifreq);
+ buffer = realloc((void *)buffer, bufsize);
+ ifc.ifc_len = bufsize;
+ ifc.ifc_buf = buffer;
+ if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
+ perror("ifconfig (SIOCGIFCONF)");
+ exit (1);
+ }
+ } while (ifc.ifc_len > oldbufsize);
+
ifflags = ifc.ifc_req->ifr_flags;
end = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
ifptr = ifc.ifc_req;
@@ -243,7 +259,7 @@ main(argc, argv)
perror("ifconfig: socket");
exit(1);
}
- if (ifptr->ifr_flags == ifflags)
+ if (ifptr->ifr_flags == ifflags)
ifconfig(argc,argv,af,rafp,selectflag);
if(ifptr->ifr_addr.sa_len) /* Dohw! */
ifptr = (struct ifreq *) ((caddr_t) ifptr +
@@ -251,6 +267,7 @@ main(argc, argv)
sizeof(struct sockaddr));
ifptr++;
}
+ free(buffer);
} else
ifconfig(argc,argv,af,rafp, -1);
OpenPOWER on IntegriCloud