]> err.no Git - moreutils/commitdiff
freebsd patch from Enrico Tassi
authorJoey Hess <joey@gnu.kitenet.net>
Tue, 9 Feb 2010 20:35:10 +0000 (15:35 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Tue, 9 Feb 2010 20:38:39 +0000 (15:38 -0500)
  * ifdata:
    - Use unsigned long for ioctl command.
      On both Linux and FreeBSD ioctl expects an unsigned long command.
      FreeBSD kernel was complaining about the (by chance) signedness of
      the ioctl command (then probably ignored, since it worked both on
      Linux and FreeBSD).

        WARNING pid 799 (ifdata): ioctl sign-extension ioctl ffffffffc0206933

    - put #if defined(__linux__) around ioctls that are not supported by
      FreeBSD

    - Mention in the manpage that some options are Linux specific.

debian/changelog
ifdata.c
ifdata.docbook

index 00fc01154d6cfb5e8aec5f0de79963d5dd1b47be..5d06af3d5126b4db6cb0558bf811a24a9f419d56 100644 (file)
@@ -4,6 +4,8 @@ moreutils (0.38) UNRELEASED; urgency=low
     (Thanks, Justin B Rye)
   * parallel: Allow running independent commands,
     like `parallel -j3 -- ls df "echo hi"`
+  * ifdata: Add FreeBSD kernel support, although some of the more esoteric
+    interface options are not currently supported in FreeBSD.
 
  -- Joey Hess <joeyh@debian.org>  Mon, 05 Oct 2009 13:33:07 -0400
 
index ba68edced696c617214a22b0a677e165d9c1dd8d..2de98a0b19372bff63be861b5adc755fa52fc74d 100644 (file)
--- a/ifdata.c
+++ b/ifdata.c
@@ -4,8 +4,16 @@
 #include <stdio.h>
 #include <netdb.h>
 #include <sys/ioctl.h>
-#include <linux/sockios.h>
-#include <linux/if.h>
+
+#if defined(__linux__)
+       #include <linux/sockios.h>
+       #include <linux/if.h>
+#endif
+
+#if defined(__FreeBSD_kernel__)
+       #include <net/if.h>
+#endif
+
 #include <netinet/in.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -91,7 +99,7 @@ enum print_error_enum {
  * return 0 success
  *        1 error
  */
-static int do_socket_ioctl(const char *ifname, const int request,
+static int do_socket_ioctl(const char *ifname, const unsigned long int request,
                            struct ifreq *req, int *ioctl_errno,
                            const enum print_error_enum print_error) {
        int sock, res;
@@ -120,6 +128,8 @@ int if_exists(const char *iface) {
        return !do_socket_ioctl(iface, SIOCGIFFLAGS, &r, NULL, PRINT_NO_ERROR);
 }
 
+#if defined(__linux__)
+
 void if_flags(const char *iface) {
        struct ifreq r;
        unsigned int i;
@@ -167,8 +177,10 @@ void if_hwaddr(const char *iface) {
               hwaddr[0], hwaddr[1], hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]);
 }
 
+#endif
+
 static struct sockaddr *if_addr_value(const char *iface, struct ifreq *r, 
-                                      int request) {
+                                      unsigned long int request) {
        int e;
 
        if (do_socket_ioctl(iface, request, r, &e, PRINT_NO_ERROR)) {
@@ -217,6 +229,8 @@ int if_mtu(const char *iface) {
        return req.ifr_mtu;
 }
 
+#if defined(__linux__)
+
 static void skipline(FILE *fd) {
        int ch;
        do {
@@ -277,6 +291,8 @@ struct if_stat *get_stats(const char *iface) {
        return NULL;
 }
 
+#endif
+
 const struct {
        char *option;
        unsigned int flag;
@@ -286,14 +302,14 @@ const struct {
        { "-e",   DO_EXISTS,        0, "Reports interface existence via return code" },
        { "-p",   DO_PALL,          0, "Print out the whole config of iface" },
        { "-pe",  DO_PEXISTS,       0, "Print out yes or no according to existence" },
-       { "-ph",  DO_PHWADDRESS,    0, "Print out the hardware address" },
        { "-pa",  DO_PADDRESS,      0, "Print out the address" },
        { "-pn",  DO_PMASK,         0, "Print netmask" },
        { "-pN",  DO_PNETWORK,      0, "Print network address" },
        { "-pb",  DO_PCAST,         0, "Print broadcast" },
        { "-pm",  DO_PMTU,          0, "Print mtu" },
+#if defined(__linux__)
+       { "-ph",  DO_PHWADDRESS,    0, "Print out the hardware address" },
        { "-pf",  DO_PFLAGS,        0, "Print flags" },
-
        { "-si",  DO_SINALL,        1, "Print all statistics on input" },
        { "-sip", DO_SINPACKETS,    1, "Print # of in packets" },
        { "-sib", DO_SINBYTES,      1, "Print # of in bytes" },
@@ -313,6 +329,7 @@ const struct {
        { "-som", DO_SOUTMULTICAST, 1, "Print # of out multicast" },
        { "-bips",DO_BIPS,          1, "Print # of incoming bytes per second" },
        { "-bops",DO_BOPS,          1, "Print # of outgoing bytes per second" },
+#endif
 };
 
 void usage(const char *name) {
@@ -353,15 +370,17 @@ void please_do(int ndo, int *todo, const char *ifname) {
                        case DO_PEXISTS:
                                printf("%s", if_exists(ifname) ? "yes" : "no");
                                break;
-                       case DO_PHWADDRESS:
-                               if_hwaddr(ifname);
-                               break;
                        case DO_PADDRESS:
                                print_addr(if_addr(ifname, &req));
                                break;
+#if defined(__linux__)
+                       case DO_PHWADDRESS:
+                               if_hwaddr(ifname);
+                               break;
                        case DO_PFLAGS:
                                if_flags(ifname);
                                break;
+#endif
                        case DO_PMASK:
                                print_addr(if_mask(ifname, &req));
                                break;
@@ -383,7 +402,7 @@ void please_do(int ndo, int *todo, const char *ifname) {
                                printf(" ");
                                printf("%d", if_mtu(ifname));
                                break;
-
+#if defined(__linux__)
                        case DO_SINPACKETS:
                                printf("%llu",ifstats->in_packets);
                                break;
@@ -460,6 +479,7 @@ void please_do(int ndo, int *todo, const char *ifname) {
                                        ifstats->out_fifo, ifstats->out_colls,
                                        ifstats->out_carrier, ifstats->out_multicast);
                                break;
+#endif
                        default:
                                printf("Unknown command: %d", todo[i]);
                                break;
@@ -513,10 +533,12 @@ int main(int argc, char *argv[]) {
                return 1;
        }
 
+#if defined(__linux__)
        if (do_stats && (ifstats = get_stats(ifname)) == NULL) {
                fprintf(stderr, "Error getting statistics for %s\n", ifname);
                return 1;
        }
+#endif
 
        please_do(ndo, todo, ifname);
 
index 5f2837f71cb7ea8e1aa8481d854d975174e19ab9..86e90a8b2613fbd181618231a888484e3b5afda4 100644 (file)
@@ -104,14 +104,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                        </listitem>
                </varlistentry>
        
-               <varlistentry>
-                       <term><option>-ph</option></term>
-                       <listitem>
-                               <para>Prints the hardware address of the
-                                       interface.</para>
-                       </listitem>
-               </varlistentry>
-
                <varlistentry>
                        <term><option>-pa</option></term>
                        <listitem>
@@ -151,6 +143,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                        </listitem>
                </varlistentry>
 
+               </variablelist>
+       
+               <para>Following options are Linux only.</para>
+
+               <variablelist>
+                       
+               <varlistentry>
+                       <term><option>-ph</option></term>
+                       <listitem>
+                               <para>Prints the hardware address of the
+                                       interface.</para>
+                       </listitem>
+               </varlistentry>
+
                <varlistentry>
                        <term><option>-pf</option></term>
                        <listitem>