MCPcopy Create free account
hub / github.com/YtFlow/Maple / EnumerateInterfaces

Method EnumerateInterfaces

Maple.App/Model/Netif.cpp:89–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87 }
88
89 std::vector<Maple_App::Netif> Netif::EnumerateInterfaces() {
90
91 /* Declare and initialize variables */
92
93 DWORD dwRetVal = 0;
94
95 unsigned int i = 0;
96
97 // Set the flags to pass to GetAdaptersAddresses
98 ULONG flags =
99 GAA_FLAG_SKIP_ANYCAST
100 | GAA_FLAG_SKIP_MULTICAST
101 | GAA_FLAG_SKIP_DNS_SERVER
102 | GAA_FLAG_SKIP_FRIENDLY_NAME;
103
104 // default to unspecified address family (both)
105 ULONG family = AF_UNSPEC;
106
107
108 PIP_ADAPTER_ADDRESSES pAddresses = NULL;
109 ULONG outBufLen = 0;
110 ULONG Iterations = 0;
111
112 PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
113 PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
114
115 // Allocate a 15 KB buffer to start with.
116 outBufLen = WORKING_BUFFER_SIZE;
117 std::array<WCHAR, ADDR_BUFFER_SIZE> addrBuf{};
118 auto sniffed = Netif::SniffBestInterface();
119
120 do {
121
122 pAddresses = (IP_ADAPTER_ADDRESSES*)MALLOC(outBufLen);
123 if (pAddresses == NULL) {
124 throw std::bad_alloc{};
125 }
126
127 dwRetVal =
128 GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
129
130 if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
131 FREE(pAddresses);
132 pAddresses = NULL;
133 }
134 else {
135 break;
136 }
137
138 Iterations++;
139
140 } while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (Iterations < MAX_TRIES));
141
142 if (dwRetVal != NO_ERROR) {
143 if (pAddresses) {
144 FREE(pAddresses);
145 }
146

Callers

nothing calls this directly

Calls 1

dataMethod · 0.80

Tested by

no test coverage detected