about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/if_index.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-06-29 02:48:21 +0000
committerUlrich Drepper <drepper@redhat.com>2004-06-29 02:48:21 +0000
commitde7b50f41386cdbe7ce2b0b5833d57965fd2c641 (patch)
treec391531fdcbaaa4d3314d37bb2dfd56e563d46a4 /sysdeps/unix/sysv/linux/if_index.c
parente1be0bc5657984906bb6885623d348914e135223 (diff)
downloadglibc-de7b50f41386cdbe7ce2b0b5833d57965fd2c641.tar.gz
glibc-de7b50f41386cdbe7ce2b0b5833d57965fd2c641.tar.xz
glibc-de7b50f41386cdbe7ce2b0b5833d57965fd2c641.zip
(if_nameindex): Use extend_alloca.
Diffstat (limited to 'sysdeps/unix/sysv/linux/if_index.c')
-rw-r--r--sysdeps/unix/sysv/linux/if_index.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c
index 76349bd96d..92fb11b180 100644
--- a/sysdeps/unix/sysv/linux/if_index.c
+++ b/sysdeps/unix/sysv/linux/if_index.c
@@ -16,6 +16,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <alloca.h>
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
@@ -118,17 +119,21 @@ if_nameindex (void)
     rq_len = RQ_IFS * sizeof (struct ifreq);
 
   /* Read all the interfaces out of the kernel.  */
-  do
+  ifc.ifc_buf = alloca (rq_len);
+  ifc.ifc_len = rq_len;
+  while (1)
     {
-      ifc.ifc_buf = alloca (ifc.ifc_len = rq_len);
-      if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0)
+        if (__ioctl (fd, SIOCGIFCONF, &ifc) < 0)
 	{
 	  close_not_cancel_no_status (fd);
 	  return NULL;
 	}
-      rq_len *= 2;
+      if (ifc.ifc_len < rq_len || ! old_siocgifconf)
+	break;
+
+      ifc.ifc_buf = extend_alloca (ifc.ifc_buf, rq_len, 2 * rq_len);
+      ifc.ifc_len = rq_len;
     }
-  while (ifc.ifc_len == rq_len && old_siocgifconf);
 
   nifs = ifc.ifc_len / sizeof (struct ifreq);