zl程序教程

您现在的位置是:首页 >  后端

当前栏目

根据网卡名获取IP地址,以及掩码地址

地址网卡 获取 以及 根据 IP地址 掩码
2023-09-14 08:59:45 时间
    printf("%s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );

The socket used can be a TCP socket (SOCK_STREAM) as well.

If you also need the netmask then use the SIOCGIFNETMASK value in ioctl like this :


    printf("IP address of %s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );
    printf("Netmask of %s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );