Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4471708
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: 嵌入式

2013-01-16 10:05:21

板子: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

内容如下:

[plain] view plaincopy
  1. diff -uN ifplugd-0.28/src//ifplugstatus.c ifplugd-0.28.jyx/src//ifplugstatus.c  
  2. --- ifplugd-0.28/src//ifplugstatus.c    2005-01-05 08:25:31.000000000 +0800  
  3. +++ ifplugd-0.28.jyx/src//ifplugstatus.c    2012-11-10 17:15:22.000000000 +0800  
  4. @@ -31,8 +31,6 @@  
  5.  #include   
  6.  #include   
  7.    
  8. -#include   
  9. -  
  10.  #include "interface.h"  
  11.  #include "svn-revision.h"  
  12.    
  13. @@ -157,7 +155,7 @@  
  14.                  break;  
  15.              case 'V':  
  16.  #ifdef SVN_REVISION  
  17. -        printf("ifplugstatus "VERSION" (SVN: "SVN_REVISION")\n");  
  18. +        //printf("ifplugstatus "VERSION" (SVN: "SVN_REVISION")\n");  
  19.  #else  
  20.          printf("ifplugstatus "VERSION"\n");  
  21.  #endif  
  22. diff -uN ifplugd-0.28/src//interface.c ifplugd-0.28.jyx/src//interface.c  
  23. --- ifplugd-0.28/src//interface.c   2005-01-05 08:25:31.000000000 +0800  
  24. +++ ifplugd-0.28.jyx/src//interface.c   2012-11-10 18:01:24.000000000 +0800  
  25. @@ -22,11 +22,11 @@  
  26.  #include   
  27.  #endif  
  28.    
  29. -#include   
  30. -#include   
  31.  #include   
  32.  #include   
  33.  #include   
  34. +#include   
  35. +#include   
  36.  #include   
  37.  #include   
  38.  #include   
  39. @@ -41,8 +41,6 @@  
  40.  #include "interface.h"  
  41.  #include "wireless.h"  
  42.    
  43. -#include   
  44. -  
  45.  void interface_up(int fd, char *iface) {  
  46.      struct ifreq ifr;  
  47.    
  48. @@ -51,7 +49,7 @@  
  49.        
  50.      if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {  
  51.          if (interface_do_message)  
  52. -            daemon_log(LOG_WARNING, "Warning: Could not get interface flags.");  
  53. +            printf("Warning: Could not get interface flags.");  
  54.            
  55.          return;  
  56.      }  
  57. @@ -61,21 +59,21 @@  
  58.        
  59.      if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) {  
  60.          if (interface_do_message)  
  61. -            daemon_log(LOG_WARNING, "Warning: Could not get interface address.");  
  62. +            printf("Warning: Could not get interface address.");  
  63.      } else if (ifr.ifr_addr.sa_family != AF_INET) {  
  64.          if (interface_do_message)  
  65. -            daemon_log(LOG_WARNING, "Warning: The interface is not IP-based.");  
  66. +            printf("Warning: The interface is not IP-based.");  
  67.      } else {  
  68.          ((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr.s_addr = INADDR_ANY;  
  69.          if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) {  
  70.              if (interface_do_message)  
  71. -                daemon_log(LOG_WARNING, "Warning: Could not set interface address.");  
  72. +                printf("Warning: Could not set interface address.");  
  73.          }  
  74.      }  
  75.    
  76.      if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {  
  77.          if (interface_do_message)  
  78. -            daemon_log(LOG_WARNING, "Warning: Could not get interface flags.");  
  79. +            printf("Warning: Could not get interface flags.");  
  80.            
  81.          return;  
  82.      }  
  83. @@ -84,7 +82,7 @@  
  84.        
  85.      if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)  
  86.          if (interface_do_message)  
  87. -            daemon_log(LOG_WARNING, "Warning: Could not set interface flags.");  
  88. +            printf("Warning: Could not set interface flags.");  
  89.  }  
  90.    
  91.  interface_status_t interface_detect_beat_mii(int fd, char *iface) {  
  92. @@ -98,7 +96,7 @@  
  93.    
  94.      if (ioctl(fd, SIOCGMIIPHY, &ifr) == -1) {  
  95.          if (interface_do_message)  
  96. -            daemon_log(LOG_ERR, "SIOCGMIIPHY failed: %s", strerror(errno));  
  97. +            printf("SIOCGMIIPHY failed: %s", strerror(errno));  
  98.            
  99.          return IFSTATUS_ERR;  
  100.      }  
  101. @@ -107,7 +105,7 @@  
  102.    
  103.      if (ioctl(fd, SIOCGMIIREG, &ifr) == -1) {  
  104.          if (interface_do_message)  
  105. -            daemon_log(LOG_ERR, "SIOCGMIIREG failed: %s", strerror(errno));  
  106. +            printf("SIOCGMIIREG failed: %s", strerror(errno));  
  107.            
  108.          return IFSTATUS_ERR;  
  109.      }  
  110. @@ -126,7 +124,7 @@  
  111.    
  112.      if (ioctl(fd, SIOCDEVPRIVATE, &ifr) == -1) {  
  113.          if (interface_do_message)  
  114. -            daemon_log(LOG_ERR, "SIOCDEVPRIVATE failed: %s", strerror(errno));  
  115. +            printf("SIOCDEVPRIVATE failed: %s", strerror(errno));  
  116.            
  117.          return IFSTATUS_ERR;  
  118.      }  
  119. @@ -135,7 +133,7 @@  
  120.    
  121.      if (ioctl(fd, SIOCDEVPRIVATE+1, &ifr) == -1) {  
  122.          if (interface_do_message)  
  123. -            daemon_log(LOG_ERR, "SIOCDEVPRIVATE+1 failed: %s", strerror(errno));  
  124. +            printf("SIOCDEVPRIVATE+1 failed: %s", strerror(errno));  
  125.            
  126.          return IFSTATUS_ERR;  
  127.      }  
  128. @@ -159,7 +157,7 @@  
  129.    
  130.      if (ioctl(fd, SIOCETHTOOL, &ifr) == -1) {  
  131.          if (interface_do_message)  
  132. -            daemon_log(LOG_ERR, "ETHTOOL_GLINK failed: %s", strerror(errno));  
  133. +            printf("ETHTOOL_GLINK failed: %s", strerror(errno));  
  134.            
  135.          return IFSTATUS_ERR;  
  136.      }  
  137. @@ -179,7 +177,7 @@  
  138.    
  139.      if (ioctl(fd, SIOCGIFFLAGS, &ifr) == -1) {  
  140.          if (interface_do_message)  
  141. -            daemon_log(LOG_ERR, "SIOCGIFFLAGS failed: %s", strerror(errno));  
  142. +            printf("SIOCGIFFLAGS failed: %s", strerror(errno));  
  143.    
  144.          return IFSTATUS_ERR;  
  145.      }  
  146. @@ -197,7 +195,7 @@  
  147.        
  148.      if (!(f = fopen("/proc/net/wireless", "r"))) {  
  149.          if (interface_do_message)  
  150. -            daemon_log(LOG_WARNING, "Failed to open /proc/net/wireless: %s",strerror(errno));  
  151. +            printf("Failed to open /proc/net/wireless: %s",strerror(errno));  
  152.            
  153.          return -1;  
  154.      }  
  155. @@ -229,7 +227,7 @@  
  156.    
  157.      if (q < 0) {  
  158.          if (interface_do_message)  
  159. -            daemon_log(LOG_ERR, "Failed to find interface in /proc/net/wireless");  
  160. +            printf("Failed to find interface in /proc/net/wireless");  
  161.      }  
  162.            
  163.      return q;  
  164. @@ -249,7 +247,7 @@  
  165.    
  166.      if (ioctl(fd, SIOCGIWSTATS, &req) < 0) {  
  167.          if (interface_do_message)  
  168. -            daemon_log(LOG_ERR, "Failed to get interface quality: %s\n", strerror(errno));  
  169. +            printf("Failed to get interface quality: %s\n", strerror(errno));  
  170.          return -1;  
  171.      }  
  172.    
  173. @@ -263,7 +261,7 @@  
  174.         
  175.      if (ioctl(fd, SIOCGIWRANGE, &req) < 0) {  
  176.          if (interface_do_message)  
  177. -            daemon_log(LOG_ERR, "SIOCGIWRANGE failed: %s\n", strerror(errno));  
  178. +            printf("SIOCGIWRANGE failed: %s\n", strerror(errno));  
  179.          return -1;  
  180.      }  
  181.        
  182. @@ -302,7 +300,7 @@  
  183.         
  184.      if (ioctl(fd, SIOCGIWAP, &req) < 0) {  
  185.          if (interface_do_message)  
  186. -            daemon_log(LOG_WARNING, "Failed to get AP address: %s",strerror(errno));  
  187. +            printf("Failed to get AP address: %s",strerror(errno));  
  188.          return IFSTATUS_ERR;  
  189.      }  
  190.    
  191. @@ -314,7 +312,7 @@  
  192.      if ((q = get_wlan_qual_new(fd, iface)) < 0)  
  193.          if ((q = get_wlan_qual_old(iface)) < 0) {  
  194.              if (interface_do_message)  
  195. -                daemon_log(LOG_WARNING, "Failed to get wireless link quality.");  
  196. +                printf("Failed to get wireless link quality.");  
  197.                
  198.              return IFSTATUS_ERR;  
  199.          }  
  200. diff -uN ifplugd-0.28/src//Makefile.jyx ifplugd-0.28.jyx/src//Makefile.jyx  
  201. --- ifplugd-0.28/src//Makefile.jyx  1970-01-01 08:00:00.000000000 +0800  
  202. +++ ifplugd-0.28.jyx/src//Makefile.jyx  2012-11-10 18:00:11.000000000 +0800  
  203. @@ -0,0 +1,2 @@  
  204. +ifplugstatus:interface.c ifplugstatus.c  
  205. +   arm-linux-gcc interface.c ifplugstatus.c -I ./ -o ifplugstatus   
  206.  
patch -p1 < ifplugstatus-jyx.path 

cd src

make -f Makefile.jyx

便可生成交叉编译的ifplugstatus了.

运行它

类似输出

lo: link beat detected
eth0: unplugged
wlan0: link beat detected

阅读(4905) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~