bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-inetutils] ifconfig -a doesn't show all interfaces


From: Giuseppe Scrivano
Subject: Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
Date: Sat, 07 Aug 2010 21:37:05 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

"Alfred M. Szmidt" <address@hidden> writes:

>    +#define HAVE_SYSTEM_IF_NAMEINDEX 1
>
> I dislike this so much that I have to object to the patch, can't we
> put the GNU/Linux cruft in linux.c, and have a generic version in
> generic.c that is used by OSF, Solaris, ...? Or find something more
> decent than have random macros all over the place?

This is another version, I have removed the macro.

Cheers,
Giuseppe



>From ffe718a689595a3e2db593ce7ccd185bee8e6af7 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <address@hidden>
Date: Sat, 7 Aug 2010 21:29:30 +0200
Subject: [PATCH] Under GNU/Linux ifconfig -a includes interfaces without an 
address

* bootstrap.conf (gnulib_modules): Add module `read-file'.

* NEWS: Update.

* ifconfig/options.c (parse_cmdline): Use system_functions->if_nameindex,
not if_nameindex.

* ifconfig/system.h: Include <if_index.h>.  Add declaration of
`system_functions' and `generic_system_functions'.
(system_functions): New struct.
* ifconfig/system.c (_generic_system_functions): New struct.

* ifconfig/system/hpux.c (system_functions): New struct.
* ifconfig/system/qnc.c (system_functions): Likewise.
* ifconfig/system/solaris.c (system_functions): Likewise.
* ifconfig/system/solaris.c (system_functions): Likewise.

* ifconfig/system/linux.c (linux_if_nameindex): New function.
(linux_system_functions): New struct.
(system_functions): New struct.
---
 ChangeLog                 |   25 +++++++++++++
 NEWS                      |    8 ++++
 bootstrap.conf            |    1 +
 ifconfig/options.c        |    2 +-
 ifconfig/system.c         |    5 +++
 ifconfig/system.h         |   11 ++++++
 ifconfig/system/hpux.c    |    2 +
 ifconfig/system/linux.c   |   86 +++++++++++++++++++++++++++++++++++++++++++++
 ifconfig/system/linux.h   |    2 +-
 ifconfig/system/qnx.c     |    2 +
 ifconfig/system/solaris.c |    2 +
 11 files changed, 144 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 052daee..46dd072 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2010-08-07  Giuseppe Scrivano  <address@hidden>
+
+       Under GNU/Linux ifconfig -a includes interfaces without an address
+
+       * bootstrap.conf (gnulib_modules): Add module `read-file'.
+
+       * NEWS: Update.
+
+       * ifconfig/options.c (parse_cmdline): Use 
system_functions->if_nameindex,
+       not if_nameindex.
+
+       * ifconfig/system.h: Include <if_index.h>.  Add declaration of
+       `system_functions' and `generic_system_functions'.
+       (system_functions): New struct.
+       * ifconfig/system.c (_generic_system_functions): New struct.
+
+       * ifconfig/system/hpux.c (system_functions): New struct.
+       * ifconfig/system/qnc.c (system_functions): Likewise.
+       * ifconfig/system/solaris.c (system_functions): Likewise.
+       * ifconfig/system/solaris.c (system_functions): Likewise.
+
+       * ifconfig/system/linux.c (linux_if_nameindex): New function.
+       (linux_system_functions): New struct.
+       (system_functions): New struct.
+
 2010-07-30  Giuseppe Scrivano  <address@hidden>
 
        * ifconfig/if_index.c (if_nameindex): Remove local variable `len'.
diff --git a/NEWS b/NEWS
index 4583586..2f2dfdf 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,14 @@ See the end of this file for for license conditions.
 
 Please send inetutils bug reports to <address@hidden>.
 
+XXX YY, ZZ
+Version A.B:
+
+* ifconfig
+
+Now under GNU/Linux "ifconfig -a" shows also interfaces without an address.
+
+
 May 15, 2010
 Version 1.8:
 
diff --git a/bootstrap.conf b/bootstrap.conf
index bbb5c2e..facab0a 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -53,6 +53,7 @@ minmax
 obstack
 poll
 progname
+read-file
 readline
 readutmp
 realloc
diff --git a/ifconfig/options.c b/ifconfig/options.c
index 752aa47..52acd26 100644
--- a/ifconfig/options.c
+++ b/ifconfig/options.c
@@ -590,7 +590,7 @@ parse_cmdline (int argc, char *argv[])
       /* No interfaces specified.  Get a list of all interfaces.  */
       struct if_nameindex *ifnx, *ifnxp;
 
-      ifnx = ifnxp = if_nameindex ();
+      ifnx = ifnxp = system_functions->if_nameindex ();
       while (ifnxp->if_index != 0 || ifnxp->if_name != NULL)
        {
          struct ifconfig *ifp;
diff --git a/ifconfig/system.c b/ifconfig/system.c
index 3349187..9caa812 100644
--- a/ifconfig/system.c
+++ b/ifconfig/system.c
@@ -30,3 +30,8 @@
 #else
 # include "system/generic.c"
 #endif
+
+struct system_functions generic_system_functions =
+   {
+     .if_nameindex = if_nameindex
+   };
diff --git a/ifconfig/system.h b/ifconfig/system.h
index 0a74da8..20f843a 100644
--- a/ifconfig/system.h
+++ b/ifconfig/system.h
@@ -23,6 +23,8 @@
 # define IFCONFIG_SYSTEM_H
 
 
+# include <if_index.h>
+
 /* Option parsing.  */
 
 extern struct argp_child system_argp_child;
@@ -85,6 +87,15 @@ int system_configure (int sfd, struct ifreq *ifr,
 # endif
 
 
+struct system_functions
+{
+  struct if_nameindex* (*if_nameindex) (void);
+};
+
+/* System specific functions.  */
+extern struct system_functions *system_functions;
+
+extern struct system_functions generic_system_functions;
 
 # if defined(__linux__)
 #  include "system/linux.h"
diff --git a/ifconfig/system/hpux.c b/ifconfig/system/hpux.c
index 5ba5a0b..5f86e86 100644
--- a/ifconfig/system/hpux.c
+++ b/ifconfig/system/hpux.c
@@ -162,3 +162,5 @@ system_configure (int sfd, struct ifreq *ifr, struct 
system_ifconfig *ifs)
 {
   return 0;
 }
+
+struct system_functions *system_functions = &generic_system_functions;
diff --git a/ifconfig/system/linux.c b/ifconfig/system/linux.c
index fd5a1b2..8816b8d 100644
--- a/ifconfig/system/linux.c
+++ b/ifconfig/system/linux.c
@@ -46,6 +46,8 @@
 #include <net/if_arp.h>
 #include <linux/if_ether.h>
 
+#include <read-file.h>
+
 #include "../ifconfig.h"
 
 
@@ -846,3 +848,87 @@ system_configure (int sfd, struct ifreq *ifr, struct 
system_ifconfig *ifs)
     }
   return 0;
 }
+
+static struct if_nameindex *
+linux_if_nameindex (void)
+{
+  char *content, *it;
+  size_t length, index;
+  struct if_nameindex *idx = NULL;
+  int fd;
+
+  fd = socket (AF_INET, SOCK_DGRAM, 0);
+  if (fd < 0)
+    return NULL;
+
+  content = read_file (PATH_PROCNET_DEV, &length);
+  if (content == NULL)
+    return NULL;
+
+  /* Count how many interfaces we have.  */
+  {
+    size_t n = 0;
+    it = content;
+    do
+      {
+        it = memchr (it + 1, ':', length - (it - content));
+        n++;
+      }
+    while (it);
+
+    idx = malloc (n * sizeof (*idx));
+    if (idx == NULL)
+      {
+        int saved_errno = errno;
+        close (fd);
+        free (content);
+        errno = saved_errno;
+        return NULL;
+      }
+  }
+
+  for (it = memchr (content, ':', length), index = 0; it;
+       it = memchr (it, ':', it - content), index++)
+    {
+      char *start = it - 1;
+      *it = '\0';
+
+      while (*start != ' ' && *start != '\n')
+        start--;
+
+      idx[index].if_name = strdup (start + 1);
+      idx[index].if_index = index + 1;
+
+# if defined(SIOCGIFINDEX)
+      {
+        struct ifreq cur;
+        strcpy (cur.ifr_name, idx[index].if_name);
+        cur.ifr_index = -1;
+        if (ioctl (fd, SIOCGIFINDEX, &cur) >= 0)
+          idx[index].if_index = cur.ifr_index;
+      }
+# endif
+
+      if (idx[index].if_name == NULL)
+        {
+          int saved_errno = errno;
+          close (fd);
+          free (content);
+          errno = saved_errno;
+          return NULL;
+        }
+    }
+
+  idx[index].if_index = 0;
+  idx[index].if_name = NULL;
+
+  free (content);
+  return idx;
+}
+
+static struct system_functions linux_system_functions =
+   {
+     .if_nameindex = linux_if_nameindex
+   };
+
+struct system_functions *system_functions = &linux_system_functions;
diff --git a/ifconfig/system/linux.h b/ifconfig/system/linux.h
index 5b03581..45d9350 100644
--- a/ifconfig/system/linux.h
+++ b/ifconfig/system/linux.h
@@ -86,7 +86,7 @@ void system_fh_txqlen_query (format_data_t form, int argc, 
char *argv[]);
 void system_fh_txqlen (format_data_t form, int argc, char *argv[]);
 
 void system_fh_ifstat_query (format_data_t form, int argc, char *argv[]);
-                                   
+
 _IU_EXTRN (rx_packets)
 _IU_EXTRN (tx_packets)
 _IU_EXTRN (rx_bytes)
diff --git a/ifconfig/system/qnx.c b/ifconfig/system/qnx.c
index a2a3abd..62ea51a 100644
--- a/ifconfig/system/qnx.c
+++ b/ifconfig/system/qnx.c
@@ -65,3 +65,5 @@ system_configure (int sfd, struct ifreq *ifr, struct 
system_ifconfig *ifs)
 {
   return 0;
 }
+
+struct system_functions *system_functions = &generic_system_functions;
diff --git a/ifconfig/system/solaris.c b/ifconfig/system/solaris.c
index 2f5884f..af8601d 100644
--- a/ifconfig/system/solaris.c
+++ b/ifconfig/system/solaris.c
@@ -178,3 +178,5 @@ system_configure (int sfd, struct ifreq *ifr, struct 
system_ifconfig *ifs)
   return 0;
 #endif
 }
+
+struct system_functions *system_functions = &generic_system_functions;
-- 
1.7.1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]