summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTed Lemon <source@isc.org>2001-05-02 06:36:54 +0000
committerTed Lemon <source@isc.org>2001-05-02 06:36:54 +0000
commit615a574a25a6015aa246699609f38339bdad4ef2 (patch)
treeaf733eb3fe16ffe1dce3b6e457eac5903e0aa8b5 /common
parent24f9d67e03f5e844a2e59e06c17eaa14289e6838 (diff)
downloadisc-dhcp-615a574a25a6015aa246699609f38339bdad4ef2.tar.gz
Tweak the SIOCGIFCONF code once again.
Diffstat (limited to 'common')
-rw-r--r--common/discover.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/common/discover.c b/common/discover.c
index 6c3c8d91..6619fb27 100644
--- a/common/discover.c
+++ b/common/discover.c
@@ -43,7 +43,7 @@
#ifndef lint
static char copyright[] =
-"$Id: discover.c,v 1.41 2001/04/09 01:03:12 mellon Exp $ Copyright (c) 1995-2001 The Internet Software Consortium. All rights reserved.\n";
+"$Id: discover.c,v 1.42 2001/05/02 06:36:54 mellon Exp $ Copyright (c) 1995-2001 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -159,8 +159,7 @@ void discover_interfaces (state)
/* Get the interface configuration information... */
-#ifdef SIOCGIFCONF_NULL_BUF_GIVES_CORRECT_LEN
-
+#ifdef SIOCGIFCONF_ZERO_PROBE
/* linux will only tell us how long a buffer it wants if we give it
* a null buffer first. So, do a dry run to figure out the length.
*
@@ -171,24 +170,13 @@ void discover_interfaces (state)
ic.ifc_len = 0;
ic.ifc_ifcu.ifcu_buf = (caddr_t)NULL;
-
- i = ioctl(sock, SIOCGIFCONF, &ic);
- if (i < 0)
- log_fatal ("ioctl: SIOCGIFCONF: %m");
-
- ic.ifc_ifcu.ifcu_buf = dmalloc ((size_t)ic.ifc_len, MDL);
- if (!ic.ifc_ifcu.ifcu_buf)
- log_fatal ("Can't allocate SIOCGIFCONF buffer.");
-
-#else /* SIOCGIFCONF_NULL_BUF_GIVES_CORRECT_LEN */
-
+#else
/* otherwise, we just feed it a starting size, and it'll tell us if
* it needs more */
ic.ifc_len = sizeof buf;
ic.ifc_ifcu.ifcu_buf = (caddr_t)buf;
-
-#endif /* SIOCGIFCONF_NULL_BUF_GIVES_CORRECT_LEN */
+#endif
gifconf_again:
i = ioctl(sock, SIOCGIFCONF, &ic);
@@ -198,13 +186,23 @@ void discover_interfaces (state)
/* If the SIOCGIFCONF resulted in more data than would fit in
a buffer, allocate a bigger buffer. */
- if (ic.ifc_ifcu.ifcu_buf == buf &&
- ic.ifc_len > sizeof buf) {
+ if ((ic.ifc_ifcu.ifcu_buf == buf
+#ifdef SIOCGIFCONF_ZERO_PROBE
+ || ic.ifc_ifcu.ifcu_buf == 0
+#endif
+ ) && ic.ifc_len > sizeof buf) {
ic.ifc_ifcu.ifcu_buf = dmalloc ((size_t)ic.ifc_len, MDL);
if (!ic.ifc_ifcu.ifcu_buf)
log_fatal ("Can't allocate SIOCGIFCONF buffer.");
goto gifconf_again;
+#ifdef SIOCGIFCONF_ZERO_PROBE
+ } else if (ic.ifc_ifcu.ifcu_buf == 0) {
+ ic.ifc_ifcu.ifcu_buf = (caddr_t)buf;
+ if.ifc_len = sizeof buf;
+ goto gifconf_again;
+#endif
}
+
/* If we already have a list of interfaces, and we're running as
a DHCP server, the interfaces were requested. */