From: Joey Hess Date: Tue, 9 Feb 2010 20:35:10 +0000 (-0500) Subject: freebsd patch from Enrico Tassi X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff93b6b5da3e3d404a659973fe898b9cfd3a8092;p=moreutils freebsd patch from Enrico Tassi * 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. --- diff --git a/debian/changelog b/debian/changelog index 00fc011..5d06af3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Mon, 05 Oct 2009 13:33:07 -0400 diff --git a/ifdata.c b/ifdata.c index ba68edc..2de98a0 100644 --- a/ifdata.c +++ b/ifdata.c @@ -4,8 +4,16 @@ #include #include #include -#include -#include + +#if defined(__linux__) + #include + #include +#endif + +#if defined(__FreeBSD_kernel__) + #include +#endif + #include #include #include @@ -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); diff --git a/ifdata.docbook b/ifdata.docbook index 5f2837f..86e90a8 100644 --- a/ifdata.docbook +++ b/ifdata.docbook @@ -104,14 +104,6 @@ with this program; if not, write to the Free Software Foundation, Inc., - - - - Prints the hardware address of the - interface. - - - @@ -151,6 +143,20 @@ with this program; if not, write to the Free Software Foundation, Inc., + + + Following options are Linux only. + + + + + + + Prints the hardware address of the + interface. + + +