Last active
January 31, 2024 10:50
-
-
Save gvanem/57d24d69e0099886fb15 to your computer and use it in GitHub Desktop.
A simple program to enumerate the adapters found by Win10Pcap. Ref: https://github.com/SoftEtherVPN/Win10Pcap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Simple program to enumerate the adapters found by Win10Pcap. | |
* | |
* Ref: https://github.com/SoftEtherVPN/Win10Pcap | |
* | |
* Put this file in the root directory of Win10Pcap-root and do: | |
* | |
* cl -nologo -W3 -Zi -Ot -DWIN32 -DWIN32COM_CPP -MTd -GF -GS -EHsc -RTCs -RTCu -RTCc | |
* -I./Packet_dll -Fe./enum_adapters.exe enum_adapters.c | |
* -link -nologo -debug Packet.lib user32.lib ws2_32.lib version.lib | |
* winmm.lib iphlpapi.lib advapi32.lib | |
* | |
* (yes, all on one line). | |
* | |
* G. Vanem <gvanem@yahoo.no> 2015 - 2024. | |
*/ | |
#define WIN32_LEAN_AND_MEAN | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <windows.h> | |
#define USE_WIN10PCAP_STATIC | |
#include "./Packet_dll/Packet32.c" | |
static void print_sl_adapter_info_list (const char *indent, const struct SL_ADAPTER_INFO_LIST *sl); | |
static void print_sl_adapter_info (const char *indent, const struct SL_ADAPTER_INFO *info); | |
static void print_adapter_info (const char *indent, ADAPTER *a); | |
static int real_main (int argc, char **argv) | |
{ | |
SE_LIST *o; | |
SU *su; | |
UINT i; | |
printf ("PacketLibraryVersion(): %s\n", PacketLibraryVersion()); | |
printf ("PacketGetDriverVersion(): %s\n", PacketGetDriverVersion()); | |
su = OpenSuBasicAdapter(); | |
if (!su) | |
{ | |
printf ("Win10Pcap.sys driver not installed.\n"); | |
return (1); | |
} | |
print_sl_adapter_info_list (" ", &su->AdapterInfoList); | |
o = SuGetAdapterList (su); | |
for (i = 0; i < SE_LIST_NUM(o); i++) | |
{ | |
const SU_ADAPTER_LIST *d = SE_LIST_DATA (o, i); | |
char adapter_name [sizeof(SL_ADAPTER_DEVICE_NAME)+1]; | |
ADAPTER *a; | |
printf ("\nAdapter: %d\n", i); | |
printf (" Name: %.*s\n", (int)sizeof(d->Name)-1, d->Name); | |
printf (" Name_Replaced: %.*s\n", (int)sizeof(d->Name_Replaced)-1, d->Name_Replaced); | |
printf (" SortKey: %.*s\n", (int)sizeof(d->SortKey)-1, d->SortKey); | |
printf (" Guid: %.*s\n", (int)sizeof(d->Guid)-1, d->Guid); | |
print_sl_adapter_info (" ", &d->Info); | |
snprintf (adapter_name, sizeof(adapter_name), "\\Device\\%s", d->Name); | |
a = PacketOpenAdapter (adapter_name); | |
printf (" PacketOpenAdapter (\"%s\"):", adapter_name); | |
if (!a) | |
puts (" failed"); | |
else | |
{ | |
print_adapter_info (" ", a); | |
PacketCloseAdapter (a); | |
} | |
} | |
SuFree (su); | |
return (0); | |
} | |
static void print_sl_adapter_info_list (const char *indent, const struct SL_ADAPTER_INFO_LIST *sl) | |
{ | |
printf ("%sSignature: 0x%08X\n", indent, sl->Signature); | |
printf ("%sSeLowVersion: 0x%04X\n", indent, sl->SeLowVersion); | |
printf ("%sEnumCompleted: %u\n", indent, sl->EnumCompleted); | |
printf ("%sNumAdapters: %u\n", indent, sl->NumAdapters); | |
} | |
static void print_sl_adapter_info (const char *indent, const struct SL_ADAPTER_INFO *info) | |
{ | |
printf ("%sAdapterId: %.*ws\n", indent, | |
(int)(sizeof(info->AdapterId)/sizeof(info->AdapterId[0])-1), info->AdapterId); | |
//printf ("%sDeviceName: %.*ws\n", indent, (int)sizeof(info->DeviceName)-1, info->DeviceName); | |
printf ("%sMacAddress: %02X:%02X:%02X:%02X:%02X:%02X\n", indent, | |
info->MacAddress[0], info->MacAddress[1], info->MacAddress[2], | |
info->MacAddress[3], info->MacAddress[4], info->MacAddress[5]); | |
printf ("%sMtuSize: %u\n", indent, info->MtuSize); | |
printf ("%sFriendlyName: %.*s\n", indent, (int)sizeof(info->FriendlyName)-1, info->FriendlyName); | |
printf ("%sSupportsVLanHw: %d\n", indent, info->SupportsVLanHw); | |
} | |
static void print_adapter_info (const char *indent, ADAPTER *a) | |
{ | |
printf ("%sSymlink: %s\n", indent, a->SymbolicLink); | |
printf ("%shFile: %p\n", indent, a->hFile); | |
} | |
#ifdef _DEBUG | |
/* | |
* Only one global mem-state. | |
*/ | |
static _CrtMemState last_state; | |
/* | |
* In `_DEBUG`-mode, remember the `last_state` as the CRT-memory | |
* start-up state. | |
*/ | |
void crtdbug_init (void) | |
{ | |
_HFILE file = _CRTDBG_FILE_STDERR; | |
int mode = _CRTDBG_MODE_FILE; | |
int flags = _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_DELAY_FREE_MEM_DF; | |
_CrtSetReportFile (_CRT_ASSERT, file); | |
_CrtSetReportMode (_CRT_ASSERT, mode); | |
_CrtSetReportFile (_CRT_ERROR, file); | |
_CrtSetReportMode (_CRT_ERROR, mode); | |
_CrtSetReportFile (_CRT_WARN, file); | |
_CrtSetReportMode (_CRT_WARN, mode); | |
_CrtSetDbgFlag (flags | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); | |
_CrtMemCheckpoint (&last_state); | |
} | |
/** | |
* In `_DEBUG`-mode, compare the `last_state` set in `crtdbug_init()` to | |
* check if there is a significant difference in the mem-state. | |
*/ | |
void crtdbug_exit (void) | |
{ | |
_CrtMemState new_state, diff_state; | |
_CrtMemCheckpoint (&new_state); | |
/* No significant difference in the mem-state. So just get out. | |
*/ | |
if (!_CrtMemDifference(&diff_state, &last_state, &new_state)) | |
return; | |
_CrtCheckMemory(); | |
_CrtSetDbgFlag (0); | |
//_CrtMemDumpStatistics (&last_state); | |
_CrtDumpMemoryLeaks(); | |
} | |
#else | |
void crtdbug_init (void) | |
{ | |
} | |
void crtdbug_exit (void) | |
{ | |
} | |
#endif | |
int main (int argc, char **argv) | |
{ | |
int rc; | |
crtdbug_init(); | |
DllMain (NULL, DLL_PROCESS_ATTACH, NULL); | |
rc = real_main (argc, argv); | |
DllMain (NULL, DLL_PROCESS_DETACH, NULL); | |
crtdbug_exit(); | |
return (rc); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment