• 【info获取】openwrt获取info源码


    static char *getipolloinfo(__maybe_unused struct api_data *root)
    {
    	FILE *fstream=NULL;  
    	char ipaddr[16];
    	char macaddr[18];
    	char gateway[16];
    	char netmask[16];
    	char fpgaversion[6];
    	for(int i=0;i<5;i++)
    	{
    		switch(i)
    		{
    			case 0:
    				memset(ipaddr,0,sizeof(ipaddr));
    				if(NULL==(fstream=popen("ifconfig br-lan | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'| tr -d ['
    ']","r")))  
    				{ 
    					applog(LOG_WARNING,"get ip addr execute command failed
    "); 
    					continue;  
    				} 
    				if(NULL!=fgets(ipaddr, sizeof(ipaddr), fstream)) 
    				{ 
    					applog(LOG_WARNING,"ipaddr=%s
    ",ipaddr);
    
    				} 
    				else
    				{
    					continue;
    				}
    			break;
    			case 1:
    				memset(macaddr,0,sizeof(macaddr));
    				if(NULL==(fstream=popen("cat /sys/class/net/br-lan/address| tr -d ['
    ']","r")))  
    				{ 
    					applog(LOG_WARNING,"get mac addr execute command failed
    "); 
    					continue;  
    				} 
    				if(NULL!=fgets(macaddr, sizeof(macaddr), fstream)) 
    				{ 
    					applog(LOG_WARNING,"macaddr=%s
    ",macaddr);
    				} 
    				else
    				{
    					continue;
    				}
    			break;
    			case 2:
    				memset(gateway,0,sizeof(gateway));
    				if(NULL==(fstream=popen("netstat -rn|grep br-lan|awk '{print $2}'|awk 'NR==1'| tr -d ['
    ']","r")))  
    				{ 
    					applog(LOG_WARNING,"get gateway execute command failed
    "); 
    					continue;  
    				} 
    				if(NULL!=fgets(gateway, sizeof(gateway), fstream)) 
    				{ 
    					applog(LOG_WARNING,"gateway=%s
    ",gateway);
    				} 
    				else
    				{
    					continue;
    				}
    			break;
    			case 3:
    				memset(netmask,0,sizeof(netmask));
    				if(NULL==(fstream=popen("ifconfig br-lan | grep "Mask" | awk '{ print $4}' |awk -F: '{print $2}'| tr -d ['
    ']","r")))  
    				{ 
    					applog(LOG_WARNING,"get Netmask execute command failed
    "); 
    					continue;  
    				} 
    				if(NULL!=fgets(netmask, sizeof(netmask), fstream)) 
    				{ 
    					applog(LOG_WARNING,"netmask=%s
    ",netmask);
    				} 
    				else
    				{
    					continue;
    				}
    			break;
    			case 4:
    				memset(fpgaversion,0,sizeof(fpgaversion));
    				if(NULL==(fstream=popen("cat /tmp/fpgaversion| tr -d ['
    ']","r")))  
    				{ 
    					applog(LOG_WARNING,"get fpga version command failed
    "); 
    					continue;  
    				} 
    				if(NULL!=fgets(fpgaversion, sizeof(fpgaversion), fstream)) 
    				{ 
    					applog(LOG_WARNING,"fpgaversion=%s
    ",fpgaversion);
    				} 
    				else
    				{
    					continue;
    				}
    
    			break;	
    		}
    		
    		pclose(fstream);
    	}
    
    	root = api_add_string(root, "IP", ipaddr, true);
    	root = api_add_string(root, "Gateway", gateway, true);
    	root = api_add_string(root, "Netmask", netmask, true);
    	root = api_add_string(root, "MAC", macaddr, true);
    	root = api_add_string(root, "FPGA Version", fpgaversion, true);
    	 return (char *)root;
    	
    }
    

      

  • 相关阅读:
    good course Very
    HTTP Hypertext Transfer Protocol Overview
    Linux下tar.xz结尾的文件的解压方法
    原来java HttpURLConnection本身就提供了chunk的支持,又是让人一惊啊
    牛人一枚
    V2EX › 花了3个晚上,把readability最新的1.7.1转成了python版的
    13.11. 惯例优先原则(convention over configuration)
    明尼苏达大学
    快速构建实时抓取集群 « 搜索技术博客-淘宝
    Java Practices > Home
  • 原文地址:https://www.cnblogs.com/yuanqiangfei/p/15477620.html
Copyright © 2020-2023  润新知