簡體   English   中英

如何在C程序中從Linux中的IPv6地址獲取網絡接口名稱?

[英]How to get network interface name from IPv6 address in linux in a C program?

我想從屬於Linux中C程序接口的IPv6地址獲取網絡接口名稱(如ens33,ens37等)。 怎么做? 請幫忙。

您可以使用getifaddrs 獲取網絡接口列表( Linux獲取所有網絡接口名稱

下面是getifaddrs手冊頁

   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 */
       };

反之,只需搜索列表即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM