260 |
|
|
261 |
|
return NULL; |
262 |
|
} |
263 |
+ |
|
264 |
+ |
|
265 |
+ |
/* |
266 |
+ |
* Get TAP-Win32 adapters |
267 |
+ |
*/ |
268 |
+ |
|
269 |
+ |
#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}" |
270 |
+ |
|
271 |
+ |
#define TAP_COMPONENT_ID "tap0801" |
272 |
+ |
|
273 |
+ |
const char *ether_tap_devices(void) |
274 |
+ |
{ |
275 |
+ |
HKEY adapter_key; |
276 |
+ |
LONG status; |
277 |
+ |
DWORD len; |
278 |
+ |
int i = 0; |
279 |
+ |
|
280 |
+ |
status = RegOpenKeyEx( |
281 |
+ |
HKEY_LOCAL_MACHINE, |
282 |
+ |
ADAPTER_KEY, |
283 |
+ |
0, |
284 |
+ |
KEY_READ, |
285 |
+ |
&adapter_key); |
286 |
+ |
|
287 |
+ |
if (status != ERROR_SUCCESS) |
288 |
+ |
return NULL; |
289 |
+ |
|
290 |
+ |
list<string> devices; |
291 |
+ |
|
292 |
+ |
while (true) { |
293 |
+ |
char enum_name[256]; |
294 |
+ |
char unit_string[256]; |
295 |
+ |
HKEY unit_key; |
296 |
+ |
char component_id_string[] = "ComponentId"; |
297 |
+ |
char component_id[256]; |
298 |
+ |
char net_cfg_instance_id_string[] = "NetCfgInstanceId"; |
299 |
+ |
char net_cfg_instance_id[256]; |
300 |
+ |
DWORD data_type; |
301 |
+ |
|
302 |
+ |
len = sizeof (enum_name); |
303 |
+ |
status = RegEnumKeyEx( |
304 |
+ |
adapter_key, |
305 |
+ |
i, |
306 |
+ |
enum_name, |
307 |
+ |
&len, |
308 |
+ |
NULL, |
309 |
+ |
NULL, |
310 |
+ |
NULL, |
311 |
+ |
NULL); |
312 |
+ |
if (status != ERROR_SUCCESS) |
313 |
+ |
break; |
314 |
+ |
|
315 |
+ |
snprintf (unit_string, sizeof(unit_string), "%s\\%s", |
316 |
+ |
ADAPTER_KEY, enum_name); |
317 |
+ |
|
318 |
+ |
status = RegOpenKeyEx( |
319 |
+ |
HKEY_LOCAL_MACHINE, |
320 |
+ |
unit_string, |
321 |
+ |
0, |
322 |
+ |
KEY_READ, |
323 |
+ |
&unit_key); |
324 |
+ |
|
325 |
+ |
if (status == ERROR_SUCCESS) { |
326 |
+ |
len = sizeof (component_id); |
327 |
+ |
status = RegQueryValueEx( |
328 |
+ |
unit_key, |
329 |
+ |
component_id_string, |
330 |
+ |
NULL, |
331 |
+ |
&data_type, |
332 |
+ |
(BYTE *)component_id, |
333 |
+ |
&len); |
334 |
+ |
|
335 |
+ |
if (status == ERROR_SUCCESS && data_type == REG_SZ) { |
336 |
+ |
len = sizeof (net_cfg_instance_id); |
337 |
+ |
status = RegQueryValueEx( |
338 |
+ |
unit_key, |
339 |
+ |
net_cfg_instance_id_string, |
340 |
+ |
NULL, |
341 |
+ |
&data_type, |
342 |
+ |
(BYTE *)net_cfg_instance_id, |
343 |
+ |
&len); |
344 |
+ |
|
345 |
+ |
if (status == ERROR_SUCCESS && data_type == REG_SZ) { |
346 |
+ |
if (!strcmp (component_id, TAP_COMPONENT_ID)) |
347 |
+ |
devices.push_back(net_cfg_instance_id); |
348 |
+ |
} |
349 |
+ |
} |
350 |
+ |
RegCloseKey (unit_key); |
351 |
+ |
} |
352 |
+ |
++i; |
353 |
+ |
} |
354 |
+ |
|
355 |
+ |
RegCloseKey (adapter_key); |
356 |
+ |
|
357 |
+ |
if (devices.empty()) |
358 |
+ |
return NULL; |
359 |
+ |
|
360 |
+ |
// The result is a '\0' separated list of strings |
361 |
+ |
list<string>::const_iterator it; |
362 |
+ |
len = 0; |
363 |
+ |
for (it = devices.begin(); it != devices.end(); it++) |
364 |
+ |
len += (*it).length() + 1; |
365 |
+ |
|
366 |
+ |
char *names = (char *)malloc(len); |
367 |
+ |
if (names) { |
368 |
+ |
char *p = names; |
369 |
+ |
for (it = devices.begin(); it != devices.end(); it++) { |
370 |
+ |
len = (*it).length(); |
371 |
+ |
strcpy(p, (*it).c_str()); |
372 |
+ |
p[len] = '\0'; |
373 |
+ |
p += len + 1; |
374 |
+ |
} |
375 |
+ |
} |
376 |
+ |
|
377 |
+ |
return names; |
378 |
+ |
} |