Chris Webb <ch...@arachsys.com> writes: > I'm having trouble with the ifconfig shipped with GNU inetutils 1.8 on > x86-64 linux with glibc 2.11.1. Building and running it (either with or > without -a) only ever gives information for the loopback interface, although > running it in the form 'ifconfig eth0' will correctly give info for the eth0 > interface.
I've done some debugging on this. The code in if_nameindex() is a bit strange. I have no idea why it is doing something like ifr = (struct ifreq *) ((caddr_t) ifr + len + IFNAMSIZ); (which doesn't work) rather than ifr++ (which does). Perhaps some portability issue on another platform? I include a patch below to fix and tidy up this function, assuming this is just a relic. There remains a second bug with inetutils ifconfig on linux: ifconfig only displays active interfaces, whether or not -a is given. As far as I can see, SIOCGIFCONF is only returning active interfaces. I'll take a look at that next. -- 8< -- From: Chris Webb <ch...@arachsys.com> Date: Thu, 1 Jul 2010 10:50:32 +0100 Subject: [PATCH] Fix if_nameindex() in ifconfig on linux/x86-64 This makes ifconfig [-a] work correctly on 64-bit linux, and possibly other 64-bit platforms too. Signed-off-by: Chris Webb <ch...@arachsys.com> diff --git a/ifconfig/if_index.c b/ifconfig/if_index.c index 199904c..6b734be 100644 --- a/ifconfig/if_index.c +++ b/ifconfig/if_index.c @@ -132,22 +132,8 @@ if_nameindex (void) end = (struct ifreq *) ((caddr_t) ifr + ifc.ifc_len); while (ifr < end) { - int len; -# ifdef HAVE_STRUCT_SOCKADDR_SA_LEN -# undef MAX -# define MAX(a,b) (((a) > (b)) ? (a) : (b)) - len = MAX (sizeof (struct sockaddr), ifr->ifr_addr.sa_len); -# else - len = sizeof (struct sockaddr); -# endif - - cur = ifr; - - /* Step along the array by the size of the current structure */ - ifr = (struct ifreq *) ((caddr_t) ifr + len + IFNAMSIZ); - /* We ignore the other families .. OK ? */ - if (cur->ifr_addr.sa_family != AF_INET) + if (ifr->ifr_addr.sa_family != AF_INET) continue; /* Make Room safely. */ @@ -166,7 +152,7 @@ if_nameindex (void) /* FIXME: We did not deal with duplicates or interface aliases. */ - idx[i].if_name = strdup (cur->ifr_name); + idx[i].if_name = strdup (ifr->ifr_name); if (idx[i].if_name == NULL) { if_freenameindex (idx); @@ -176,12 +162,13 @@ if_nameindex (void) } # if defined(SIOCGIFINDEX) - if (ioctl (fd, SIOCGIFINDEX, cur) >= 0) - idx[i].if_index = cur->ifr_index; + if (ioctl (fd, SIOCGIFINDEX, ifr) >= 0) + idx[i].if_index = ifr->ifr_index; else # endif idx[i].if_index = i + 1; i++; + ifr++; } /* Terminate the array with an empty solt. */