Browse Source

Fix Windows build: wintun function pointer declarations

- Add * to Wintun function pointer declarations (wintun.h defines types as functions)
- Use (void *) cast in GetProcAddress to avoid errors
- All 22 tests pass on Linux
nodeinfo-routing-update
Evgeny 8 months ago
parent
commit
84e6d59d77
  1. 48
      src/tun_windows.c

48
src/tun_windows.c

@ -11,19 +11,19 @@
#include <iphlpapi.h>
#include <ws2tcpip.h>
// Wintun function pointers (using function pointer syntax)
// Wintun function pointers (wintun.h defines types as functions, need pointer syntax)
static HMODULE wintun_dll = NULL;
static WINTUN_CREATE_ADAPTER_FUNC WintunCreateAdapter = NULL;
static WINTUN_CLOSE_ADAPTER_FUNC WintunCloseAdapter = NULL;
static WINTUN_OPEN_ADAPTER_FUNC WintunOpenAdapter = NULL;
static WINTUN_GET_ADAPTER_LUID_FUNC WintunGetAdapterLUID = NULL;
static WINTUN_START_SESSION_FUNC WintunStartSession = NULL;
static WINTUN_END_SESSION_FUNC WintunEndSession = NULL;
static WINTUN_GET_READ_WAIT_EVENT_FUNC WintunGetReadWaitEvent = NULL;
static WINTUN_RECEIVE_PACKET_FUNC WintunReceivePacket = NULL;
static WINTUN_RELEASE_RECEIVE_PACKET_FUNC WintunReleaseReceivePacket = NULL;
static WINTUN_ALLOCATE_SEND_PACKET_FUNC WintunAllocateSendPacket = NULL;
static WINTUN_SEND_PACKET_FUNC WintunSendPacket = NULL;
static WINTUN_CREATE_ADAPTER_FUNC *WintunCreateAdapter = NULL;
static WINTUN_CLOSE_ADAPTER_FUNC *WintunCloseAdapter = NULL;
static WINTUN_OPEN_ADAPTER_FUNC *WintunOpenAdapter = NULL;
static WINTUN_GET_ADAPTER_LUID_FUNC *WintunGetAdapterLUID = NULL;
static WINTUN_START_SESSION_FUNC *WintunStartSession = NULL;
static WINTUN_END_SESSION_FUNC *WintunEndSession = NULL;
static WINTUN_GET_READ_WAIT_EVENT_FUNC *WintunGetReadWaitEvent = NULL;
static WINTUN_RECEIVE_PACKET_FUNC *WintunReceivePacket = NULL;
static WINTUN_RELEASE_RECEIVE_PACKET_FUNC *WintunReleaseReceivePacket = NULL;
static WINTUN_ALLOCATE_SEND_PACKET_FUNC *WintunAllocateSendPacket = NULL;
static WINTUN_SEND_PACKET_FUNC *WintunSendPacket = NULL;
// Load Wintun.dll and resolve function pointers
static int wintun_load_dll(void) {
@ -68,18 +68,18 @@ static int wintun_load_dll(void) {
return -1;
}
// Resolve function pointers
WintunCreateAdapter = (WINTUN_CREATE_ADAPTER_FUNC)GetProcAddress(wintun_dll, "WintunCreateAdapter");
WintunCloseAdapter = (WINTUN_CLOSE_ADAPTER_FUNC)GetProcAddress(wintun_dll, "WintunCloseAdapter");
WintunOpenAdapter = (WINTUN_OPEN_ADAPTER_FUNC)GetProcAddress(wintun_dll, "WintunOpenAdapter");
WintunGetAdapterLUID = (WINTUN_GET_ADAPTER_LUID_FUNC)GetProcAddress(wintun_dll, "WintunGetAdapterLUID");
WintunStartSession = (WINTUN_START_SESSION_FUNC)GetProcAddress(wintun_dll, "WintunStartSession");
WintunEndSession = (WINTUN_END_SESSION_FUNC)GetProcAddress(wintun_dll, "WintunEndSession");
WintunGetReadWaitEvent = (WINTUN_GET_READ_WAIT_EVENT_FUNC)GetProcAddress(wintun_dll, "WintunGetReadWaitEvent");
WintunReceivePacket = (WINTUN_RECEIVE_PACKET_FUNC)GetProcAddress(wintun_dll, "WintunReceivePacket");
WintunReleaseReceivePacket = (WINTUN_RELEASE_RECEIVE_PACKET_FUNC)GetProcAddress(wintun_dll, "WintunReleaseReceivePacket");
WintunAllocateSendPacket = (WINTUN_ALLOCATE_SEND_PACKET_FUNC)GetProcAddress(wintun_dll, "WintunAllocateSendPacket");
WintunSendPacket = (WINTUN_SEND_PACKET_FUNC)GetProcAddress(wintun_dll, "WintunSendPacket");
// Resolve function pointers (cast to void* first to avoid errors)
WintunCreateAdapter = (WINTUN_CREATE_ADAPTER_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunCreateAdapter");
WintunCloseAdapter = (WINTUN_CLOSE_ADAPTER_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunCloseAdapter");
WintunOpenAdapter = (WINTUN_OPEN_ADAPTER_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunOpenAdapter");
WintunGetAdapterLUID = (WINTUN_GET_ADAPTER_LUID_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunGetAdapterLUID");
WintunStartSession = (WINTUN_START_SESSION_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunStartSession");
WintunEndSession = (WINTUN_END_SESSION_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunEndSession");
WintunGetReadWaitEvent = (WINTUN_GET_READ_WAIT_EVENT_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunGetReadWaitEvent");
WintunReceivePacket = (WINTUN_RECEIVE_PACKET_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunReceivePacket");
WintunReleaseReceivePacket = (WINTUN_RELEASE_RECEIVE_PACKET_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunReleaseReceivePacket");
WintunAllocateSendPacket = (WINTUN_ALLOCATE_SEND_PACKET_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunAllocateSendPacket");
WintunSendPacket = (WINTUN_SEND_PACKET_FUNC *)(void *)GetProcAddress(wintun_dll, "WintunSendPacket");
// Check that all functions were resolved
if (!WintunCreateAdapter || !WintunCloseAdapter || !WintunOpenAdapter ||

Loading…
Cancel
Save