板子:helper2416 作者:帅得不敢出门 c++哈哈堂:31843264
ifplugd网址 可用于检测网络是否连接上, 如有线网卡网线是否连上, 无线网卡是否连接上 3g的暂时无法测试是否可行. 另外networkmanager也可以用于检测,其提供了命令行接口的程序nmcli
下载ifplugd-0.28.tar.gz
tar -xvf ifplugd-0.28.tar.gz
cd ifplugd-0.28
在此目录下新建
ifplugstatus-jyx.path
内容如下:
-
diff -uN ifplugd-0.28/src//ifplugstatus.c ifplugd-0.28.jyx/src//ifplugstatus.c
-
--- ifplugd-0.28/src//ifplugstatus.c 2005-01-05 08:25:31.000000000 +0800
-
+++ ifplugd-0.28.jyx/src//ifplugstatus.c 2012-11-10 17:15:22.000000000 +0800
-
@@ -31,8 +31,6 @@
-
#include
-
#include
-
-
-#include
-
-
-
#include "interface.h"
-
#include "svn-revision.h"
-
-
@@ -157,7 +155,7 @@
-
break;
-
case 'V':
-
#ifdef SVN_REVISION
-
- printf("ifplugstatus "VERSION" (SVN: "SVN_REVISION")\n");
-
+ //printf("ifplugstatus "VERSION" (SVN: "SVN_REVISION")\n");
-
#else
-
printf("ifplugstatus "VERSION"\n");
-
#endif
-
diff -uN ifplugd-0.28/src//interface.c ifplugd-0.28.jyx/src//interface.c
-
--- ifplugd-0.28/src//interface.c 2005-01-05 08:25:31.000000000 +0800
-
+++ ifplugd-0.28.jyx/src//interface.c 2012-11-10 18:01:24.000000000 +0800
-
@@ -22,11 +22,11 @@
-
#include
-
#endif
-
-
-#include
-
-#include
-
#include
-
#include
-
#include
-
+#include
-
+#include
-
#include
-
#include
-
#include
-
@@ -41,8 +41,6 @@
-
#include "interface.h"
-
#include "wireless.h"
-
-
-#include
-
-
-
void interface_up(int fd, char *iface) {
-
struct ifreq ifr;
-
-
@@ -51,7 +49,7 @@
-
-
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Warning: Could not get interface flags.");
-
+ printf("Warning: Could not get interface flags.");
-
-
return;
-
}
-
@@ -61,21 +59,21 @@
-
-
if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Warning: Could not get interface address.");
-
+ printf("Warning: Could not get interface address.");
-
} else if (ifr.ifr_addr.sa_family != AF_INET) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Warning: The interface is not IP-based.");
-
+ printf("Warning: The interface is not IP-based.");
-
} else {
-
((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr.s_addr = INADDR_ANY;
-
if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Warning: Could not set interface address.");
-
+ printf("Warning: Could not set interface address.");
-
}
-
}
-
-
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Warning: Could not get interface flags.");
-
+ printf("Warning: Could not get interface flags.");
-
-
return;
-
}
-
@@ -84,7 +82,7 @@
-
-
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Warning: Could not set interface flags.");
-
+ printf("Warning: Could not set interface flags.");
-
}
-
-
interface_status_t interface_detect_beat_mii(int fd, char *iface) {
-
@@ -98,7 +96,7 @@
-
-
if (ioctl(fd, SIOCGMIIPHY, &ifr) == -1) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "SIOCGMIIPHY failed: %s", strerror(errno));
-
+ printf("SIOCGMIIPHY failed: %s", strerror(errno));
-
-
return IFSTATUS_ERR;
-
}
-
@@ -107,7 +105,7 @@
-
-
if (ioctl(fd, SIOCGMIIREG, &ifr) == -1) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "SIOCGMIIREG failed: %s", strerror(errno));
-
+ printf("SIOCGMIIREG failed: %s", strerror(errno));
-
-
return IFSTATUS_ERR;
-
}
-
@@ -126,7 +124,7 @@
-
-
if (ioctl(fd, SIOCDEVPRIVATE, &ifr) == -1) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "SIOCDEVPRIVATE failed: %s", strerror(errno));
-
+ printf("SIOCDEVPRIVATE failed: %s", strerror(errno));
-
-
return IFSTATUS_ERR;
-
}
-
@@ -135,7 +133,7 @@
-
-
if (ioctl(fd, SIOCDEVPRIVATE+1, &ifr) == -1) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "SIOCDEVPRIVATE+1 failed: %s", strerror(errno));
-
+ printf("SIOCDEVPRIVATE+1 failed: %s", strerror(errno));
-
-
return IFSTATUS_ERR;
-
}
-
@@ -159,7 +157,7 @@
-
-
if (ioctl(fd, SIOCETHTOOL, &ifr) == -1) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "ETHTOOL_GLINK failed: %s", strerror(errno));
-
+ printf("ETHTOOL_GLINK failed: %s", strerror(errno));
-
-
return IFSTATUS_ERR;
-
}
-
@@ -179,7 +177,7 @@
-
-
if (ioctl(fd, SIOCGIFFLAGS, &ifr) == -1) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "SIOCGIFFLAGS failed: %s", strerror(errno));
-
+ printf("SIOCGIFFLAGS failed: %s", strerror(errno));
-
-
return IFSTATUS_ERR;
-
}
-
@@ -197,7 +195,7 @@
-
-
if (!(f = fopen("/proc/net/wireless", "r"))) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Failed to open /proc/net/wireless: %s",strerror(errno));
-
+ printf("Failed to open /proc/net/wireless: %s",strerror(errno));
-
-
return -1;
-
}
-
@@ -229,7 +227,7 @@
-
-
if (q < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "Failed to find interface in /proc/net/wireless");
-
+ printf("Failed to find interface in /proc/net/wireless");
-
}
-
-
return q;
-
@@ -249,7 +247,7 @@
-
-
if (ioctl(fd, SIOCGIWSTATS, &req) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "Failed to get interface quality: %s\n", strerror(errno));
-
+ printf("Failed to get interface quality: %s\n", strerror(errno));
-
return -1;
-
}
-
-
@@ -263,7 +261,7 @@
-
-
if (ioctl(fd, SIOCGIWRANGE, &req) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_ERR, "SIOCGIWRANGE failed: %s\n", strerror(errno));
-
+ printf("SIOCGIWRANGE failed: %s\n", strerror(errno));
-
return -1;
-
}
-
-
@@ -302,7 +300,7 @@
-
-
if (ioctl(fd, SIOCGIWAP, &req) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Failed to get AP address: %s",strerror(errno));
-
+ printf("Failed to get AP address: %s",strerror(errno));
-
return IFSTATUS_ERR;
-
}
-
-
@@ -314,7 +312,7 @@
-
if ((q = get_wlan_qual_new(fd, iface)) < 0)
-
if ((q = get_wlan_qual_old(iface)) < 0) {
-
if (interface_do_message)
-
- daemon_log(LOG_WARNING, "Failed to get wireless link quality.");
-
+ printf("Failed to get wireless link quality.");
-
-
return IFSTATUS_ERR;
-
}
-
diff -uN ifplugd-0.28/src//Makefile.jyx ifplugd-0.28.jyx/src//Makefile.jyx
-
--- ifplugd-0.28/src//Makefile.jyx 1970-01-01 08:00:00.000000000 +0800
-
+++ ifplugd-0.28.jyx/src//Makefile.jyx 2012-11-10 18:00:11.000000000 +0800
-
@@ -0,0 +1,2 @@
-
+ifplugstatus:interface.c ifplugstatus.c
-
+ arm-linux-gcc interface.c ifplugstatus.c -I ./ -o ifplugstatus
-
patch -p1 < ifplugstatus-jyx.path
cd src
make -f Makefile.jyx
便可生成交叉编译的ifplugstatus了.
运行它
类似输出
lo: link beat detected
eth0: unplugged
wlan0: link beat detected
阅读(5023) | 评论(0) | 转发(0) |