1515#ifdef __linux__
1616#include <linux/ethtool.h>
1717#include <linux/sockios.h>
18+ #include <linux/if.h>
1819#endif
1920
2021#if defined(__FreeBSD__ ) || defined(__OpenBSD__ ) || defined(__APPLE__ )
2728#include <sys/sockio.h>
2829#endif
2930
31+ static const NIFlag niFlags [] = {
32+ { IFF_UP , "UP" },
33+ { IFF_BROADCAST , "BROADCAST" },
34+ { IFF_DEBUG , "DEBUG" },
35+ { IFF_LOOPBACK , "LOOPBACK" },
36+ { IFF_POINTOPOINT , "POINTOPOINT" },
37+ { IFF_RUNNING , "RUNNING" },
38+ { IFF_NOARP , "NOARP" },
39+ { IFF_PROMISC , "PROMISC" },
40+ { IFF_ALLMULTI , "ALLMULTI" },
41+ { IFF_MULTICAST , "MULTICAST" },
42+ #if defined(__linux__ ) || defined (__APPLE__ ) || defined (__sun )
43+ { IFF_NOTRAILERS , "NOTRAILERS" },
44+ #endif
45+ #ifdef __linux__
46+ { IFF_MASTER , "MASTER" },
47+ { IFF_SLAVE , "SLAVE" },
48+ { IFF_PORTSEL , "PORTSEL" },
49+ { IFF_AUTOMEDIA , "AUTOMEDIA" },
50+ { IFF_DYNAMIC , "DYNAMIC" },
51+ { IFF_LOWER_UP , "LOWER_UP" },
52+ { IFF_DORMANT , "DORMANT" },
53+ { IFF_ECHO , "ECHO" },
54+ #endif
55+ #if defined(__FreeBSD__ ) || defined (__APPLE__ ) || defined (__OpenBSD__ )
56+ { IFF_OACTIVE , "OACTIVE" },
57+ { IFF_SIMPLEX , "SIMPLEX" },
58+ { IFF_LINK0 , "LINK0" },
59+ { IFF_LINK1 , "LINK1" },
60+ { IFF_LINK2 , "LINK2" },
61+ #endif
62+ #if defined(__FreeBSD__ ) || defined (__APPLE__ )
63+ { IFF_ALTPHYS , "ALTPHYS" },
64+ #endif
65+ #ifdef __FreeBSD__
66+ { IFF_CANTCONFIG , "CANTCONFIG" },
67+ #endif
68+ // sentinel
69+ { 0 , NULL }
70+ };
71+
3072static void addNewIp (FFlist * list , const char * name , const char * addr , int type , bool defaultRoute , bool firstOnly )
3173{
3274 FFLocalIpResult * ip = NULL ;
@@ -44,6 +86,7 @@ static void addNewIp(FFlist* list, const char* name, const char* addr, int type,
4486 ffStrbufInit (& ip -> ipv4 );
4587 ffStrbufInit (& ip -> ipv6 );
4688 ffStrbufInit (& ip -> mac );
89+ ffStrbufInit (& ip -> flags );
4790 ip -> defaultRoute = defaultRoute ;
4891 ip -> mtu = -1 ;
4992 ip -> speed = -1 ;
@@ -96,6 +139,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
96139 if (options -> namePrefix .length && strncmp (ifa -> ifa_name , options -> namePrefix .chars , options -> namePrefix .length ) != 0 )
97140 continue ;
98141
142+ bool newIP = false;
99143 if (ifa -> ifa_addr -> sa_family == AF_INET )
100144 {
101145 if (!(options -> showType & FF_LOCALIP_TYPE_IPV4_BIT ))
@@ -117,6 +161,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
117161 }
118162
119163 addNewIp (results , ifa -> ifa_name , addressBuffer , AF_INET , isDefaultRoute , !(options -> showType & FF_LOCALIP_TYPE_ALL_IPS_BIT ));
164+ newIP = true;
120165 }
121166 else if (ifa -> ifa_addr -> sa_family == AF_INET6 )
122167 {
@@ -142,6 +187,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
142187 }
143188
144189 addNewIp (results , ifa -> ifa_name , addressBuffer , AF_INET6 , isDefaultRoute , !(options -> showType & FF_LOCALIP_TYPE_ALL_IPS_BIT ));
190+ newIP = true;
145191 }
146192 #if __FreeBSD__ || __OpenBSD__ || __APPLE__
147193 else if (ifa -> ifa_addr -> sa_family == AF_LINK )
@@ -154,6 +200,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
154200 snprintf (addressBuffer , sizeof (addressBuffer ), "%02x:%02x:%02x:%02x:%02x:%02x" ,
155201 ptr [0 ], ptr [1 ], ptr [2 ], ptr [3 ], ptr [4 ], ptr [5 ]);
156202 addNewIp (results , ifa -> ifa_name , addressBuffer , -1 , isDefaultRoute , false);
203+ newIP = true;
157204 }
158205 #else
159206 else if (ifa -> ifa_addr -> sa_family == AF_PACKET )
@@ -166,8 +213,16 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
166213 snprintf (addressBuffer , sizeof (addressBuffer ), "%02x:%02x:%02x:%02x:%02x:%02x" ,
167214 ptr [0 ], ptr [1 ], ptr [2 ], ptr [3 ], ptr [4 ], ptr [5 ]);
168215 addNewIp (results , ifa -> ifa_name , addressBuffer , -1 , isDefaultRoute , false);
216+ newIP = true;
169217 }
170218 #endif
219+
220+ if (newIP )
221+ {
222+ FFLocalIpResult * result = FF_LIST_GET (FFLocalIpResult , * results , results -> length - 1 );
223+ if (options -> showType & FF_LOCALIP_TYPE_FLAGS_BIT )
224+ writeNIFlagsToStrBuf (& result -> flags , (int )ifa -> ifa_flags , niFlags );
225+ }
171226 }
172227
173228 if (ifAddrStruct ) freeifaddrs (ifAddrStruct );
0 commit comments