Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
I talked to Giuseppe on IRC, and said that I liked the patch, but would prefer one where you don't need to redefine all elements of the SYSTEM_FUNCTIONS structure. Anyway, he'll push/post/whatever a new/old version soon. (Just FYI)
Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
Alfred M. Szmidt a...@gnu.org 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 gscriv...@gnu.org 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 gscriv...@gnu.org + + 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 gscriv...@gnu.org * 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 bug-inetutils@gnu.org. +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
Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
+2010-08-01 Giuseppe Scrivano gscriv...@gnu.org + +Under GNU/Linux ifconfig -a includes interfaces without an address Doesn't describe the change, should say something like: Don't show FOO under BAR when doing BAZ. +* bootstrap.conf (gnulib_modules): Add module `read-file'. + +* NEWS: Mention the new change. Please just say Updated. :-) +#define HAVE_SYSTEM_IF_NAMEINDEX 1 Can we detect this using configure?
Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
+#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?
Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
Giuseppe Scrivano gscriv...@gnu.org writes: It seems that SIOCGIFCONF, used by ifconfig, doesn't return all interfaces as we expect. What do you think about this patch? Any comment? Cheers, Giuseppe From 1f4f0273c5dbb14706055639e932554dce8d0353 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano gscriv...@gnu.org Date: Sun, 1 Aug 2010 14:52:28 +0200 Subject: [PATCH] Now ifconfig -a includes interfaces without an address * NEWS: Mention the change. * ifconfig/if_index.c (if_nameindex): Remove local variables `ifc', `i', `rq_len', `last_len', `ifr', `end', `cur'. Add local variables `content', `it', `length', `index'. Remove code that uses the SIOCGIFCONF ioctl to get the interfaces list. Parse the PATH_PROCNET_DEV file to fetch the list of interfaces. * bootstrap.conf (gnulib_modules): Add `read-file' module. --- ChangeLog | 14 + NEWS|8 +++ bootstrap.conf |1 + ifconfig/if_index.c | 138 +-- 4 files changed, 79 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 052daee..c5fcddd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,18 @@ +2010-08-01 Giuseppe Scrivano gscriv...@gnu.org + + * NEWS: Mention the change. + + * ifconfig/if_index.c (if_nameindex): Remove local variables + `ifc', `i', `rq_len', `last_len', `ifr', `end', `cur'. + Add local variables `content', `it', `length', `index'. + Remove code that uses the SIOCGIFCONF ioctl to get the interfaces + list. Parse the PATH_PROCNET_DEV file to fetch the list of + interfaces. + + * bootstrap.conf (gnulib_modules): Add `read-file' module. + 2010-07-30 Giuseppe Scrivano gscriv...@gnu.org + Suggested by Chris Webb ch...@arachsys.com * ifconfig/if_index.c (if_nameindex): Remove local variable `len'. Remove code that compute the sizeof of the struct `ifreq'. diff --git a/NEWS b/NEWS index 4583586..2dba114 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 bug-inetutils@gnu.org. +XXX YY, ZZ +Version A.B: + +* ifconfig + +ifconfig -a includes 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/if_index.c b/ifconfig/if_index.c index 3062bf7..3eafb3a 100644 --- a/ifconfig/if_index.c +++ b/ifconfig/if_index.c @@ -29,6 +29,8 @@ #include sys/types.h #include sys/socket.h +#include read-file.h + /* Solaris at least earlier 2.6 and before does not include the ioctl definitions if BSD_COMP is not set. */ #if defined(__svr4__) @@ -97,104 +99,76 @@ if_freenameindex (struct if_nameindex *ifn) struct if_nameindex * if_nameindex (void) { -#if defined(SIOCGIFCONF) - int fd = socket (AF_INET, SOCK_DGRAM, 0); - struct ifconf ifc; - unsigned int i = 0; - int rq_len, last_len; + char *content, *it; + size_t length, index; struct if_nameindex *idx = NULL; - struct ifreq *ifr, *end, *cur; + int fd; + fd = socket (AF_INET, SOCK_DGRAM, 0); if (fd 0) return NULL; - /* A first estimate. */ - rq_len = 4 * sizeof (struct ifreq); - - ifc.ifc_buf = NULL; - ifc.ifc_len = 0; - /* Read all the interfaces out of the kernel. */ - do -{ - last_len = ifc.ifc_len; - ifc.ifc_buf = alloca (ifc.ifc_len = rq_len); - if (ifc.ifc_buf == NULL || ioctl (fd, SIOCGIFCONF, ifc) 0) - { - close (fd); - return NULL; - } - rq_len *= 2; -} - while (ifc.ifc_len != last_len); - - i = 0; - ifr = (struct ifreq *) ifc.ifc_req; - end = (struct ifreq *) ((caddr_t) ifr + ifc.ifc_len); - while (ifr end) -{ - cur = ifr; - - ++ifr; + content = read_file (PATH_PROCNET_DEV, length); + if (content == NULL) +return NULL; - /* We ignore the other families .. OK ? */ - if (cur-ifr_addr.sa_family != AF_INET) - continue; + /* Count how many interfaces we have. */ + { +size_t n = 0; +it = content; +do + { +it = memchr (it + 1, ':', length - (it - content)); +n++; + } +while (it); - /* Make Room safely. */ +idx = malloc (n * sizeof (*idx)); +if (idx == NULL) { - struct if_nameindex *tidx = NULL; - tidx = realloc (idx, (i + 1) * sizeof (*idx)); - if (tidx == NULL) - { - if_freenameindex (idx); - close (fd); - errno = ENOBUFS; - return NULL; - } - idx = tidx; +int saved_errno = errno; +close (fd); +free (content); +errno = saved_errno; +return NULL; } + } - /* FIXME: We did not deal with duplicates or interface aliases. */ + for (it = memchr (content, ':',
Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
+2010-08-01 Giuseppe Scrivano gscriv...@gnu.org + +* NEWS: Mention the change. Just write Updated., all I can think is What change?... +* ifconfig/if_index.c (if_nameindex): Remove local variables +`ifc', `i', `rq_len', `last_len', `ifr', `end', `cur'. +Add local variables `content', `it', `length', `index'. +Remove code that uses the SIOCGIFCONF ioctl to get the interfaces +list. Parse the PATH_PROCNET_DEV file to fetch the list of +interfaces. What about systems without PATH_PROCNET_DEV?
Re: [bug-inetutils] ifconfig -a doesn't show all interfaces
Giuseppe Scrivano gscriv...@gnu.org ha escrit: What do you think about this patch? Any comment? This will certainly work on GNU/Linux. But how about other systems? Besides, this stuff being Linux-specific, it should go to ifconfig/system/linux.c. Regards, Sergey