diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-04-12 13:58:11 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-04-12 13:58:11 +0000 |
commit | 3a46885c17ba051ced802e3d35b9ddc6bf10edf6 (patch) | |
tree | 22163205f0c0c511acbf2da8121fd22c05cbf45b /src | |
parent | 6f81258a90dd9813246a76ccb35c72255541f5e1 (diff) |
preparation for 0.24
git-svn-id: file:///home/lennart/svn/public/ifplugd/trunk@109 2bf48fe7-cfc1-0310-909f-d9042e1e0fef
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ifplugd.c | 23 | ||||
-rw-r--r-- | src/ifplugstatus.c | 28 | ||||
-rw-r--r-- | src/interface.c | 19 | ||||
-rw-r--r-- | src/interface.h | 3 |
5 files changed, 54 insertions, 21 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 6e36a96..fb849bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ # along with ifplugd; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -AM_CFLAGS = $(LIBDAEMON_CFLAGS) -DSYSCONFDIR="\"$(sysconfdir)\"" +AM_CFLAGS = $(LIBDAEMON_CFLAGS) -DSYSCONFDIR="\"$(sysconfdir)\"" -D_GNU_SOURCE LDADD = $(LIBDAEMON_LIBS) sbin_PROGRAMS = ifplugd ifplugstatus diff --git a/src/ifplugd.c b/src/ifplugd.c index 28f1ce5..d9aa708 100644 --- a/src/ifplugd.c +++ b/src/ifplugd.c @@ -19,8 +19,6 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#define _GNU_SOURCE - #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -87,7 +85,7 @@ int disabled = 0; interface_status_t failure_status = IFSTATUS_ERR; -enum { API_AUTO, API_ETHTOOL, API_MII, API_PRIVATE, API_WLAN } api_mode = API_AUTO; +enum { API_AUTO, API_ETHTOOL, API_MII, API_PRIVATE, API_WLAN, API_IFF } api_mode = API_AUTO; interface_status_t (*detect_beat_func)(int, char*); interface_status_t (*cached_detect_beat_func)(int, char*) = NULL; @@ -256,17 +254,23 @@ interface_status_t detect_beat_auto(int fd, char *iface) { if (cached_detect_beat_func && (status = cached_detect_beat_func(fd, iface)) != IFSTATUS_ERR) return status; - if ((status = interface_detect_beat_mii(fd, iface)) != IFSTATUS_ERR) { - cached_detect_beat_func = interface_detect_beat_mii; - daemon_log(LOG_INFO, "Using detection mode: SIOCGMIIPHY"); + if ((status = interface_detect_beat_iff(fd, iface)) != IFSTATUS_ERR) { + cached_detect_beat_func = interface_detect_beat_iff; + daemon_log(LOG_INFO, "Using detection mode: IFF_RUNNING"); return status; } - + if ((status = interface_detect_beat_ethtool(fd, iface)) != IFSTATUS_ERR) { cached_detect_beat_func = interface_detect_beat_ethtool; daemon_log(LOG_INFO, "Using detection mode: SIOCETHTOOL"); return status; } + + if ((status = interface_detect_beat_mii(fd, iface)) != IFSTATUS_ERR) { + cached_detect_beat_func = interface_detect_beat_mii; + daemon_log(LOG_INFO, "Using detection mode: SIOCGMIIPHY"); + return status; + } if ((status = interface_detect_beat_wlan(fd, iface)) != IFSTATUS_ERR) { cached_detect_beat_func = interface_detect_beat_wlan; @@ -400,7 +404,8 @@ void work(void) { case API_ETHTOOL: detect_beat_func = interface_detect_beat_ethtool; break; case API_MII: detect_beat_func = interface_detect_beat_mii; break; case API_PRIVATE: detect_beat_func = interface_detect_beat_priv; break; - case API_WLAN: detect_beat_func = interface_detect_beat_wlan;break; + case API_WLAN: detect_beat_func = interface_detect_beat_wlan; break; + case API_IFF: detect_beat_func = interface_detect_beat_iff; break; default: detect_beat_func = detect_beat_auto; @@ -609,6 +614,7 @@ void usage(char *p) { case API_MII: m = "mii"; break; case API_PRIVATE: m = "priv"; break; case API_WLAN: m = "wlan"; break; + case API_IFF: m = "iff"; break; default: m = "auto"; } @@ -763,6 +769,7 @@ void parse_args(int argc, char *argv[]) { case 'p': api_mode = API_PRIVATE; break; case 'w': api_mode = API_WLAN; break; case 'a': api_mode = API_AUTO; break; + case 'i': api_mode = API_IFF; break; default: daemon_log(LOG_ERR, "Unknown API mode: %s", optarg); exit(2); diff --git a/src/ifplugstatus.c b/src/ifplugstatus.c index 12cdd89..e4db11b 100644 --- a/src/ifplugstatus.c +++ b/src/ifplugstatus.c @@ -51,7 +51,12 @@ int handle(char *iface) { if (verbose > 0) { printf("%s:\n", iface); - if ((s = interface_detect_beat_ethtool(fd, iface)) == IFSTATUS_ERR) + if ((s = interface_detect_beat_iff(fd, iface)) == IFSTATUS_ERR) + printf(" IFF_RUNNING failed.\n"); + else + printf(" IFF_RUNNING: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged"); + + if ((s = interface_detect_beat_ethtool(fd, iface)) == IFSTATUS_ERR) printf(" SIOCETHTOOL failed (%s)\n", strerror(errno)); else printf(" SIOCETHTOOL: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged"); @@ -60,23 +65,24 @@ int handle(char *iface) { printf(" SIOCGMIIPHY failed (%s)\n", strerror(errno)); else printf(" SIOCGMIIPHY: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged"); - - if ((s = interface_detect_beat_priv(fd, iface)) == IFSTATUS_ERR) - printf(" SIOCDEVPRIVATE failed (%s)\n", strerror(errno)); - else - printf(" SIOCDEVPRIVATE: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged"); if ((s = interface_detect_beat_wlan(fd, iface)) == IFSTATUS_ERR) printf(" Wireless failed.\n"); else printf(" Wireless: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged"); + if ((s = interface_detect_beat_priv(fd, iface)) == IFSTATUS_ERR) + printf(" SIOCDEVPRIVATE failed (%s)\n", strerror(errno)); + else + printf(" SIOCDEVPRIVATE: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged"); + } else { - - if ((s = interface_detect_beat_mii(fd, iface)) == IFSTATUS_ERR) - if ((s = interface_detect_beat_ethtool(fd, iface)) == IFSTATUS_ERR) - if ((s = interface_detect_beat_wlan(fd, iface)) == IFSTATUS_ERR) - s = interface_detect_beat_priv(fd, iface); + + if ((s = interface_detect_beat_iff(fd, iface)) == IFSTATUS_ERR) + if ((s = interface_detect_beat_ethtool(fd, iface)) == IFSTATUS_ERR) + if ((s = interface_detect_beat_mii(fd, iface)) == IFSTATUS_ERR) + if ((s = interface_detect_beat_wlan(fd, iface)) == IFSTATUS_ERR) + s = interface_detect_beat_priv(fd, iface); switch(s) { case IFSTATUS_UP: diff --git a/src/interface.c b/src/interface.c index d277612..6007172 100644 --- a/src/interface.c +++ b/src/interface.c @@ -163,6 +163,25 @@ interface_status_t interface_detect_beat_ethtool(int fd, char *iface) { return edata.data ? IFSTATUS_UP : IFSTATUS_DOWN; } +interface_status_t interface_detect_beat_iff(int fd, char *iface) { + + struct ifreq ifr; + + if (interface_auto_up) + interface_up(fd, iface); + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1); + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) == -1) { + if (interface_do_message) + daemon_log(LOG_ERR, "SIOCGIFFLAGS failed: %s", strerror(errno)); + + return IFSTATUS_ERR; + } + + return ifr.ifr_flags & IFF_RUNNING ? IFSTATUS_UP : IFSTATUS_DOWN; +} static int get_wlan_qual_old(char *iface) { FILE *f; diff --git a/src/interface.h b/src/interface.h index d1f3826..2f35a84 100644 --- a/src/interface.h +++ b/src/interface.h @@ -1,7 +1,7 @@ #ifndef foointerfacehfoo #define foointerfacehfoo -/* $Id: interface.h 1.2 Wed, 23 Oct 2002 20:49:08 +0200 lennart $ */ +/* $Id$ */ /* * This file is part of ifplugd. @@ -32,5 +32,6 @@ interface_status_t interface_detect_beat_mii(int fd, char *iface); interface_status_t interface_detect_beat_priv(int fd, char *iface); interface_status_t interface_detect_beat_ethtool(int fd, char *iface); interface_status_t interface_detect_beat_wlan(int fd, char *iface); +interface_status_t interface_detect_beat_iff(int fd, char *iface); #endif |