X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fifplugd.c;h=88bf448fa2abcf5032e75bba8ab5d1be464baa20;hb=3f21044f20ef304309651bbdef8b275475f03a28;hp=58f56dbf15a6546a27d2058dc305206ab705a5a9;hpb=0ef64bdb40c54681e8dd5ab8df42ac88e4ab1d4a;p=oweals%2Fbusybox.git diff --git a/networking/ifplugd.c b/networking/ifplugd.c index 58f56dbf1..88bf448fa 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c @@ -6,13 +6,40 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ + +//usage:#define ifplugd_trivial_usage +//usage: "[OPTIONS]" +//usage:#define ifplugd_full_usage "\n\n" +//usage: "Network interface plug detection daemon\n" +//usage: "\n -n Don't daemonize" +//usage: "\n -s Don't log to syslog" +//usage: "\n -i IFACE Interface" +//usage: "\n -f/-F Treat link detection error as link down/link up" +//usage: "\n (otherwise exit on error)" +//usage: "\n -a Don't up interface at each link probe" +//usage: "\n -M Monitor creation/destruction of interface" +//usage: "\n (otherwise it must exist)" +//usage: "\n -r PROG Script to run" +//usage: "\n -x ARG Extra argument for script" +//usage: "\n -I Don't exit on nonzero exit code from script" +//usage: "\n -p Don't run \"up\" script on startup" +//usage: "\n -q Don't run \"down\" script on exit" +//usage: "\n -l Always run script on startup" +//usage: "\n -t SECS Poll time in seconds" +//usage: "\n -u SECS Delay before running script after link up" +//usage: "\n -d SECS Delay after link down" +//usage: "\n -m MODE API mode (mii, priv, ethtool, wlan, iff, auto)" +//usage: "\n -k Kill running daemon" + #include "libbb.h" #include "fix_u32.h" #include #include #include -#include +#ifdef HAVE_NET_ETHERNET_H +# include +#endif #include #include #include @@ -131,18 +158,21 @@ static int network_ioctl(int request, void* data, const char *errmsg) static smallint detect_link_mii(void) { - struct ifreq ifreq; - struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data; + /* char buffer instead of bona-fide struct avoids aliasing warning */ + char buf[sizeof(struct ifreq)]; + struct ifreq *const ifreq = (void *)buf; - set_ifreq_to_ifname(&ifreq); + struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data; - if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY") < 0) { + set_ifreq_to_ifname(ifreq); + + if (network_ioctl(SIOCGMIIPHY, ifreq, "SIOCGMIIPHY") < 0) { return IFSTATUS_ERR; } mii->reg_num = 1; - if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG") < 0) { + if (network_ioctl(SIOCGMIIREG, ifreq, "SIOCGMIIREG") < 0) { return IFSTATUS_ERR; } @@ -151,18 +181,21 @@ static smallint detect_link_mii(void) static smallint detect_link_priv(void) { - struct ifreq ifreq; - struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data; + /* char buffer instead of bona-fide struct avoids aliasing warning */ + char buf[sizeof(struct ifreq)]; + struct ifreq *const ifreq = (void *)buf; - set_ifreq_to_ifname(&ifreq); + struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data; + + set_ifreq_to_ifname(ifreq); - if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE") < 0) { + if (network_ioctl(SIOCDEVPRIVATE, ifreq, "SIOCDEVPRIVATE") < 0) { return IFSTATUS_ERR; } mii->reg_num = 1; - if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1") < 0) { + if (network_ioctl(SIOCDEVPRIVATE+1, ifreq, "SIOCDEVPRIVATE+1") < 0) { return IFSTATUS_ERR; }