• 获取板子网卡Ip


    积累点滴,一种获取板子网卡Ip方法

     1 int main()
     2 {
     3     struct ifreq stIfconfig;
     4 
     5     char szIPeth0[16];
     6     char szIPeth1[16];
     7     memset(szIPeth0,0x0,16);
     8     memset(szIPeth1,0x0,16);
     9 
    10     int nNetWorkSocket = socket(AF_INET, SOCK_DGRAM, 0);
    11 
    12     //获取eth0的ip
    13     strncpy(stIfconfig.ifr_name, "eth0",5);
    14     if (ioctl(nNetWorkSocket, SIOCGIFADDR, &stIfconfig) < 0)
    15     {
    16         printf("ioctl does not get eth0!")
    17     }
    18     else
    19     {
    20         strncpy(szIPeth0,inet_ntoa(((struct sockaddr_in*)&(stIfconfig.ifr_addr))->sin_addr),16);
    21     }
    22 
    23     //获取eth1的ip
    24     strncpy(stIfconfig.ifr_name, "eth1",5);
    25     if (ioctl(nNetWorkSocket, SIOCGIFADDR, &stIfconfig) < 0)
    26     {
    27         printf("ioctl does not get eth1!")
    28     }
    29     else
    30     {
    31         strncpy(szIPeth1,inet_ntoa(((struct sockaddr_in*)&(stIfconfig.ifr_addr))->sin_addr),16);
    32     }
    33     
    34     printf("eth0 = %s", szIPeth0);
    35     printf("eth1 = %s", szIPeth1);
    36     
    37 }
  • 相关阅读:
    Codeforces 672D
    Codeforces 672C
    Codeforces 673D
    Codeforces 1181D
    Codeforces 1181C
    Codeforces 1011F
    Codeforces 1011E
    2020.1.3计导全面复习
    csp模拟题-201903
    CCF模拟题-201909
  • 原文地址:https://www.cnblogs.com/liwentao1091/p/2881396.html
Copyright © 2020-2023  润新知