summaryrefslogtreecommitdiffstats
path: root/contrib/bind/lib/irs/gethostent.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind/lib/irs/gethostent.c')
-rw-r--r--contrib/bind/lib/irs/gethostent.c59
1 files changed, 43 insertions, 16 deletions
diff --git a/contrib/bind/lib/irs/gethostent.c b/contrib/bind/lib/irs/gethostent.c
index 8e7e717..3964b5f 100644
--- a/contrib/bind/lib/irs/gethostent.c
+++ b/contrib/bind/lib/irs/gethostent.c
@@ -16,7 +16,7 @@
*/
#if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: gethostent.c,v 1.32 2002/05/27 06:50:55 marka Exp $";
+static const char rcsid[] = "$Id: gethostent.c,v 1.32.10.2 2003/06/04 01:09:43 marka Exp $";
#endif
/* Imports */
@@ -482,7 +482,7 @@ freehostent(struct hostent *he) {
#define LIFREQ lifreq
#endif
-static int
+static void
scan_interfaces6(int *have_v4, int *have_v6) {
struct LIFCONF lifc;
struct LIFREQ lifreq;
@@ -492,12 +492,9 @@ scan_interfaces6(int *have_v4, int *have_v6) {
static unsigned int bufsiz = 4095;
int s, cpsize, n;
- /* Set to zero. Used as loop terminators below. */
- *have_v4 = *have_v6 = 0;
-
/* Get interface list from system. */
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) == -1)
- goto err_ret;
+ goto cleanup;
/*
* Grow buffer until large enough to contain all interface
@@ -506,7 +503,7 @@ scan_interfaces6(int *have_v4, int *have_v6) {
for (;;) {
buf = memget(bufsiz);
if (buf == NULL)
- goto err_ret;
+ goto cleanup;
#ifdef SETFAMILYFLAGS
lifc.lifc_family = AF_UNSPEC; /* request all families */
lifc.lifc_flags = 0;
@@ -526,10 +523,10 @@ scan_interfaces6(int *have_v4, int *have_v6) {
break;
}
if ((n == -1) && errno != EINVAL)
- goto err_ret;
+ goto cleanup;
if (bufsiz > 1000000)
- goto err_ret;
+ goto cleanup;
memput(buf, bufsiz);
bufsiz += 4096;
@@ -600,16 +597,42 @@ scan_interfaces6(int *have_v4, int *have_v6) {
memput(buf, bufsiz);
close(s);
/* printf("scan interface -> 4=%d 6=%d\n", *have_v4, *have_v6); */
- return (0);
- err_ret:
+ return;
+ cleanup:
if (buf != NULL)
memput(buf, bufsiz);
if (s != -1)
close(s);
/* printf("scan interface -> 4=%d 6=%d\n", *have_v4, *have_v6); */
- return (-1);
+ return;
}
+#endif
+#ifdef __linux
+#ifndef IF_NAMESIZE
+# ifdef IFNAMSIZ
+# define IF_NAMESIZE IFNAMSIZ
+# else
+# define IF_NAMESIZE 16
+# endif
+#endif
+static void
+scan_linux6(int *have_v6) {
+ FILE *proc = NULL;
+ char address[33];
+ char name[IF_NAMESIZE+1];
+ int ifindex, prefix, flag3, flag4;
+
+ proc = fopen("/proc/net/if_inet6", "r");
+ if (proc == NULL)
+ return;
+
+ if (fscanf(proc, "%32[a-f0-9] %x %x %x %x %16s\n",
+ address, &ifindex, &prefix, &flag3, &flag4, name) == 6)
+ *have_v6 = 1;
+ fclose(proc);
+ return;
+}
#endif
static int
@@ -626,17 +649,21 @@ scan_interfaces(int *have_v4, int *have_v6) {
int s, n;
size_t cpsize;
+ /* Set to zero. Used as loop terminators below. */
+ *have_v4 = *have_v6 = 0;
+
#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR) && \
!defined(IRIX_EMUL_IOCTL_SIOCGIFCONF)
/*
* Try to scan the interfaces using IPv6 ioctls().
*/
- if (!scan_interfaces6(have_v4, have_v6))
+ scan_interfaces6(have_v4, have_v6);
+ if (*have_v4 != 0 && *have_v6 != 0)
return (0);
#endif
-
- /* Set to zero. Used as loop terminators below. */
- *have_v4 = *have_v6 = 0;
+#ifdef __linux
+ scan_linux6(have_v6);
+#endif
/* Get interface list from system. */
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
OpenPOWER on IntegriCloud