File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1414#define MALLOC (x ) HeapAlloc(GetProcessHeap(), 0 , (x))
1515#define FREE (x ) HeapFree(GetProcessHeap(), 0 , (x))
1616
17+ #if (_WIN32_WINNT < 0x0501) /* WIN2000-SP1. network 169.254/16 */
18+ #define IN4_IS_ADDR_LINKLOCAL (ip ) ((ip)->S_un.S_un_b.s_b1 == 169 && (ip)->S_un.S_un_b.s_b2 == 254 )
19+ #else
20+ #include < mstcpip.h>
21+ #endif
22+
1723std::vector<interfaceInformation> interfaceList ()
1824{
1925 std::vector<interfaceInformation> list;
@@ -71,12 +77,21 @@ std::vector<interfaceInformation> interfaceList()
7177
7278 interfaceInformation ifAddr;
7379 ifAddr.name = pCurrAddresses->AdapterName ;
80+
81+ if (pCurrAddresses->OperStatus != IfOperStatusUp)
82+ continue ; // Ignore adapters not UP
7483
7584 for (auto addr_i = pCurrAddresses->FirstUnicastAddress ; addr_i != NULL ; addr_i = addr_i->Next )
7685 {
7786 const auto a = addr_i->Address .lpSockaddr ;
7887 const auto sa = (struct sockaddr_in *)a;
88+
7989 if (a->sa_family != AF_INET) continue ; // just IPv4
90+
91+ // we do no want a link-local address; we cannot bind to it. And there is no-one there
92+ if (IN4_IS_ADDR_LINKLOCAL (&sa->sin_addr ))
93+ continue ;
94+
8095 char buf[INET_ADDRSTRLEN];
8196 inet_ntop (a->sa_family , &(sa->sin_addr ), buf, sizeof (buf));
8297 // extract broadcast address for this interface
You can’t perform that action at this time.
0 commit comments