commit-inetutils
[Top][All Lists]
Advanced

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

[SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-213-g8583f


From: Mats Erik Andersson
Subject: [SCM] GNU Inetutils branch, master, updated. inetutils-1_9_1-213-g8583f18
Date: Fri, 23 Nov 2012 00:40:44 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Inetutils ".

The branch, master has been updated
       via  8583f18c3f7829a3d7c3413fd1446679b26f6652 (commit)
      from  dbf10eb3d0fc58d109931d00cc46caedc46ab909 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=8583f18c3f7829a3d7c3413fd1446679b26f6652


commit 8583f18c3f7829a3d7c3413fd1446679b26f6652
Author: Mats Erik Andersson <address@hidden>
Date:   Fri Nov 23 00:52:38 2012 +0100

    ifconfig: Hwaddr support for BSD.

diff --git a/ChangeLog b/ChangeLog
index 733b0aa..2bcb796 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2012-11-23  Mats Erik Andersson  <address@hidden>
+
+       ifconfig: Initial hwaddr support for BSD.
+
+       * ifconfig/options.c (formats) <unix format>:
+       Place hwtype/hwaddr stanza before addr stanza,
+       and emit text only if hwtype evaluates to true.
+       (argp_options): Mention `--format=help' in usage.
+       * ifconfig/system/bsd.c: Multiple inclusions.
+       (ifp): New variable.
+       (ESTABLISH_IFADDRS): New macro.
+       (system_fh_hwaddr_query, system_fh_hwaddr)
+       (system_fh_hwtype_query, system_fh_hwtype):
+       New functions.
+       * ifconfig/system/bsd.h (IU_BSD_TYPE, ETHERNAME):
+       New macros.
+       (SYSTEM_FORMAT_HANDLER): Replace keys "dragonflybsd",
+       "freebsd", "netbsd", and "openbsd" by the single
+       IU_BSD_TYPE, encoding the only relevant system type.
+       Add keys "hwaddr?", "hwaddr", "hwtype?", and "hwtype".
+       (system_fh_hwaddr_query, system_fh_hwaddr)
+       (system_fh_hwtype_query, system_fh_hwtype):
+       New prototypes.
+
 2012-11-21  Mats Erik Andersson  <address@hidden>
 
        ifconfig: Make address changes possible on BSD.
diff --git a/ifconfig/options.c b/ifconfig/options.c
index 364a55d..43f4902 100644
--- a/ifconfig/options.c
+++ b/ifconfig/options.c
@@ -139,19 +139,21 @@ struct format formats[] = {
   /* Resembles the output of ifconfig shipped with unix systems like
      Solaris 2.7 or HPUX 10.20.  */
   {"unix",
-   "Traditional UNIX interface listing.  Default for Solaris and HPUX.",
+   "Traditional UNIX interface listing.  Default for Solaris, BSD and HPUX.",
    "${format}{check-existence}"
    "${ifdisplay?}{"
    "${name}: flags=${flags}{number}{%hx}<${flags}{string}{,}>"
    "${metric?}{ metric ${metric}}"
    "${mtu?}{ mtu ${mtu}}${\\n}"
+   /* Print only if hwtype emits something.  */
+   "${exists?}{hwtype?}{"
+     "${hwtype?}{${\\t}${hwtype}${exists?}{hwaddr?}{"
+       "${hwaddr?}{ ${hwaddr}}}${\\n}}}"
    "${addr?}{${\\t}inet ${addr}"
    "${dstaddr?}{ --> ${dstaddr}}"
    " netmask ${netmask}{0}{%#02x}${netmask}{1}{%02x}"
    "${netmask}{2}{%02x}${netmask}{3}{%02x}"
    "${brdaddr?}{ broadcast ${brdaddr}}${\\n}}"
-   "${exists?}{hwtype?}{${hwtype?}{${\\t}${hwtype}"
-   "}${exists?}{hwaddr?}{${hwaddr?}{ ${hwaddr}}}${\\n}}"
    "}"
   },
   /* Resembles the output of ifconfig shipped with OSF 4.0g.  */
@@ -225,7 +227,7 @@ static struct argp_option argp_options[] = {
   { "metric", METRIC_OPTION, "N", 0,
     "set metric of interface to N" },
   { "format", FORMAT_OPTION, "FORMAT", 0,
-    "select output format (or set back to default)" },
+    "select output format; set to `help' for info" },
   { "up", UP_OPTION, NULL, 0,
     "activate the interface (default if address is given)" },
   { "down", DOWN_OPTION, NULL, 0,
diff --git a/ifconfig/system/bsd.c b/ifconfig/system/bsd.c
index 7a50731..4b337ed 100644
--- a/ifconfig/system/bsd.c
+++ b/ifconfig/system/bsd.c
@@ -21,6 +21,13 @@
 
 #include <unistd.h>
 #include "../ifconfig.h"
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <net/if_types.h>
+#include <net/if_dl.h>
+#include <netinet/if_ether.h>
+#include <ifaddrs.h>
 
 
 /* Output format stuff.  */
@@ -55,10 +62,115 @@ system_configure (int sfd, struct ifreq *ifr, struct 
system_ifconfig *ifs)
 
 
 /* System hooks. */
+static struct ifaddrs *ifp = NULL;
+
+#define ESTABLISH_IFADDRS \
+  if (!ifp) \
+    getifaddrs (&ifp);
 
 struct if_nameindex* (*system_if_nameindex) (void) = if_nameindex;
 
 void
+system_fh_hwaddr_query (format_data_t form, int argc, char *argv[])
+{
+  ESTABLISH_IFADDRS
+  if (!ifp)
+    select_arg (form, argc, argv, 1);
+  else
+    {
+      int missing = 1;
+      struct ifaddrs *fp;
+
+      for (fp = ifp; fp; fp = fp->ifa_next)
+       {
+         struct sockaddr_dl *dl;
+
+         if (fp->ifa_addr->sa_family != AF_LINK ||
+             strcmp (fp->ifa_name, form->ifr->ifr_name))
+           continue;
+
+         dl = (struct sockaddr_dl *) fp->ifa_addr;
+         if (dl && (dl->sdl_len > 0) &&
+             dl->sdl_type == IFT_ETHER)        /* XXX: More cases?  */
+           missing = 0;
+         break;
+       }
+      select_arg (form, argc, argv, missing);
+    }
+}
+
+void
+system_fh_hwaddr (format_data_t form, int argc, char *argv[])
+{
+  ESTABLISH_IFADDRS
+  if (!ifp)
+    put_string (form, "(hwaddr unknown)");
+  else
+    {
+      int missing = 1;
+      struct ifaddrs *fp;
+
+      for (fp = ifp; fp; fp = fp->ifa_next)
+       {
+         struct sockaddr_dl *dl;
+
+         if (fp->ifa_addr->sa_family != AF_LINK ||
+             strcmp (fp->ifa_name, form->ifr->ifr_name))
+           continue;
+
+         dl = (struct sockaddr_dl *) fp->ifa_addr;
+         if (dl && (dl->sdl_len > 0) &&
+             dl->sdl_type == IFT_ETHER)        /* XXX: More cases?  */
+           {
+             missing = 0;
+             put_string (form, ether_ntoa ((struct ether_addr *) LLADDR (dl)));
+           }
+         break;
+       }
+      if (missing)
+       put_string (form, "(hwaddr unknown)");
+    }
+}
+
+void
+system_fh_hwtype_query (format_data_t form, int argc, char *argv[])
+{
+  system_fh_hwaddr_query (form, argc, argv);
+}
+
+void
+system_fh_hwtype (format_data_t form, int argc, char *argv[])
+{
+  ESTABLISH_IFADDRS
+  if (!ifp)
+    put_string (form, "(hwtype unknown)");
+  else
+    {
+      int found = 0;
+      struct ifaddrs *fp;
+      struct sockaddr_dl *dl = NULL;
+
+      for (fp = ifp; fp; fp = fp->ifa_next)
+       {
+         if (fp->ifa_addr->sa_family != AF_LINK ||
+             strcmp (fp->ifa_name, form->ifr->ifr_name))
+           continue;
+
+         dl = (struct sockaddr_dl *) fp->ifa_addr;
+         if (dl && (dl->sdl_len > 0) &&
+             dl->sdl_type == IFT_ETHER)        /* XXX: More cases?  */
+           {
+             found = 1;
+             put_string (form, ETHERNAME);
+           }
+         break;
+       }
+      if (!found)
+       put_string (form, "(unknown hwtype)");
+    }
+}
+
+void
 system_fh_metric (format_data_t form, int argc, char *argv[])
 {
 #ifdef SIOCGIFMETRIC
diff --git a/ifconfig/system/bsd.h b/ifconfig/system/bsd.h
index e6aeec2..49dcfaa 100644
--- a/ifconfig/system/bsd.h
+++ b/ifconfig/system/bsd.h
@@ -22,6 +22,24 @@
 # include "../printif.h"
 # include "../options.h"
 # include <sys/sockio.h>
+
+/* BSD variant chooser.  */
+# if defined __DragonFly__
+#  define IU_BSD_TYPE "dragonfly"
+# elif defined __FreeBSD__
+#  define IU_BSD_TYPE "freebsd"
+# elif defined __NetBSD__
+#  define IU_BSD_TYPE "netbsd"
+# elif defined __OpenBSD__
+#  define IU_BSD_TYPE "openbsd"
+#  define ETHERNAME "lladdr"
+# else /* Exotic BSD versions.  */
+#  define IU_BSD_TYPE "unknownbsd"
+# endif
+
+# ifndef ETHERNAME
+#  define ETHERNAME "ether"
+# endif
 
 
 /* Option support.  */
@@ -37,25 +55,19 @@ struct system_ifconfig
 
 /* Output format support.  */
 
-/* Set this to a comma seperated, comma terminated list of struct
-   format_handler entries.  They are inserted at the beginning of the
-   default list, so they override generic implementations if they have
-   the same name.  For example:
-   #define SYSTEM_FORMAT_HANDLER { "foobar", system_fh_nothing }, \
-   { "newline", system_fh_newline },
-   Define some architecture symbol like "foobar", so it can be tested
-   for in generic format strings with ${exists?}{foobar?}.  */
 # define SYSTEM_FORMAT_HANDLER \
   {"bsd", fh_nothing},         \
-  {"dragonflybsd", fh_nothing},        \
-  {"freebsd", fh_nothing},     \
-  {"netbsd", fh_nothing},      \
-  {"openbsd", fh_nothing},     \
+  {IU_BSD_TYPE, fh_nothing},   \
+  {"hwaddr?", system_fh_hwaddr_query}, \
+  {"hwaddr", system_fh_hwaddr}, \
+  {"hwtype?", system_fh_hwtype_query}, \
+  {"hwtype", system_fh_hwtype}, \
   {"metric", system_fh_metric},
 
-/* Prototype system_fh_* functions here.
-   void system_fh_newline (format_data_t, int, char **);
-*/
+void system_fh_hwaddr_query (format_data_t form, int argc, char *argv[]);
+void system_fh_hwaddr (format_data_t form, int argc, char *argv[]);
+void system_fh_hwtype_query (format_data_t form, int argc, char *argv[]);
+void system_fh_hwtype (format_data_t form, int argc, char *argv[]);
 void system_fh_metric (format_data_t form, int argc, char *argv[]);
 
-#endif
+#endif /* IFCONFIG_SYSTEM_BSD_H */

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog             |   24 ++++++++++
 ifconfig/options.c    |   10 +++--
 ifconfig/system/bsd.c |  112 +++++++++++++++++++++++++++++++++++++++++++++++++
 ifconfig/system/bsd.h |   44 ++++++++++++-------
 4 files changed, 170 insertions(+), 20 deletions(-)


hooks/post-receive
-- 
GNU Inetutils 



reply via email to

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