Skip to content

Commit

Permalink
Merge PR #1020 from Siberiawind/master
Browse files Browse the repository at this point in the history
Windows: an unexpected error occurred reports (#994)
  • Loading branch information
alalamav committed May 19, 2021
2 parents 09d7867 + d2b8e06 commit d6027f0
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tools/smartdnsblock/smartdnsblock/smartdnsblock.cpp
Expand Up @@ -35,15 +35,35 @@ ULONG GET_ADAPTERS_ADDRESSES_BUFFER_SIZE = 16384;
PCWSTR FILTER_PROVIDER_NAME = L"Outline";
PCWSTR SUBLAYER_NAME = L"Smart DNS Block";

UINT64 MAX_TRIES = 2;
UINT64 LOWER_FILTER_WEIGHT = 10;
UINT64 HIGHER_FILTER_WEIGHT = 20;

int main(int argc, char **argv) {
// Lookup the interface index of outline-tap0.
PIP_ADAPTER_ADDRESSES adaptersAddresses =
(IP_ADAPTER_ADDRESSES *)malloc(GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);
DWORD result = GetAdaptersAddresses(AF_INET, 0, NULL, adaptersAddresses,
&GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);
PIP_ADAPTER_ADDRESSES adaptersAddresses = NULL;

UINT64 count = 0;
DWORD result = 0;
do {
adaptersAddresses = (IP_ADAPTER_ADDRESSES*)malloc(GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);

// Required value will be told to GET_ADAPTERS_ADDRESSES_BUFFER_SIZE
// if GetAdaptersAddresses() returns ERROR_BUFFER_OVERFLOW:
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses#return-value
result = GetAdaptersAddresses(AF_INET, 0, NULL, adaptersAddresses,
&GET_ADAPTERS_ADDRESSES_BUFFER_SIZE);

if (result != NO_ERROR) {
wcerr << "could not fetch network device list: " << result << endl;
free(adaptersAddresses);
adaptersAddresses = NULL;
}
else {
wcout << "fetch network device list success!";
}
} while ((result == ERROR_BUFFER_OVERFLOW) && (count++ < MAX_TRIES));

if (result != NO_ERROR) {
wcerr << "could not fetch network device list: " << result << endl;
return 1;
Expand Down

0 comments on commit d6027f0

Please sign in to comment.