summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorGary Palmer <gpalmer@FreeBSD.org>1996-06-24 22:27:01 +0000
committerGary Palmer <gpalmer@FreeBSD.org>1996-06-24 22:27:01 +0000
commite964af08c062bf263668d5129b66358b58e0feba (patch)
tree50b8cc7d9db40c8b90c756c02ecf5f5ba462b5db /sbin
parent9556f391438f039d7882b05fb1afee4640a36867 (diff)
downloadsrc-test2-e964af08c062bf263668d5129b66358b58e0feba.tar.gz
src-test2-e964af08c062bf263668d5129b66358b58e0feba.zip
Notes
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 cc37eb892968..7b37f5f716f1 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\
@@ -208,22 +213,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;
@@ -235,7 +251,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 +
@@ -243,6 +259,7 @@ main(argc, argv)
sizeof(struct sockaddr));
ifptr++;
}
+ free(buffer);
} else
ifconfig(argc,argv,af,rafp, -1);