From 61c7b800a12f5ee705817903e8385be9719aace0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 1 Feb 2004 01:05:29 +0000 Subject: rename ifstatus file git-svn-id: file:///home/lennart/svn/public/ifplugd/trunk@97 2bf48fe7-cfc1-0310-909f-d9042e1e0fef --- man/ifplugstatus.8.xml.in | 117 ++++++++++++++++++++++++ man/ifstatus.8.xml.in | 117 ------------------------ src/ifplugstatus.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++ src/ifstatus.c | 221 ---------------------------------------------- 4 files changed, 338 insertions(+), 338 deletions(-) create mode 100644 man/ifplugstatus.8.xml.in delete mode 100644 man/ifstatus.8.xml.in create mode 100644 src/ifplugstatus.c delete mode 100644 src/ifstatus.c diff --git a/man/ifplugstatus.8.xml.in b/man/ifplugstatus.8.xml.in new file mode 100644 index 0000000..f7bb62a --- /dev/null +++ b/man/ifplugstatus.8.xml.in @@ -0,0 +1,117 @@ + + + + + + + + + + + + ifplugstatus [options] [INTERFACE] + + + +

ifplugstatus is an utility which may be used to detect the link + status of a local Linux ethernet device, much in the same way + mii-diag, mii-tool and ethtool work. In fact it supports all + three different APIs these three tools use. Thus, it provides + maximal compatibility. The newest API (ethtool) is used first, + than the next older (mii-diag) and at last the oldest + (mii-tool). It may be used in shell script since it returns the + current status as return value. It is especially useful to + detect the available APIs on the used network driver. (Option + -v)

+
+ + + +

You may speicify an ethernet device on the command + line. Otherwise ifplugstatus will check for eth0..eth9 + automatically.

+ + + + + + + + + + + + +
+ +
+

0 Success

+

1 Failure

+

2 Link beat detected (only available when an interface is specified)

+

3 Unplugged (same here)

+
+ +
+

ifplugd was written by Lennart Poettering + <@PACKAGE_BUGREPORT@>. ifplugd is available + at +

+
+ +
+

+ , , , +

+
+ +
+

This man page was written using by Oliver Kurth.

+
+ +
diff --git a/man/ifstatus.8.xml.in b/man/ifstatus.8.xml.in deleted file mode 100644 index f7bb62a..0000000 --- a/man/ifstatus.8.xml.in +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - ifplugstatus [options] [INTERFACE] - - - -

ifplugstatus is an utility which may be used to detect the link - status of a local Linux ethernet device, much in the same way - mii-diag, mii-tool and ethtool work. In fact it supports all - three different APIs these three tools use. Thus, it provides - maximal compatibility. The newest API (ethtool) is used first, - than the next older (mii-diag) and at last the oldest - (mii-tool). It may be used in shell script since it returns the - current status as return value. It is especially useful to - detect the available APIs on the used network driver. (Option - -v)

-
- - - -

You may speicify an ethernet device on the command - line. Otherwise ifplugstatus will check for eth0..eth9 - automatically.

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

0 Success

-

1 Failure

-

2 Link beat detected (only available when an interface is specified)

-

3 Unplugged (same here)

-
- -
-

ifplugd was written by Lennart Poettering - <@PACKAGE_BUGREPORT@>. ifplugd is available - at -

-
- -
-

- , , , -

-
- -
-

This man page was written using by Oliver Kurth.

-
- -
diff --git a/src/ifplugstatus.c b/src/ifplugstatus.c new file mode 100644 index 0000000..12cdd89 --- /dev/null +++ b/src/ifplugstatus.c @@ -0,0 +1,221 @@ +/* $Id$ */ + +/* + * This file is part of ifplugd. + * + * ifplugd is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * ifplugd is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ifplugd; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "interface.h" +#include "svn-revision.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + +int interface_auto_up = 0, interface_do_message = 0; + +int verbose = 0; +char *interface = NULL; + +int handle(char *iface) { + int fd, r = 0; + interface_status_t s; + + if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) + return -1; + + if (verbose > 0) { + printf("%s:\n", iface); + + 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"); + + if ((s = interface_detect_beat_mii(fd, iface)) == IFSTATUS_ERR) + 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"); + + } 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); + + switch(s) { + case IFSTATUS_UP: + if (!verbose) + printf("%s: link beat detected\n", iface); + r = 1; + break; + + case IFSTATUS_DOWN: + if (!verbose) + printf("%s: unplugged\n", iface); + r = 2; + break; + + default: + if (!verbose) + printf("%s: not supported%s\n", iface, getuid() != 0 ? " (Retry as root?)" : ""); + + r = -1; + break; + } + } + + + close(fd); + return r; +} + +void usage(char *p) { + if (strrchr(p, '/')) + p = strchr(p, '/')+1; + + printf("%s [options] [INTERFACE]\n" + " -a --auto Enable interface automatically (%s)\n" + " -q --quiet Quiet behaviour (%s)\n" + " -v --verbose Enable verbosity (%s)\n" + " -h --help Show this help\n" + " -V --version Show version number\n", + p, interface_auto_up ? "on" : "off", verbose < 0 ? "on" : "off", verbose > 0 ? "on" : "off"); +} + + +void parse(int argc, char *argv[]) { + static struct option long_options[] = { + {"auto", no_argument, 0, 'a'}, + {"quiet", no_argument, 0, 'q'}, + {"verbose", no_argument, 0, 'v'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0} + }; + int option_index = 0; + int help = 0; + + for (;;) { + int c; + + if ((c = getopt_long(argc, argv, "avhqV", long_options, &option_index)) < 0) + break; + + switch (c) { + case 'a' : + interface_auto_up = !interface_auto_up; + break; + case 'v': + verbose++; + break; + case 'q': + verbose--; + break; + case 'h': + help = 1; + break; + case 'V': +#ifdef SVN_REVISION + printf("ifplugstatus "VERSION" (SVN: "SVN_REVISION")\n"); +#else + printf("ifplugstatus "VERSION"\n"); +#endif + exit(0); + default: + fprintf(stderr, "Unknown parameter.\n"); + exit(1); + + } + } + + if (help) { + usage(argv[0]); + exit(0); + } + + if (optind < argc) + interface = argv[optind]; +} + + +int main(int argc, char *argv[]) { + parse(argc, argv); + + if (interface) { + int r; + + if ((r = handle(interface)) < 0) { + if (verbose == 0) + fprintf(stderr, "Failure (%s)\n", strerror(errno)); + return 1; + } + + return r+1; + + } else { + FILE *f; + char ln[256]; + + if (!(f = fopen("/proc/net/dev", "r"))) { + fprintf(stderr, "Failed to open /proc/net/dev: %s\n", strerror(errno)); + return 1; + } + + fgets(ln, sizeof(ln), f); + fgets(ln, sizeof(ln), f); + + while (fgets(ln, sizeof(ln), f)) { + char *p, *e; + + p = ln+strspn(ln, " \t"); + if (!(e = strchr(p, ':'))) { + fprintf(stderr, "Parse failure in /proc/net/dev.\n"); + fclose(f); + return 1; + } + + *e = 0; + handle(p); + } + + fclose(f); + } + + return 0; +} diff --git a/src/ifstatus.c b/src/ifstatus.c deleted file mode 100644 index 12cdd89..0000000 --- a/src/ifstatus.c +++ /dev/null @@ -1,221 +0,0 @@ -/* $Id$ */ - -/* - * This file is part of ifplugd. - * - * ifplugd is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * ifplugd is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with ifplugd; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "interface.h" -#include "svn-revision.h" - -#ifdef HAVE_CONFIG_H -#include -#endif - -int interface_auto_up = 0, interface_do_message = 0; - -int verbose = 0; -char *interface = NULL; - -int handle(char *iface) { - int fd, r = 0; - interface_status_t s; - - if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) - return -1; - - if (verbose > 0) { - printf("%s:\n", iface); - - 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"); - - if ((s = interface_detect_beat_mii(fd, iface)) == IFSTATUS_ERR) - 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"); - - } 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); - - switch(s) { - case IFSTATUS_UP: - if (!verbose) - printf("%s: link beat detected\n", iface); - r = 1; - break; - - case IFSTATUS_DOWN: - if (!verbose) - printf("%s: unplugged\n", iface); - r = 2; - break; - - default: - if (!verbose) - printf("%s: not supported%s\n", iface, getuid() != 0 ? " (Retry as root?)" : ""); - - r = -1; - break; - } - } - - - close(fd); - return r; -} - -void usage(char *p) { - if (strrchr(p, '/')) - p = strchr(p, '/')+1; - - printf("%s [options] [INTERFACE]\n" - " -a --auto Enable interface automatically (%s)\n" - " -q --quiet Quiet behaviour (%s)\n" - " -v --verbose Enable verbosity (%s)\n" - " -h --help Show this help\n" - " -V --version Show version number\n", - p, interface_auto_up ? "on" : "off", verbose < 0 ? "on" : "off", verbose > 0 ? "on" : "off"); -} - - -void parse(int argc, char *argv[]) { - static struct option long_options[] = { - {"auto", no_argument, 0, 'a'}, - {"quiet", no_argument, 0, 'q'}, - {"verbose", no_argument, 0, 'v'}, - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} - }; - int option_index = 0; - int help = 0; - - for (;;) { - int c; - - if ((c = getopt_long(argc, argv, "avhqV", long_options, &option_index)) < 0) - break; - - switch (c) { - case 'a' : - interface_auto_up = !interface_auto_up; - break; - case 'v': - verbose++; - break; - case 'q': - verbose--; - break; - case 'h': - help = 1; - break; - case 'V': -#ifdef SVN_REVISION - printf("ifplugstatus "VERSION" (SVN: "SVN_REVISION")\n"); -#else - printf("ifplugstatus "VERSION"\n"); -#endif - exit(0); - default: - fprintf(stderr, "Unknown parameter.\n"); - exit(1); - - } - } - - if (help) { - usage(argv[0]); - exit(0); - } - - if (optind < argc) - interface = argv[optind]; -} - - -int main(int argc, char *argv[]) { - parse(argc, argv); - - if (interface) { - int r; - - if ((r = handle(interface)) < 0) { - if (verbose == 0) - fprintf(stderr, "Failure (%s)\n", strerror(errno)); - return 1; - } - - return r+1; - - } else { - FILE *f; - char ln[256]; - - if (!(f = fopen("/proc/net/dev", "r"))) { - fprintf(stderr, "Failed to open /proc/net/dev: %s\n", strerror(errno)); - return 1; - } - - fgets(ln, sizeof(ln), f); - fgets(ln, sizeof(ln), f); - - while (fgets(ln, sizeof(ln), f)) { - char *p, *e; - - p = ln+strspn(ln, " \t"); - if (!(e = strchr(p, ':'))) { - fprintf(stderr, "Parse failure in /proc/net/dev.\n"); - fclose(f); - return 1; - } - - *e = 0; - handle(p); - } - - fclose(f); - } - - return 0; -} -- cgit