<menu id="w8yyk"><menu id="w8yyk"></menu></menu>
  • <dd id="w8yyk"><nav id="w8yyk"></nav></dd>
    <menu id="w8yyk"></menu>
    <menu id="w8yyk"><code id="w8yyk"></code></menu>
    <menu id="w8yyk"></menu>
    <xmp id="w8yyk">
    <xmp id="w8yyk"><nav id="w8yyk"></nav>
  • 網站首頁 > 物聯資訊 > 技術分享

    嵌入式 hi3518平臺檢測網線是否插上

    2016-09-28 00:00:00 廣州睿豐德信息科技有限公司 閱讀
    睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接 [html] view plain copy    在CODE上查看代碼片派生到我的代碼片
    1.   
    [html] view plain copy    在CODE上查看代碼片派生到我的代碼片
    1. /********************************** (C) COPYRIGHT *******************************  
    2. * File Name          : linkstatus_check.c  
    3. * Author             : skdkjzz  
    4. * Date               : 2014/08/07  
    5. * Description        : 網線是否插上  
    6. *********************************************************************************/  
    7.   
    8.   
    9. #include <sys/types.h>    
    10. #include <string.h>    
    11. #include <stdlib.h>    
    12. #include <sys/types.h>    
    13. #include <sys/ioctl.h>    
    14. #include <sys/stat.h>    
    15. #include <stdio.h>    
    16. #include <string.h>    
    17. #include <errno.h>    
    18. #include <net/if.h>    
    19. #include <sys/utsname.h>    
    20. #include <limits.h>    
    21. #include <ctype.h>       
    22. #include <sys/socket.h>    
    23. #include <netinet/in.h>    
    24. #include <arpa/inet.h>       
    25. #include <linux/sockios.h>    
    26.     
    27. #define ETHTOOL_GLINK   0x0000000a   /* Get link status (ethtool_value) */    
    28. struct ethtool_value {    
    29.                       unsigned int   cmd;    
    30.                       unsigned int   data;     
    31.                      };      
    32.     
    33. int get_netlink_status(const char *if_name);    
    34.      
    35.   
    36.   
    37. /****************************************************************   
    38.    return value:    
    39.    -1 -- error , details can check errno    
    40.    1  -- interface link up    
    41.    0  -- interface link down.    
    42. ****************************************************************/  
    43. int get_netlink_status(const char *if_name)    
    44. {    
    45.     int skfd;    
    46.     struct ifreq ifr;    
    47.     struct ethtool_value edata;    
    48.     edata.cmd = ETHTOOL_GLINK;    
    49.     edata.data = 0;    
    50.     memset(&ifr, 0, sizeof(ifr));    
    51.     strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name) - 1);    
    52.     ifr.ifr_data = (char *)&edata;    
    53.     if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) == 0)    
    54.         return -1;    
    55.     if (ioctl(skfd, SIOCETHTOOL, &ifr) == -1)    
    56.     {    
    57.        close(skfd);         
    58.        return -1;    
    59.     }    
    60.     close(skfd);    
    61.     return edata.data;    
    62. }    
    63.   
    64.   
    65. int main()    
    66. {    
    67.     char net_buf[10]="eth0";   
    68.     printf("Net link status: %s\n", get_netlink_status(net_buf) == 1 ? "up" : "down");    
    69.     return 0;    
    70. }    
    71.    
    72.   
    73.   
    74.    </span>  
    RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成
    最近免费观看高清韩国日本大全