diff --git a/code/trunk/sys_nicmonitor/mnic.c b/code/trunk/sys_nicmonitor/mnic.c index fd4d3da..b4f4d6c 100644 --- a/code/trunk/sys_nicmonitor/mnic.c +++ b/code/trunk/sys_nicmonitor/mnic.c @@ -17,7 +17,7 @@ #define IPLEN 16 #define CONF_FILE "/conf/nic/sys_netcard_conf.txt" -#define MNIC_VERSION "1.5" +#define MNIC_VERSION "1.6" #define NIC_UNKNOWN 0 #define NIC_DOWN 1 @@ -622,8 +622,10 @@ static char *parse_str(char **s) int ping_gw(char *devname) { + FILE *fp; int i, ret = -1, j, k; - char buf[64]; + char buf[128]; + char getbuf[64]; i = find_nic_config(devname); if( i == -1 ) @@ -634,20 +636,31 @@ int ping_gw(char *devname) for(k=0; k /dev/null 2>&1", conf.pinglap,conf.nic[i].ping_ip[j]); - ret=system(buf); -#if 0 - if (WIFSIGNALED(ret) && - (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT)) - exit(0); -#endif - if(ret == 0) - return 0; + //snprintf(buf, sizeof(buf), "ping -c 1 -w %d %s > /dev/null 2>&1", conf.pinglap,conf.nic[i].ping_ip[j]); + + snprintf(buf,sizeof(buf),"ping -c 1 -w %d %s|grep received|awk -F, '{print $2}'|awk '{print $1}'", conf.pinglap,conf.nic[i].ping_ip[j]); + if((fp = popen(buf,"r")) == NULL) + { + perror("popen"); + return 0; + }else{ + fgets(getbuf,sizeof(getbuf),fp); + if(strncmp(getbuf,"1",1) == 0) + { + pclose(fp); + return 0; + }else{ + pclose(fp); + return -1; + } + } + pclose(fp); + return 0; } } - return -1; + return 0; } static void *check_inc_switch(void *ptr)