1
我想從Linux中的C程序獲取來自該接口的IPv6地址的網絡接口名稱(如ens33,ens37等)。怎麼做?請幫忙。如何在C程序中從linux中的IPv6地址獲取網絡接口名稱?
我想從Linux中的C程序獲取來自該接口的IPv6地址的網絡接口名稱(如ens33,ens37等)。怎麼做?請幫忙。如何在C程序中從linux中的IPv6地址獲取網絡接口名稱?
你可以得到的網絡接口使用(Linux getting all network interface names)列表
下面是從人頁面
The getifaddrs() function creates a linked list of structures describing the network interfaces of the local system, and stores the address
of the first item of the list in *ifap. The list consists of ifaddrs structures, defined as follows:
struct ifaddrs {
struct ifaddrs *ifa_next; /* Next item in list */
char *ifa_name; /* Name of interface */
unsigned int ifa_flags; /* Flags from SIOCGIFFLAGS */
struct sockaddr *ifa_addr; /* Address of interface */
struct sockaddr *ifa_netmask; /* Netmask of interface */
union {
struct sockaddr *ifu_broadaddr;
/* Broadcast address of interface */
struct sockaddr *ifu_dstaddr;
/* Point-to-point destination address */
} ifa_ifu;
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
void *ifa_data; /* Address-specific data */
};
做相反的,只是搜索列表。