Skip to contentSkip to conversation

inetutils: ifconfig -a includes interfaces without an address

meta-oe Chunrong Guo 4 participants 5 messages Nov 1, 2012 – Nov 2, 2012

lore
Share & tools
lore
#0 lore raw

*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.

---
 .../inetutils/inetutils-1.8/15.patch               |  197 +++++++++++++++
 .../inetutils/inetutils-1.8/add-module.patch       |   18 ++
 .../inetutils/inetutils-1.8/add-readfile.patch     |  250 ++++++++++++++++++++
 .../inetutils/inetutils_1.8.bb                     |    3 +
 4 files changed, 468 insertions(+), 0 deletions(-)
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.patch
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +197 -0
new file mode 100644
index 0000000..c2d4f11
@@ -0,0 +1,197 @@
+--- inetutils-1.8/ifconfig/if_index.c	2010-05-15 06:25:47.000000000 -0500
++++ ../inetutils-1.8-r0+fsl.1/inetutils-1.8/ifconfig/if_index.c	2012-10-30 04:03:19.595348659 -0500
+@@ -28,7 +28,7 @@
+ #include <unistd.h>
+ #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,24 +97,29 @@
+ 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;
+-  struct if_nameindex *idx = NULL;
+-  struct ifreq *ifr, *end, *cur;
++  //printk("if_nameindex\n");
+ 
++//#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);
++ // rq_len = 4 * sizeof (struct ifreq);
+ 
+-  ifc.ifc_buf = NULL;
+-  ifc.ifc_len = 0;
++//  ifc.ifc_buf = NULL;
++//  ifc.ifc_len = 0;
+   /* Read all the interfaces out of the kernel.  */
+-  do
++/*  do
+     {
+       last_len = ifc.ifc_len;
+       ifc.ifc_buf = alloca (ifc.ifc_len = rq_len);
+@@ -142,30 +147,59 @@
+ # endif
+ 
+       cur = ifr;
+-
+-      /* Step along the array by the size of the current structure */
+-      ifr = (struct ifreq *) ((caddr_t) ifr + len + IFNAMSIZ);
++*/
++      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);
++ 
++     /* 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)
+-	continue;
+-
++    //  if (cur->ifr_addr.sa_family != AF_INET)
++	//continue;
++   idx = malloc (n * sizeof(*idx));
++   if (idx == NULL)
+       /* Make Room safely.  */
+       {
+-	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;
++	//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, ':', length), index = 0; it;
++       it = memchr (it, ':', it - content), index++)
++    {
++      char *start = it - 1;
++      *it = '\0';
++
++      while (*start != ' ' && *start != '\n')
++        start--;
+ 
++/*
+       idx[i].if_name = strdup (cur->ifr_name);
+       if (idx[i].if_name == NULL)
+ 	{
+@@ -174,18 +208,38 @@
+ 	  errno = ENOBUFS;
+ 	  return NULL;
+ 	}
++*/
++      idx[index].if_name = strdup (start + 1);
++      idx[index].if_index = index + 1;
+ 
+ # if defined(SIOCGIFINDEX)
+-      if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
+-	idx[i].if_index = cur->ifr_index;
+-      else
++  //    if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
++//	idx[i].if_index = cur->ifr_index;
++ //     else
++    {
++        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
+-	idx[i].if_index = i + 1;
+-      i++;
++//	idx[i].if_index = i + 1;
++ //      i++;
++   if (idx[index].if_name == NULL)
++        {
++          int saved_errno = errno;
++          close (fd);
++          free (content);
++          errno = saved_errno;
++          return NULL;
++        }
++
+     }
+ 
+   /* Terminate the array with an empty solt.  */
+-  {
++/*  {
+     struct if_nameindex *tidx = NULL;
+     tidx = realloc (idx, (i + 1) * sizeof (*idx));
+     if (tidx == NULL)
+@@ -199,14 +253,19 @@
+   }
+   idx[i].if_index = 0;
+   idx[i].if_name = NULL;
+-
+-  close (fd);
++*/
++  idx[index].if_index = 0;
++  idx[index].if_name = NULL;
++ 
++ // close (fd);
++ free(content);
+   return idx;
+-
++/*
+ #else
+   errno = ENOSYS;
+   return NULL;
+ #endif
++*/
+ }
+ 
+ char *
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch new file +18 -0
new file mode 100644
index 0000000..7acc3a4
@@ -0,0 +1,18 @@
+--- inetutils-1.8/lib/gnulib.mk	2010-05-15 06:34:54.000000000 -0500
++++ inetutils-1.8/lib/gnulib.mk	2012-10-29 21:50:44.821671025 -0500
+@@ -111,6 +111,15 @@
+ 
+ ## end   gnulib module argp-version-etc
+ 
++
++## begin gnulib module read-file
++
++libgnu_a_SOURCES += read-file.c
++
++EXTRA_DIST += read-file.h
++
++## end   gnulib module read-file
++
+ ## begin gnulib module arpa_inet
+ 
+ BUILT_SOURCES += arpa/inet.h
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.patch new file +250 -0

250 lines not on this page · raw message

meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +3 -0
index 761b2e6..74a9875 100644
@@ -22,6 +22,9 @@ SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-${PV}.tar.gz \
            file://fix-disable-ipv6.patch \
            file://disable-pre-ANSI-compilers.patch \
            file://remove_gets.patch \
+           file://add-readfile.patch \
+           file://15.patch \
+           file://add-module.patch \
 " 
 SRC_URI[md5sum] = "ad8fdcdf1797b9ca258264a6b04e48fd"
 SRC_URI[sha256sum] = "c8500baee04b9ea408c9e65e24ad7f5b41e7d96d42fb1d29abf25b52b68311c7"
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 7 lines · [[oe] [meta-oe ] inetutils: ifconfig -a includes interfaces without an…

*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.

I'm still not understanding the objective of these changes. The above commit log says what you're doing, but I cannot tell why. Since the patch itself is leaving largeish chunks of code commented out and/or dead, removing previous ifdef's and using an inconsistent style, it's kind of caught my attention and I can't help asking why.

Particularly since the short log message seems to me that you're trying to change existing, documented and reasonably correct behaviour. What's actually broken here?

-J.

Quoted 507 lines
---
 .../inetutils/inetutils-1.8/15.patch               |  197 +++++++++++++++
 .../inetutils/inetutils-1.8/add-module.patch       |   18 ++
 .../inetutils/inetutils-1.8/add-readfile.patch     |  250 ++++++++++++++++++++
 .../inetutils/inetutils_1.8.bb                     |    3 +
 4 files changed, 468 insertions(+), 0 deletions(-)
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.patch
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +197 -0
new file mode 100644
index 0000000..c2d4f11
@@ -0,0 +1,197 @@
+--- inetutils-1.8/ifconfig/if_index.c	2010-05-15 06:25:47.000000000 -0500
++++ ../inetutils-1.8-r0+fsl.1/inetutils-1.8/ifconfig/if_index.c	2012-10-30 04:03:19.595348659 -0500
+@@ -28,7 +28,7 @@
+ #include <unistd.h>
+ #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,24 +97,29 @@
+ 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;
+-  struct if_nameindex *idx = NULL;
+-  struct ifreq *ifr, *end, *cur;
++  //printk("if_nameindex\n");
+ 
++//#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);
++ // rq_len = 4 * sizeof (struct ifreq);
+ 
+-  ifc.ifc_buf = NULL;
+-  ifc.ifc_len = 0;
++//  ifc.ifc_buf = NULL;
++//  ifc.ifc_len = 0;
+   /* Read all the interfaces out of the kernel.  */
+-  do
++/*  do
+     {
+       last_len = ifc.ifc_len;
+       ifc.ifc_buf = alloca (ifc.ifc_len = rq_len);
+@@ -142,30 +147,59 @@
+ # endif
+ 
+       cur = ifr;
+-
+-      /* Step along the array by the size of the current structure */
+-      ifr = (struct ifreq *) ((caddr_t) ifr + len + IFNAMSIZ);
++*/
++      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);
++ 
++     /* 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)
+-	continue;
+-
++    //  if (cur->ifr_addr.sa_family != AF_INET)
++	//continue;
++   idx = malloc (n * sizeof(*idx));
++   if (idx == NULL)
+       /* Make Room safely.  */
+       {
+-	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;
++	//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, ':', length), index = 0; it;
++       it = memchr (it, ':', it - content), index++)
++    {
++      char *start = it - 1;
++      *it = '\0';
++
++      while (*start != ' ' && *start != '\n')
++        start--;
+ 
++/*
+       idx[i].if_name = strdup (cur->ifr_name);
+       if (idx[i].if_name == NULL)
+ 	{
+@@ -174,18 +208,38 @@
+ 	  errno = ENOBUFS;
+ 	  return NULL;
+ 	}
++*/
++      idx[index].if_name = strdup (start + 1);
++      idx[index].if_index = index + 1;
+ 
+ # if defined(SIOCGIFINDEX)
+-      if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
+-	idx[i].if_index = cur->ifr_index;
+-      else
++  //    if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
++//	idx[i].if_index = cur->ifr_index;
++ //     else
++    {
++        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
+-	idx[i].if_index = i + 1;
+-      i++;
++//	idx[i].if_index = i + 1;
++ //      i++;
++   if (idx[index].if_name == NULL)
++        {
++          int saved_errno = errno;
++          close (fd);
++          free (content);
++          errno = saved_errno;
++          return NULL;
++        }
++
+     }
+ 
+   /* Terminate the array with an empty solt.  */
+-  {
++/*  {
+     struct if_nameindex *tidx = NULL;
+     tidx = realloc (idx, (i + 1) * sizeof (*idx));
+     if (tidx == NULL)
+@@ -199,14 +253,19 @@
+   }
+   idx[i].if_index = 0;
+   idx[i].if_name = NULL;
+-
+-  close (fd);
++*/
++  idx[index].if_index = 0;
++  idx[index].if_name = NULL;
++ 
++ // close (fd);
++ free(content);
+   return idx;
+-
++/*
+ #else
+   errno = ENOSYS;
+   return NULL;
+ #endif
++*/
+ }
+ 
+ char *
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch new file +18 -0
new file mode 100644
index 0000000..7acc3a4
@@ -0,0 +1,18 @@
+--- inetutils-1.8/lib/gnulib.mk	2010-05-15 06:34:54.000000000 -0500
++++ inetutils-1.8/lib/gnulib.mk	2012-10-29 21:50:44.821671025 -0500
+@@ -111,6 +111,15 @@
+ 
+ ## end   gnulib module argp-version-etc
+ 
++
++## begin gnulib module read-file
++
++libgnu_a_SOURCES += read-file.c
++
++EXTRA_DIST += read-file.h
++
++## end   gnulib module read-file
++
+ ## begin gnulib module arpa_inet
+ 
+ BUILT_SOURCES += arpa/inet.h
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.patch new file +250 -0
new file mode 100644
index 0000000..bb18ae9
@@ -0,0 +1,250 @@
+Signed-off-by: Chunrong Guo <[email protected]>
+---
+ inetutils-1.8/lib/read-file.c |  191 +++++++++++++++++++++++++++++++++++++++++
+ inetutils-1.8/lib/read-file.h |   36 ++++++++
+ 2 files changed, 227 insertions(+)
+ create mode 100644 inetutils-1.8/lib/read-file.c
+ create mode 100644 inetutils-1.8/lib/read-file.h
+
+diff --git a/lib/read-file.c b/lib/read-file.c
+new file mode 100644
+index 0000000..ba7aef3
+--- /dev/null
++++ b/lib/read-file.c
+@@ -0,0 +1,191 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.c -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson and Bruno Haible.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3, or (at your option)
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software Foundation,
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
++
++#include <config.h>
++
++#include "read-file.h"
++
++/* Get fstat.  */
++#include <sys/stat.h>
++
++/* Get ftello.  */
++#include <stdio.h>
++
++/* Get SIZE_MAX.  */
++#include <stdint.h>
++
++/* Get malloc, realloc, free. */
++#include <stdlib.h>
++
++/* Get errno. */
++#include <errno.h>
++
++/* Read a STREAM and return a newly allocated string with the content,
++   and set *LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   *LENGTH.  On errors, *LENGTH is undefined, errno preserves the
++   values set by system functions (if any), and NULL is returned.  */
++char *
++fread_file (FILE *stream, size_t *length)
++{
++  char *buf = NULL;
++  size_t alloc = BUFSIZ;
++
++  /* For a regular file, allocate a buffer that has exactly the right
++     size.  This avoids the need to do dynamic reallocations later.  */
++  {
++    struct stat st;
++
++    if (fstat (fileno (stream), &st) >= 0 && S_ISREG (st.st_mode))
++      {
++        off_t pos = ftello (stream);
++
++        if (pos >= 0 && pos < st.st_size)
++          {
++            off_t alloc_off = st.st_size - pos;
++
++            /* '1' below, accounts for the trailing NUL.  */
++            if (SIZE_MAX - 1 < alloc_off)
++              {
++                errno = ENOMEM;
++                return NULL;
++              }
++
++            alloc = alloc_off + 1;
++          }
++      }
++  }
++
++  if (!(buf = malloc (alloc)))
++    return NULL; /* errno is ENOMEM.  */
++
++  {
++    size_t size = 0; /* number of bytes read so far */
++    int save_errno;
++
++    for (;;)
++      {
++        /* This reads 1 more than the size of a regular file
++           so that we get eof immediately.  */
++        size_t requested = alloc - size;
++        size_t count = fread (buf + size, 1, requested, stream);
++        size += count;
++
++        if (count != requested)
++          {
++            save_errno = errno;
++            if (ferror (stream))
++              break;
++
++            /* Shrink the allocated memory if possible.  */
++            if (size < alloc - 1)
++              {
++                char *smaller_buf = realloc (buf, size + 1);
++                if (smaller_buf != NULL)
++                  buf = smaller_buf;
++              }
++
++            buf[size] = '\0';
++            *length = size;
++            return buf;
++          }
++
++        {
++          char *new_buf;
++
++          if (alloc == SIZE_MAX)
++            {
++              save_errno = ENOMEM;
++              break;
++            }
++
++          if (alloc < SIZE_MAX - alloc / 2)
++            alloc = alloc + alloc / 2;
++          else
++            alloc = SIZE_MAX;
++
++          if (!(new_buf = realloc (buf, alloc)))
++            {
++              save_errno = errno;
++              break;
++            }
++
++          buf = new_buf;
++        }
++      }
++
++    free (buf);
++    errno = save_errno;
++    return NULL;
++  }
++}
++
++static char *
++internal_read_file (const char *filename, size_t *length, const char *mode)
++{
++  FILE *stream = fopen (filename, mode);
++  char *out;
++  int save_errno;
++
++  if (!stream)
++    return NULL;
++
++  out = fread_file (stream, length);
++
++  save_errno = errno;
++
++  if (fclose (stream) != 0)
++    {
++      if (out)
++        {
++          save_errno = errno;
++          free (out);
++        }
++      errno = save_errno;
++      return NULL;
++    }
++
++  return out;
++}
++
++/* Open and read the contents of FILENAME, and return a newly
++   allocated string with the content, and set *LENGTH to the length of
++   the string.  The string is zero-terminated, but the terminating
++   zero byte is not counted in *LENGTH.  On errors, *LENGTH is
++   undefined, errno preserves the values set by system functions (if
++   any), and NULL is returned.  */
++char *
++read_file (const char *filename, size_t *length)
++{
++  return internal_read_file (filename, length, "r");
++}
++
++/* Open (on non-POSIX systems, in binary mode) and read the contents
++   of FILENAME, and return a newly allocated string with the content,
++   and set LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   the LENGTH variable.  On errors, *LENGTH is undefined, errno
++   preserves the values set by system functions (if any), and NULL is
++   returned.  */
++char *
++read_binary_file (const char *filename, size_t *length)
++{
++  return internal_read_file (filename, length, "rb");
++}
+
+diff --git a/lib/read-file.h b/lib/read-file.h
+index 0000000..14041dc
+--- /dev/null
++++ b/lib/read-file.h
+@@ -0,0 +1,36 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.h -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3, or (at your option)
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software Foundation,
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
++
++#ifndef READ_FILE_H
++#define READ_FILE_H
++
++/* Get size_t.  */
++#include <stddef.h>
++
++/* Get FILE.  */
++#include <stdio.h>
++
++extern char *fread_file (FILE * stream, size_t * length);
++
++extern char *read_file (const char *filename, size_t * length);
++
++extern char *read_binary_file (const char *filename, size_t * length);
++
++#endif /* READ_FILE_H */
+-- 
+1.7.9.7
+
meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +3 -0
index 761b2e6..74a9875 100644
@@ -22,6 +22,9 @@ SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-${PV}.tar.gz \
            file://fix-disable-ipv6.patch \
            file://disable-pre-ANSI-compilers.patch \
            file://remove_gets.patch \
+           file://add-readfile.patch \
+           file://15.patch \
+           file://add-module.patch \
 " 
 SRC_URI[md5sum] = "ad8fdcdf1797b9ca258264a6b04e48fd"
 SRC_URI[sha256sum] = "c8500baee04b9ea408c9e65e24ad7f5b41e7d96d42fb1d29abf25b52b68311c7"
Signature · 2 lines
Joe MacDonald, Sr. Member of Technical Staff, Linux Products Group, Wind River
direct 613.270.5750     mobile 613.291.7421     fax 613.592.2283
#2 lore raw
Quoted 16 lines · Joe MacDonald
Quoted 7 lines · [[oe] [meta-oe ] inetutils: ifconfig -a includes interfaces without an…

*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.

I'm still not understanding the objective of these changes. The above commit log says what you're doing, but I cannot tell why. Since the patch itself is leaving largeish chunks of code commented out and/or dead, removing previous ifdef's and using an inconsistent style, it's kind of caught my attention and I can't help asking why.

Quoted 3 lines

Particularly since the short log message seems to me that you're trying to change existing, documented and reasonably correct behaviour. What's actually broken here?

Chunrong,

I'm having a hard time parsing this as well... is this fixing the issue with ifconfig were we are not seeing all the ethernet interfaces?

-M

Quoted 513 lines

-J.

Quoted 498 lines
---
 .../inetutils/inetutils-1.8/15.patch               |  197 +++++++++++++++
 .../inetutils/inetutils-1.8/add-module.patch       |   18 ++
 .../inetutils/inetutils-1.8/add-readfile.patch     |  250 ++++++++++++++++++++
 .../inetutils/inetutils_1.8.bb                     |    3 +
 4 files changed, 468 insertions(+), 0 deletions(-)
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch
 create mode 100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.patch
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +197 -0
new file mode 100644
index 0000000..c2d4f11
@@ -0,0 +1,197 @@
+--- inetutils-1.8/ifconfig/if_index.c        2010-05-15 06:25:47.000000000 -0500
++++ ../inetutils-1.8-r0+fsl.1/inetutils-1.8/ifconfig/if_index.c      2012-10-30 04:03:19.595348659 -0500
+@@ -28,7 +28,7 @@
+ #include <unistd.h>
+ #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,24 +97,29 @@
+ 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;
+-  struct if_nameindex *idx = NULL;
+-  struct ifreq *ifr, *end, *cur;
++  //printk("if_nameindex\n");
+
++//#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);
++ // rq_len = 4 * sizeof (struct ifreq);
+
+-  ifc.ifc_buf = NULL;
+-  ifc.ifc_len = 0;
++//  ifc.ifc_buf = NULL;
++//  ifc.ifc_len = 0;
+   /* Read all the interfaces out of the kernel.  */
+-  do
++/*  do
+     {
+       last_len = ifc.ifc_len;
+       ifc.ifc_buf = alloca (ifc.ifc_len = rq_len);
+@@ -142,30 +147,59 @@
+ # endif
+
+       cur = ifr;
+-
+-      /* Step along the array by the size of the current structure */
+-      ifr = (struct ifreq *) ((caddr_t) ifr + len + IFNAMSIZ);
++*/
++      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);
++
++     /* 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)
+-    continue;
+-
++    //  if (cur->ifr_addr.sa_family != AF_INET)
++    //continue;
++   idx = malloc (n * sizeof(*idx));
++   if (idx == NULL)
+       /* Make Room safely.  */
+       {
+-    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;
++    //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, ':', length), index = 0; it;
++       it = memchr (it, ':', it - content), index++)
++    {
++      char *start = it - 1;
++      *it = '\0';
++
++      while (*start != ' ' && *start != '\n')
++        start--;
+
++/*
+       idx[i].if_name = strdup (cur->ifr_name);
+       if (idx[i].if_name == NULL)
+     {
+@@ -174,18 +208,38 @@
+       errno = ENOBUFS;
+       return NULL;
+     }
++*/
++      idx[index].if_name = strdup (start + 1);
++      idx[index].if_index = index + 1;
+
+ # if defined(SIOCGIFINDEX)
+-      if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
+-    idx[i].if_index = cur->ifr_index;
+-      else
++  //    if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
++//  idx[i].if_index = cur->ifr_index;
++ //     else
++    {
++        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
+-    idx[i].if_index = i + 1;
+-      i++;
++//  idx[i].if_index = i + 1;
++ //      i++;
++   if (idx[index].if_name == NULL)
++        {
++          int saved_errno = errno;
++          close (fd);
++          free (content);
++          errno = saved_errno;
++          return NULL;
++        }
++
+     }
+
+   /* Terminate the array with an empty solt.  */
+-  {
++/*  {
+     struct if_nameindex *tidx = NULL;
+     tidx = realloc (idx, (i + 1) * sizeof (*idx));
+     if (tidx == NULL)
+@@ -199,14 +253,19 @@
+   }
+   idx[i].if_index = 0;
+   idx[i].if_name = NULL;
+-
+-  close (fd);
++*/
++  idx[index].if_index = 0;
++  idx[index].if_name = NULL;
++
++ // close (fd);
++ free(content);
+   return idx;
+-
++/*
+ #else
+   errno = ENOSYS;
+   return NULL;
+ #endif
++*/
+ }
+
+ char *
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch new file +18 -0
new file mode 100644
index 0000000..7acc3a4
@@ -0,0 +1,18 @@
+--- inetutils-1.8/lib/gnulib.mk      2010-05-15 06:34:54.000000000 -0500
++++ inetutils-1.8/lib/gnulib.mk      2012-10-29 21:50:44.821671025 -0500
+@@ -111,6 +111,15 @@
+
+ ## end   gnulib module argp-version-etc
+
++
++## begin gnulib module read-file
++
++libgnu_a_SOURCES += read-file.c
++
++EXTRA_DIST += read-file.h
++
++## end   gnulib module read-file
++
+ ## begin gnulib module arpa_inet
+
+ BUILT_SOURCES += arpa/inet.h
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.patch new file +250 -0
new file mode 100644
index 0000000..bb18ae9
@@ -0,0 +1,250 @@
+Signed-off-by: Chunrong Guo <[email protected]>
+---
+ inetutils-1.8/lib/read-file.c |  191 +++++++++++++++++++++++++++++++++++++++++
+ inetutils-1.8/lib/read-file.h |   36 ++++++++
+ 2 files changed, 227 insertions(+)
+ create mode 100644 inetutils-1.8/lib/read-file.c
+ create mode 100644 inetutils-1.8/lib/read-file.h
+
+diff --git a/lib/read-file.c b/lib/read-file.c
+new file mode 100644
+index 0000000..ba7aef3
+--- /dev/null
++++ b/lib/read-file.c
+@@ -0,0 +1,191 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.c -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson and Bruno Haible.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3, or (at your option)
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software Foundation,
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
++
++#include <config.h>
++
++#include "read-file.h"
++
++/* Get fstat.  */
++#include <sys/stat.h>
++
++/* Get ftello.  */
++#include <stdio.h>
++
++/* Get SIZE_MAX.  */
++#include <stdint.h>
++
++/* Get malloc, realloc, free. */
++#include <stdlib.h>
++
++/* Get errno. */
++#include <errno.h>
++
++/* Read a STREAM and return a newly allocated string with the content,
++   and set *LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   *LENGTH.  On errors, *LENGTH is undefined, errno preserves the
++   values set by system functions (if any), and NULL is returned.  */
++char *
++fread_file (FILE *stream, size_t *length)
++{
++  char *buf = NULL;
++  size_t alloc = BUFSIZ;
++
++  /* For a regular file, allocate a buffer that has exactly the right
++     size.  This avoids the need to do dynamic reallocations later.  */
++  {
++    struct stat st;
++
++    if (fstat (fileno (stream), &st) >= 0 && S_ISREG (st.st_mode))
++      {
++        off_t pos = ftello (stream);
++
++        if (pos >= 0 && pos < st.st_size)
++          {
++            off_t alloc_off = st.st_size - pos;
++
++            /* '1' below, accounts for the trailing NUL.  */
++            if (SIZE_MAX - 1 < alloc_off)
++              {
++                errno = ENOMEM;
++                return NULL;
++              }
++
++            alloc = alloc_off + 1;
++          }
++      }
++  }
++
++  if (!(buf = malloc (alloc)))
++    return NULL; /* errno is ENOMEM.  */
++
++  {
++    size_t size = 0; /* number of bytes read so far */
++    int save_errno;
++
++    for (;;)
++      {
++        /* This reads 1 more than the size of a regular file
++           so that we get eof immediately.  */
++        size_t requested = alloc - size;
++        size_t count = fread (buf + size, 1, requested, stream);
++        size += count;
++
++        if (count != requested)
++          {
++            save_errno = errno;
++            if (ferror (stream))
++              break;
++
++            /* Shrink the allocated memory if possible.  */
++            if (size < alloc - 1)
++              {
++                char *smaller_buf = realloc (buf, size + 1);
++                if (smaller_buf != NULL)
++                  buf = smaller_buf;
++              }
++
++            buf[size] = '\0';
++            *length = size;
++            return buf;
++          }
++
++        {
++          char *new_buf;
++
++          if (alloc == SIZE_MAX)
++            {
++              save_errno = ENOMEM;
++              break;
++            }
++
++          if (alloc < SIZE_MAX - alloc / 2)
++            alloc = alloc + alloc / 2;
++          else
++            alloc = SIZE_MAX;
++
++          if (!(new_buf = realloc (buf, alloc)))
++            {
++              save_errno = errno;
++              break;
++            }
++
++          buf = new_buf;
++        }
++      }
++
++    free (buf);
++    errno = save_errno;
++    return NULL;
++  }
++}
++
++static char *
++internal_read_file (const char *filename, size_t *length, const char *mode)
++{
++  FILE *stream = fopen (filename, mode);
++  char *out;
++  int save_errno;
++
++  if (!stream)
++    return NULL;
++
++  out = fread_file (stream, length);
++
++  save_errno = errno;
++
++  if (fclose (stream) != 0)
++    {
++      if (out)
++        {
++          save_errno = errno;
++          free (out);
++        }
++      errno = save_errno;
++      return NULL;
++    }
++
++  return out;
++}
++
++/* Open and read the contents of FILENAME, and return a newly
++   allocated string with the content, and set *LENGTH to the length of
++   the string.  The string is zero-terminated, but the terminating
++   zero byte is not counted in *LENGTH.  On errors, *LENGTH is
++   undefined, errno preserves the values set by system functions (if
++   any), and NULL is returned.  */
++char *
++read_file (const char *filename, size_t *length)
++{
++  return internal_read_file (filename, length, "r");
++}
++
++/* Open (on non-POSIX systems, in binary mode) and read the contents
++   of FILENAME, and return a newly allocated string with the content,
++   and set LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   the LENGTH variable.  On errors, *LENGTH is undefined, errno
++   preserves the values set by system functions (if any), and NULL is
++   returned.  */
++char *
++read_binary_file (const char *filename, size_t *length)
++{
++  return internal_read_file (filename, length, "rb");
++}
+
+diff --git a/lib/read-file.h b/lib/read-file.h
+index 0000000..14041dc
+--- /dev/null
++++ b/lib/read-file.h
+@@ -0,0 +1,36 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.h -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson.
++
++   This program is free software; you can redistribute it and/or modify
++   it under the terms of the GNU General Public License as published by
++   the Free Software Foundation; either version 3, or (at your option)
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software Foundation,
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
++
++#ifndef READ_FILE_H
++#define READ_FILE_H
++
++/* Get size_t.  */
++#include <stddef.h>
++
++/* Get FILE.  */
++#include <stdio.h>
++
++extern char *fread_file (FILE * stream, size_t * length);
++
++extern char *read_file (const char *filename, size_t * length);
++
++extern char *read_binary_file (const char *filename, size_t * length);
++
++#endif /* READ_FILE_H */
+--
+1.7.9.7
+
meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +0 -0
index 761b2e6..74a9875 100644

meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-${PV}.tar.gz \ · line 30

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +3 -0
@@ -22,6 +22,9 @@ SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-${PV}.tar.gz \
            file://fix-disable-ipv6.patch \
            file://disable-pre-ANSI-compilers.patch \
            file://remove_gets.patch \
+           file://add-readfile.patch \
+           file://15.patch \
+           file://add-module.patch \
 "
 SRC_URI[md5sum] = "ad8fdcdf1797b9ca258264a6b04e48fd"
 SRC_URI[sha256sum] = "c8500baee04b9ea408c9e65e24ad7f5b41e7d96d42fb1d29abf25b52b68311c7"

--
Joe MacDonald, Sr. Member of Technical Staff, Linux Products Group, Wind River
direct 613.270.5750 mobile 613.291.7421 fax 613.592.2283

#3 lore raw

The patch fixes "inetutils.ifconfig -a" doesn't show all interfaces.

More story is in http://www.mail-archive.com/[email protected]/msg01745.html

Best Regards,

Zhenhua

Quoted 582 lines

-----Original Message-----
From: McClintock Matthew-B29882
Sent: Thursday, November 01, 2012 11:19 PM
To: Joe MacDonald
Cc: [email protected]; McClintock Matthew-B29882; Luo Zhenhua-B19537
Subject: Re: [oe] [meta-oe ] inetutils: ifconfig -a includes interfaces without an address

Quoted 1 line · Joe MacDonald

[[oe] [meta-oe ] inetutils: ifconfig -a includes interfaces without an

Quoted 5 lines · address] On 12.11.01 (Thu 17:59) Chunrong Guo wrote:
Quoted 5 lines

*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

Quoted 10 lines
Quoted 3 lines

list. Parse the PATH_PROCNET_DEV file to fetch the list of interfaces.

I'm still not understanding the objective of these changes. The above commit log says what you're doing, but I cannot tell why. Since the patch itself is leaving largeish chunks of code commented out and/or dead, removing previous ifdef's and using an inconsistent style, it's kind of caught my attention and I can't help asking why.

Quoted 3 lines

Particularly since the short log message seems to me that you're trying to change existing, documented and reasonably correct behaviour. What's actually broken here?

Chunrong,

I'm having a hard time parsing this as well... is this fixing the issue with ifconfig were we are not seeing all the ethernet interfaces?

-M

Quoted 5 lines

-J.

Quoted 2 lines
---
 .../inetutils/inetutils-1.8/15.patch               |  197

+++++++++++++++

Quoted 2 lines
Quoted 2 lines
 .../inetutils/inetutils-1.8/add-module.patch       |   18 ++
 .../inetutils/inetutils-1.8/add-readfile.patch     |  250

++++++++++++++++++++

Quoted 9 lines
Quoted 9 lines
 .../inetutils/inetutils_1.8.bb                     |    3 +
 4 files changed, 468 insertions(+), 0 deletions(-)  create mode
100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch
 create mode 100644
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch
 create mode 100644

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.pat ch

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch line 1

Quoted 9 lines

diff --git a/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch b/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file mode 100644
index 0000000..c2d4f11

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +1 -0
@@ -0,0 +1,197 @@
+--- inetutils-1.8/ifconfig/if_index.c        2010-05-15

06:25:47.000000000 -0500

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch line 2

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +1 -0
++++ ../inetutils-1.8-r0+fsl.1/inetutils-1.8/ifconfig/if_index.c
2012-10-30 04:03:19.595348659 -0500
Quoted 41 lines
Quoted 41 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +41 -0
+@@ -28,7 +28,7 @@
+ #include <unistd.h>
+ #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,24 +97,29 @@  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;
+-  struct if_nameindex *idx = NULL;
+-  struct ifreq *ifr, *end, *cur;
++  //printk("if_nameindex\n");
+
++//#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);
++ // rq_len = 4 * sizeof (struct ifreq);
+
+-  ifc.ifc_buf = NULL;
+-  ifc.ifc_len = 0;
++//  ifc.ifc_buf = NULL;
++//  ifc.ifc_len = 0;
+   /* Read all the interfaces out of the kernel.  */
+-  do
++/*  do
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +8 -0
+     {
+       last_len = ifc.ifc_len;
+       ifc.ifc_buf = alloca (ifc.ifc_len = rq_len); @@ -142,30
++147,59 @@  # endif
+
+       cur = ifr;
+-
+-      /* Step along the array by the size of the current structure

*/

Quoted 144 lines
Quoted 144 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +140 -0
+-      ifr = (struct ifreq *) ((caddr_t) ifr + len + IFNAMSIZ);
++*/
++      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);
++
++     /* 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)
+-    continue;
+-
++    //  if (cur->ifr_addr.sa_family != AF_INET)
++    //continue;
++   idx = malloc (n * sizeof(*idx));
++   if (idx == NULL)
+       /* Make Room safely.  */
+       {
+-    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;
++    //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, ':', length), index = 0; it;
++       it = memchr (it, ':', it - content), index++)
++    {
++      char *start = it - 1;
++      *it = '\0';
++
++      while (*start != ' ' && *start != '\n')
++        start--;
+
++/*
+       idx[i].if_name = strdup (cur->ifr_name);
+       if (idx[i].if_name == NULL)
+     {
+@@ -174,18 +208,38 @@
+       errno = ENOBUFS;
+       return NULL;
+     }
++*/
++      idx[index].if_name = strdup (start + 1);
++      idx[index].if_index = index + 1;
+
+ # if defined(SIOCGIFINDEX)
+-      if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
+-    idx[i].if_index = cur->ifr_index;
+-      else
++  //    if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
++//  idx[i].if_index = cur->ifr_index;
++ //     else
++    {
++        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
+-    idx[i].if_index = i + 1;
+-      i++;
++//  idx[i].if_index = i + 1;
++ //      i++;
++   if (idx[index].if_name == NULL)
++        {
++          int saved_errno = errno;
++          close (fd);
++          free (content);
++          errno = saved_errno;
++          return NULL;
++        }
++
+     }
+
+   /* Terminate the array with an empty solt.  */
+-  {
++/*  {
+     struct if_nameindex *tidx = NULL;
+     tidx = realloc (idx, (i + 1) * sizeof (*idx));
+     if (tidx == NULL)
+@@ -199,14 +253,19 @@
+   }
+   idx[i].if_index = 0;
+   idx[i].if_name = NULL;
+-
+-  close (fd);
++*/
++  idx[index].if_index = 0;
++  idx[index].if_name = NULL;
++
++ // close (fd);
++ free(content);
+   return idx;
+-
++/*
+ #else
+   errno = ENOSYS;
+   return NULL;
+ #endif
++*/
+ }
+
+ char *

diff --git a/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.pat ch b/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.pat

Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module line 1

Quoted 8 lines

ch
new file mode 100644
index 0000000..7acc3a4

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module new file +2 -0
+++ .patch
@@ -0,0 +1,18 @@
+--- inetutils-1.8/lib/gnulib.mk      2010-05-15 06:34:54.000000000 -

0500

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module line 2

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module new file +1 -0
++++ inetutils-1.8/lib/gnulib.mk      2012-10-29 21:50:44.821671025 -

0500

Quoted 22 lines
Quoted 22 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module new file +16 -0
+@@ -111,6 +111,15 @@
+
+ ## end   gnulib module argp-version-etc
+
++
++## begin gnulib module read-file
++
++libgnu_a_SOURCES += read-file.c
++
++EXTRA_DIST += read-file.h
++
++## end   gnulib module read-file
++
+ ## begin gnulib module arpa_inet
+
+ BUILT_SOURCES += arpa/inet.h

diff --git a/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.p atch b/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.p atch
new file mode 100644

Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 3

Quoted 8 lines

index 0000000..bb18ae9

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +4 -0
+++ le.patch
@@ -0,0 +1,250 @@
+Signed-off-by: Chunrong Guo <[email protected]>
+---
+ inetutils-1.8/lib/read-file.c |  191

+++++++++++++++++++++++++++++++++++++++++

Quoted 9 lines
Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
+ inetutils-1.8/lib/read-file.h |   36 ++++++++
+ 2 files changed, 227 insertions(+)
+ create mode 100644 inetutils-1.8/lib/read-file.c  create mode
+100644 inetutils-1.8/lib/read-file.h
+
+diff --git a/lib/read-file.c b/lib/read-file.c new file mode 100644
+index 0000000..ba7aef3
+--- /dev/null
++++ b/lib/read-file.c
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 20

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
+@@ -0,0 +1,191 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.c -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson and Bruno Haible.
++
++   This program is free software; you can redistribute it and/or

modify

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 21

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   it under the terms of the GNU General Public License as published

by

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 22

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   the Free Software Foundation; either version 3, or (at your

option)

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 31

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software

Foundation,

Quoted 15 lines
Quoted 15 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +15 -0
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
++ USA.  */
++
++#include <config.h>
++
++#include "read-file.h"
++
++/* Get fstat.  */
++#include <sys/stat.h>
++
++/* Get ftello.  */
++#include <stdio.h>
++
++/* Get SIZE_MAX.  */
++#include <stdint.h>
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 54

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
++
++/* Get malloc, realloc, free. */
++#include <stdlib.h>
++
++/* Get errno. */
++#include <errno.h>
++
++/* Read a STREAM and return a newly allocated string with the

content,

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 63

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   and set *LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   *LENGTH.  On errors, *LENGTH is undefined, errno preserves the
++   values set by system functions (if any), and NULL is returned.
++*/ char * fread_file (FILE *stream, size_t *length) {
++  char *buf = NULL;
++  size_t alloc = BUFSIZ;
++
++  /* For a regular file, allocate a buffer that has exactly the

right

Quoted 110 lines
Quoted 110 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +110 -0
++     size.  This avoids the need to do dynamic reallocations later.
++ */  {
++    struct stat st;
++
++    if (fstat (fileno (stream), &st) >= 0 && S_ISREG (st.st_mode))
++      {
++        off_t pos = ftello (stream);
++
++        if (pos >= 0 && pos < st.st_size)
++          {
++            off_t alloc_off = st.st_size - pos;
++
++            /* '1' below, accounts for the trailing NUL.  */
++            if (SIZE_MAX - 1 < alloc_off)
++              {
++                errno = ENOMEM;
++                return NULL;
++              }
++
++            alloc = alloc_off + 1;
++          }
++      }
++  }
++
++  if (!(buf = malloc (alloc)))
++    return NULL; /* errno is ENOMEM.  */
++
++  {
++    size_t size = 0; /* number of bytes read so far */
++    int save_errno;
++
++    for (;;)
++      {
++        /* This reads 1 more than the size of a regular file
++           so that we get eof immediately.  */
++        size_t requested = alloc - size;
++        size_t count = fread (buf + size, 1, requested, stream);
++        size += count;
++
++        if (count != requested)
++          {
++            save_errno = errno;
++            if (ferror (stream))
++              break;
++
++            /* Shrink the allocated memory if possible.  */
++            if (size < alloc - 1)
++              {
++                char *smaller_buf = realloc (buf, size + 1);
++                if (smaller_buf != NULL)
++                  buf = smaller_buf;
++              }
++
++            buf[size] = '\0';
++            *length = size;
++            return buf;
++          }
++
++        {
++          char *new_buf;
++
++          if (alloc == SIZE_MAX)
++            {
++              save_errno = ENOMEM;
++              break;
++            }
++
++          if (alloc < SIZE_MAX - alloc / 2)
++            alloc = alloc + alloc / 2;
++          else
++            alloc = SIZE_MAX;
++
++          if (!(new_buf = realloc (buf, alloc)))
++            {
++              save_errno = errno;
++              break;
++            }
++
++          buf = new_buf;
++        }
++      }
++
++    free (buf);
++    errno = save_errno;
++    return NULL;
++  }
++}
++
++static char *
++internal_read_file (const char *filename, size_t *length, const
++char *mode) {
++  FILE *stream = fopen (filename, mode);
++  char *out;
++  int save_errno;
++
++  if (!stream)
++    return NULL;
++
++  out = fread_file (stream, length);
++
++  save_errno = errno;
++
++  if (fclose (stream) != 0)
++    {
++      if (out)
++        {
++          save_errno = errno;
++          free (out);
++        }
++      errno = save_errno;
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 181

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
++      return NULL;
++    }
++
++  return out;
++}
++
++/* Open and read the contents of FILENAME, and return a newly
++   allocated string with the content, and set *LENGTH to the length

of

Quoted 6 lines
Quoted 6 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +6 -0
++   the string.  The string is zero-terminated, but the terminating
++   zero byte is not counted in *LENGTH.  On errors, *LENGTH is
++   undefined, errno preserves the values set by system functions (if
++   any), and NULL is returned.  */
++char *
++read_file (const char *filename, size_t *length) {
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 195

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
++  return internal_read_file (filename, length, "r"); }
++
++/* Open (on non-POSIX systems, in binary mode) and read the contents
++   of FILENAME, and return a newly allocated string with the content,
++   and set LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   the LENGTH variable.  On errors, *LENGTH is undefined, errno
++   preserves the values set by system functions (if any), and NULL

is

Quoted 9 lines
Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   returned.  */
++char *
++read_binary_file (const char *filename, size_t *length) {
++  return internal_read_file (filename, length, "rb"); }
+
+diff --git a/lib/read-file.h b/lib/read-file.h index
+0000000..14041dc
+--- /dev/null
++++ b/lib/read-file.h
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 212

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
+@@ -0,0 +1,36 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.h -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson.
++
++   This program is free software; you can redistribute it and/or

modify

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 213

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   it under the terms of the GNU General Public License as published

by

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 214

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   the Free Software Foundation; either version 3, or (at your

option)

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 223

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software

Foundation,

Quoted 21 lines
Quoted 21 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +21 -0
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
++ USA.  */
++
++#ifndef READ_FILE_H
++#define READ_FILE_H
++
++/* Get size_t.  */
++#include <stddef.h>
++
++/* Get FILE.  */
++#include <stdio.h>
++
++extern char *fread_file (FILE * stream, size_t * length);
++
++extern char *read_file (const char *filename, size_t * length);
++
++extern char *read_binary_file (const char *filename, size_t *
++length);
++
++#endif /* READ_FILE_H */
+--
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +2 -0
+1.7.9.7
+
meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +0 -0
index 761b2e6..74a9875 100644
@@ -22,6 +22,9 @@ SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-

${PV}.tar.gz \

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-${PV}.tar.gz \

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +3 -0
            file://fix-disable-ipv6.patch \
            file://disable-pre-ANSI-compilers.patch \
            file://remove_gets.patch \
+           file://add-readfile.patch \
+           file://15.patch \
+           file://add-module.patch \
 "
 SRC_URI[md5sum] = "ad8fdcdf1797b9ca258264a6b04e48fd"
 SRC_URI[sha256sum] =

"c8500baee04b9ea408c9e65e24ad7f5b41e7d96d42fb1d29abf25b52b68311c7"

Quoted 2 lines

--
Joe MacDonald, Sr. Member of Technical Staff, Linux Products Group,

Wind River

Quoted 1 line

direct 613.270.5750 mobile 613.291.7421 fax 613.592.2283

#4 lore raw
Quoted 3 lines · On Thu, Nov 1, 2012 at 9:14 PM, Luo Zhenhua-B19537 <[email protected]> wrote:

The patch fixes "inetutils.ifconfig -a" doesn't show all interfaces.

More story is in http://www.mail-archive.com/[email protected]/msg01745.html

This info should be in the commit message. It provides much needed context for others to review and ultimately accept this patch.

-M

Quoted 588 lines

Best Regards,

Zhenhua

Quoted 582 lines

-----Original Message-----
From: McClintock Matthew-B29882
Sent: Thursday, November 01, 2012 11:19 PM
To: Joe MacDonald
Cc: [email protected]; McClintock Matthew-B29882; Luo Zhenhua-B19537
Subject: Re: [oe] [meta-oe ] inetutils: ifconfig -a includes interfaces without an address

Quoted 1 line · Joe MacDonald

[[oe] [meta-oe ] inetutils: ifconfig -a includes interfaces without an

Quoted 5 lines · address] On 12.11.01 (Thu 17:59) Chunrong Guo wrote:
Quoted 5 lines

*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

Quoted 10 lines
Quoted 3 lines

list. Parse the PATH_PROCNET_DEV file to fetch the list of interfaces.

I'm still not understanding the objective of these changes. The above commit log says what you're doing, but I cannot tell why. Since the patch itself is leaving largeish chunks of code commented out and/or dead, removing previous ifdef's and using an inconsistent style, it's kind of caught my attention and I can't help asking why.

Quoted 3 lines

Particularly since the short log message seems to me that you're trying to change existing, documented and reasonably correct behaviour. What's actually broken here?

Chunrong,

I'm having a hard time parsing this as well... is this fixing the issue with ifconfig were we are not seeing all the ethernet interfaces?

-M

Quoted 5 lines

-J.

Quoted 2 lines
---
 .../inetutils/inetutils-1.8/15.patch               |  197

+++++++++++++++

Quoted 2 lines
Quoted 2 lines
 .../inetutils/inetutils-1.8/add-module.patch       |   18 ++
 .../inetutils/inetutils-1.8/add-readfile.patch     |  250

++++++++++++++++++++

Quoted 9 lines
Quoted 9 lines
 .../inetutils/inetutils_1.8.bb                     |    3 +
 4 files changed, 468 insertions(+), 0 deletions(-)  create mode
100644 meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch
 create mode 100644
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.patch
 create mode 100644

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.pat ch

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch line 1

Quoted 9 lines

diff --git a/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch b/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file mode 100644
index 0000000..c2d4f11

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +1 -0
@@ -0,0 +1,197 @@
+--- inetutils-1.8/ifconfig/if_index.c        2010-05-15

06:25:47.000000000 -0500

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch line 2

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +1 -0
++++ ../inetutils-1.8-r0+fsl.1/inetutils-1.8/ifconfig/if_index.c
2012-10-30 04:03:19.595348659 -0500
Quoted 41 lines
Quoted 41 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +41 -0
+@@ -28,7 +28,7 @@
+ #include <unistd.h>
+ #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,24 +97,29 @@  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;
+-  struct if_nameindex *idx = NULL;
+-  struct ifreq *ifr, *end, *cur;
++  //printk("if_nameindex\n");
+
++//#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);
++ // rq_len = 4 * sizeof (struct ifreq);
+
+-  ifc.ifc_buf = NULL;
+-  ifc.ifc_len = 0;
++//  ifc.ifc_buf = NULL;
++//  ifc.ifc_len = 0;
+   /* Read all the interfaces out of the kernel.  */
+-  do
++/*  do
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +8 -0
+     {
+       last_len = ifc.ifc_len;
+       ifc.ifc_buf = alloca (ifc.ifc_len = rq_len); @@ -142,30
++147,59 @@  # endif
+
+       cur = ifr;
+-
+-      /* Step along the array by the size of the current structure

*/

Quoted 144 lines
Quoted 144 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/15.patch new file +140 -0
+-      ifr = (struct ifreq *) ((caddr_t) ifr + len + IFNAMSIZ);
++*/
++      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);
++
++     /* 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)
+-    continue;
+-
++    //  if (cur->ifr_addr.sa_family != AF_INET)
++    //continue;
++   idx = malloc (n * sizeof(*idx));
++   if (idx == NULL)
+       /* Make Room safely.  */
+       {
+-    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;
++    //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, ':', length), index = 0; it;
++       it = memchr (it, ':', it - content), index++)
++    {
++      char *start = it - 1;
++      *it = '\0';
++
++      while (*start != ' ' && *start != '\n')
++        start--;
+
++/*
+       idx[i].if_name = strdup (cur->ifr_name);
+       if (idx[i].if_name == NULL)
+     {
+@@ -174,18 +208,38 @@
+       errno = ENOBUFS;
+       return NULL;
+     }
++*/
++      idx[index].if_name = strdup (start + 1);
++      idx[index].if_index = index + 1;
+
+ # if defined(SIOCGIFINDEX)
+-      if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
+-    idx[i].if_index = cur->ifr_index;
+-      else
++  //    if (ioctl (fd, SIOCGIFINDEX, cur) >= 0)
++//  idx[i].if_index = cur->ifr_index;
++ //     else
++    {
++        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
+-    idx[i].if_index = i + 1;
+-      i++;
++//  idx[i].if_index = i + 1;
++ //      i++;
++   if (idx[index].if_name == NULL)
++        {
++          int saved_errno = errno;
++          close (fd);
++          free (content);
++          errno = saved_errno;
++          return NULL;
++        }
++
+     }
+
+   /* Terminate the array with an empty solt.  */
+-  {
++/*  {
+     struct if_nameindex *tidx = NULL;
+     tidx = realloc (idx, (i + 1) * sizeof (*idx));
+     if (tidx == NULL)
+@@ -199,14 +253,19 @@
+   }
+   idx[i].if_index = 0;
+   idx[i].if_name = NULL;
+-
+-  close (fd);
++*/
++  idx[index].if_index = 0;
++  idx[index].if_name = NULL;
++
++ // close (fd);
++ free(content);
+   return idx;
+-
++/*
+ #else
+   errno = ENOSYS;
+   return NULL;
+ #endif
++*/
+ }
+
+ char *

diff --git a/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.pat ch b/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module.pat

Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module line 1

Quoted 8 lines

ch
new file mode 100644
index 0000000..7acc3a4

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module new file +2 -0
+++ .patch
@@ -0,0 +1,18 @@
+--- inetutils-1.8/lib/gnulib.mk      2010-05-15 06:34:54.000000000 -

0500

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module line 2

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module new file +1 -0
++++ inetutils-1.8/lib/gnulib.mk      2012-10-29 21:50:44.821671025 -

0500

Quoted 22 lines
Quoted 22 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-module new file +16 -0
+@@ -111,6 +111,15 @@
+
+ ## end   gnulib module argp-version-etc
+
++
++## begin gnulib module read-file
++
++libgnu_a_SOURCES += read-file.c
++
++EXTRA_DIST += read-file.h
++
++## end   gnulib module read-file
++
+ ## begin gnulib module arpa_inet
+
+ BUILT_SOURCES += arpa/inet.h

diff --git a/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.p atch b/meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfile.p atch
new file mode 100644

Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 3

Quoted 8 lines

index 0000000..bb18ae9

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +4 -0
+++ le.patch
@@ -0,0 +1,250 @@
+Signed-off-by: Chunrong Guo <[email protected]>
+---
+ inetutils-1.8/lib/read-file.c |  191

+++++++++++++++++++++++++++++++++++++++++

Quoted 9 lines
Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
+ inetutils-1.8/lib/read-file.h |   36 ++++++++
+ 2 files changed, 227 insertions(+)
+ create mode 100644 inetutils-1.8/lib/read-file.c  create mode
+100644 inetutils-1.8/lib/read-file.h
+
+diff --git a/lib/read-file.c b/lib/read-file.c new file mode 100644
+index 0000000..ba7aef3
+--- /dev/null
++++ b/lib/read-file.c
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 20

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
+@@ -0,0 +1,191 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.c -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson and Bruno Haible.
++
++   This program is free software; you can redistribute it and/or

modify

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 21

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   it under the terms of the GNU General Public License as published

by

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 22

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   the Free Software Foundation; either version 3, or (at your

option)

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 31

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software

Foundation,

Quoted 15 lines
Quoted 15 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +15 -0
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
++ USA.  */
++
++#include <config.h>
++
++#include "read-file.h"
++
++/* Get fstat.  */
++#include <sys/stat.h>
++
++/* Get ftello.  */
++#include <stdio.h>
++
++/* Get SIZE_MAX.  */
++#include <stdint.h>
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 54

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
++
++/* Get malloc, realloc, free. */
++#include <stdlib.h>
++
++/* Get errno. */
++#include <errno.h>
++
++/* Read a STREAM and return a newly allocated string with the

content,

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 63

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   and set *LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   *LENGTH.  On errors, *LENGTH is undefined, errno preserves the
++   values set by system functions (if any), and NULL is returned.
++*/ char * fread_file (FILE *stream, size_t *length) {
++  char *buf = NULL;
++  size_t alloc = BUFSIZ;
++
++  /* For a regular file, allocate a buffer that has exactly the

right

Quoted 110 lines
Quoted 110 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +110 -0
++     size.  This avoids the need to do dynamic reallocations later.
++ */  {
++    struct stat st;
++
++    if (fstat (fileno (stream), &st) >= 0 && S_ISREG (st.st_mode))
++      {
++        off_t pos = ftello (stream);
++
++        if (pos >= 0 && pos < st.st_size)
++          {
++            off_t alloc_off = st.st_size - pos;
++
++            /* '1' below, accounts for the trailing NUL.  */
++            if (SIZE_MAX - 1 < alloc_off)
++              {
++                errno = ENOMEM;
++                return NULL;
++              }
++
++            alloc = alloc_off + 1;
++          }
++      }
++  }
++
++  if (!(buf = malloc (alloc)))
++    return NULL; /* errno is ENOMEM.  */
++
++  {
++    size_t size = 0; /* number of bytes read so far */
++    int save_errno;
++
++    for (;;)
++      {
++        /* This reads 1 more than the size of a regular file
++           so that we get eof immediately.  */
++        size_t requested = alloc - size;
++        size_t count = fread (buf + size, 1, requested, stream);
++        size += count;
++
++        if (count != requested)
++          {
++            save_errno = errno;
++            if (ferror (stream))
++              break;
++
++            /* Shrink the allocated memory if possible.  */
++            if (size < alloc - 1)
++              {
++                char *smaller_buf = realloc (buf, size + 1);
++                if (smaller_buf != NULL)
++                  buf = smaller_buf;
++              }
++
++            buf[size] = '\0';
++            *length = size;
++            return buf;
++          }
++
++        {
++          char *new_buf;
++
++          if (alloc == SIZE_MAX)
++            {
++              save_errno = ENOMEM;
++              break;
++            }
++
++          if (alloc < SIZE_MAX - alloc / 2)
++            alloc = alloc + alloc / 2;
++          else
++            alloc = SIZE_MAX;
++
++          if (!(new_buf = realloc (buf, alloc)))
++            {
++              save_errno = errno;
++              break;
++            }
++
++          buf = new_buf;
++        }
++      }
++
++    free (buf);
++    errno = save_errno;
++    return NULL;
++  }
++}
++
++static char *
++internal_read_file (const char *filename, size_t *length, const
++char *mode) {
++  FILE *stream = fopen (filename, mode);
++  char *out;
++  int save_errno;
++
++  if (!stream)
++    return NULL;
++
++  out = fread_file (stream, length);
++
++  save_errno = errno;
++
++  if (fclose (stream) != 0)
++    {
++      if (out)
++        {
++          save_errno = errno;
++          free (out);
++        }
++      errno = save_errno;
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 181

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
++      return NULL;
++    }
++
++  return out;
++}
++
++/* Open and read the contents of FILENAME, and return a newly
++   allocated string with the content, and set *LENGTH to the length

of

Quoted 6 lines
Quoted 6 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +6 -0
++   the string.  The string is zero-terminated, but the terminating
++   zero byte is not counted in *LENGTH.  On errors, *LENGTH is
++   undefined, errno preserves the values set by system functions (if
++   any), and NULL is returned.  */
++char *
++read_file (const char *filename, size_t *length) {
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 195

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
++  return internal_read_file (filename, length, "r"); }
++
++/* Open (on non-POSIX systems, in binary mode) and read the contents
++   of FILENAME, and return a newly allocated string with the content,
++   and set LENGTH to the length of the string.  The string is
++   zero-terminated, but the terminating zero byte is not counted in
++   the LENGTH variable.  On errors, *LENGTH is undefined, errno
++   preserves the values set by system functions (if any), and NULL

is

Quoted 9 lines
Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   returned.  */
++char *
++read_binary_file (const char *filename, size_t *length) {
++  return internal_read_file (filename, length, "rb"); }
+
+diff --git a/lib/read-file.h b/lib/read-file.h index
+0000000..14041dc
+--- /dev/null
++++ b/lib/read-file.h
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 212

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +8 -0
+@@ -0,0 +1,36 @@
++/* -*- buffer-read-only: t -*- vi: set ro: */
++/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
++/* read-file.h -- read file contents into a string
++   Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
++   Written by Simon Josefsson.
++
++   This program is free software; you can redistribute it and/or

modify

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 213

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   it under the terms of the GNU General Public License as published

by

Quoted 1 line

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 214

Quoted 1 line
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +1 -0
++   the Free Software Foundation; either version 3, or (at your

option)

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi line 223

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +9 -0
++   any later version.
++
++   This program is distributed in the hope that it will be useful,
++   but WITHOUT ANY WARRANTY; without even the implied warranty of
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++   GNU General Public License for more details.
++
++   You should have received a copy of the GNU General Public License
++   along with this program; if not, write to the Free Software

Foundation,

Quoted 21 lines
Quoted 21 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +21 -0
++   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
++ USA.  */
++
++#ifndef READ_FILE_H
++#define READ_FILE_H
++
++/* Get size_t.  */
++#include <stddef.h>
++
++/* Get FILE.  */
++#include <stdio.h>
++
++extern char *fread_file (FILE * stream, size_t * length);
++
++extern char *read_file (const char *filename, size_t * length);
++
++extern char *read_binary_file (const char *filename, size_t *
++length);
++
++#endif /* READ_FILE_H */
+--
Quoted 8 lines

meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-

Quoted 8 lines
meta-oe/recipes-connectivity/inetutils/inetutils-1.8/add-readfi new file +2 -0
+1.7.9.7
+
meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +0 -0
index 761b2e6..74a9875 100644
@@ -22,6 +22,9 @@ SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-

${PV}.tar.gz \

Quoted 9 lines

meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-${PV}.tar.gz \

Quoted 9 lines
meta-oe/recipes-connectivity/inetutils/inetutils_1.8.bb +3 -0
            file://fix-disable-ipv6.patch \
            file://disable-pre-ANSI-compilers.patch \
            file://remove_gets.patch \
+           file://add-readfile.patch \
+           file://15.patch \
+           file://add-module.patch \
 "
 SRC_URI[md5sum] = "ad8fdcdf1797b9ca258264a6b04e48fd"
 SRC_URI[sha256sum] =

"c8500baee04b9ea408c9e65e24ad7f5b41e7d96d42fb1d29abf25b52b68311c7"

Quoted 2 lines

--
Joe MacDonald, Sr. Member of Technical Staff, Linux Products Group,

Wind River

Quoted 1 line

direct 613.270.5750 mobile 613.291.7421 fax 613.592.2283