Skip to content

Commit 7051f02

Browse files
authored
Add discovery speedups (#10)
* Ignore any link-local address (we cannot bind to it. And there is no-one there) * Ignore adapters that are not in UP-state.
1 parent 0bd01e5 commit 7051f02

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

InterfacesWindows.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
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+
1723
std::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

0 commit comments

Comments
 (0)