2828#include <sys/sockio.h>
2929#endif
3030
31- static const NIFlag niFlags [] = {
31+ static const FFLocalIpNIFlag niFlagOptions [] = {
3232 { IFF_UP , "UP" },
3333 { IFF_BROADCAST , "BROADCAST" },
3434 { IFF_DEBUG , "DEBUG" },
@@ -66,10 +66,10 @@ static const NIFlag niFlags[] = {
6666 { IFF_CANTCONFIG , "CANTCONFIG" },
6767#endif
6868 // sentinel
69- { 0 , NULL }
69+ {},
7070};
7171
72- static void addNewIp (FFlist * list , const char * name , const char * addr , int type , bool defaultRoute , bool firstOnly )
72+ static void addNewIp (FFlist * list , const char * name , const char * addr , int type , bool defaultRoute , uint32_t flags , bool firstOnly )
7373{
7474 FFLocalIpResult * ip = NULL ;
7575
@@ -90,6 +90,8 @@ static void addNewIp(FFlist* list, const char* name, const char* addr, int type,
9090 ip -> defaultRoute = defaultRoute ;
9191 ip -> mtu = -1 ;
9292 ip -> speed = -1 ;
93+
94+ ffLocalIpFillNIFlags (& ip -> flags , flags , niFlagOptions );
9395 }
9496
9597 switch (type )
@@ -139,7 +141,8 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
139141 if (options -> namePrefix .length && strncmp (ifa -> ifa_name , options -> namePrefix .chars , options -> namePrefix .length ) != 0 )
140142 continue ;
141143
142- bool newIP = false;
144+ uint32_t flags = options -> showType & FF_LOCALIP_TYPE_FLAGS_BIT ? ifa -> ifa_flags : 0 ;
145+
143146 if (ifa -> ifa_addr -> sa_family == AF_INET )
144147 {
145148 if (!(options -> showType & FF_LOCALIP_TYPE_IPV4_BIT ))
@@ -160,8 +163,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
160163 }
161164 }
162165
163- addNewIp (results , ifa -> ifa_name , addressBuffer , AF_INET , isDefaultRoute , !(options -> showType & FF_LOCALIP_TYPE_ALL_IPS_BIT ));
164- newIP = true;
166+ addNewIp (results , ifa -> ifa_name , addressBuffer , AF_INET , isDefaultRoute , flags , !(options -> showType & FF_LOCALIP_TYPE_ALL_IPS_BIT ));
165167 }
166168 else if (ifa -> ifa_addr -> sa_family == AF_INET6 )
167169 {
@@ -186,8 +188,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
186188 }
187189 }
188190
189- addNewIp (results , ifa -> ifa_name , addressBuffer , AF_INET6 , isDefaultRoute , !(options -> showType & FF_LOCALIP_TYPE_ALL_IPS_BIT ));
190- newIP = true;
191+ addNewIp (results , ifa -> ifa_name , addressBuffer , AF_INET6 , isDefaultRoute , flags , !(options -> showType & FF_LOCALIP_TYPE_ALL_IPS_BIT ));
191192 }
192193 #if __FreeBSD__ || __OpenBSD__ || __APPLE__
193194 else if (ifa -> ifa_addr -> sa_family == AF_LINK )
@@ -199,8 +200,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
199200 uint8_t * ptr = (uint8_t * ) LLADDR ((struct sockaddr_dl * )ifa -> ifa_addr );
200201 snprintf (addressBuffer , sizeof (addressBuffer ), "%02x:%02x:%02x:%02x:%02x:%02x" ,
201202 ptr [0 ], ptr [1 ], ptr [2 ], ptr [3 ], ptr [4 ], ptr [5 ]);
202- addNewIp (results , ifa -> ifa_name , addressBuffer , -1 , isDefaultRoute , false);
203- newIP = true;
203+ addNewIp (results , ifa -> ifa_name , addressBuffer , -1 , isDefaultRoute , flags , false);
204204 }
205205 #else
206206 else if (ifa -> ifa_addr -> sa_family == AF_PACKET )
@@ -212,17 +212,9 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
212212 uint8_t * ptr = ((struct sockaddr_ll * )ifa -> ifa_addr )-> sll_addr ;
213213 snprintf (addressBuffer , sizeof (addressBuffer ), "%02x:%02x:%02x:%02x:%02x:%02x" ,
214214 ptr [0 ], ptr [1 ], ptr [2 ], ptr [3 ], ptr [4 ], ptr [5 ]);
215- addNewIp (results , ifa -> ifa_name , addressBuffer , -1 , isDefaultRoute , false);
216- newIP = true;
215+ addNewIp (results , ifa -> ifa_name , addressBuffer , -1 , isDefaultRoute , flags , false);
217216 }
218217 #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- }
226218 }
227219
228220 if (ifAddrStruct ) freeifaddrs (ifAddrStruct );
0 commit comments