diff --git a/src/hal/ethernet/win32/ethernet_win32.c b/src/hal/ethernet/win32/ethernet_win32.c index dddbaf40..e7e91100 100644 --- a/src/hal/ethernet/win32/ethernet_win32.c +++ b/src/hal/ethernet/win32/ethernet_win32.c @@ -47,6 +47,8 @@ #define HAVE_REMOTE +// Enable WinPcap specific extension: pcap_getevent() +#define WPCAP #include "pcap.h" struct sEthernetSocket { @@ -54,6 +56,11 @@ struct sEthernetSocket { struct bpf_program etherTypeFilter; }; +struct sEthernetHandleSet { + HANDLE *handles; + int nhandles; +}; + #ifdef __GNUC__ /* detect MINGW */ #ifndef __MINGW64_VERSION_MAJOR @@ -90,7 +97,6 @@ typedef ULONG (WINAPI* pgetadaptersaddresses)(ULONG family, ULONG flags, PVOID r static pgetadaptersaddresses GetAdaptersAddresses; - static bool dllLoaded = false; static void @@ -115,6 +121,54 @@ loadDLLs(void) #endif /* __GNUC__ */ +EthernetHandleSet +EthernetHandleSet_new(void) +{ + EthernetHandleSet result = (EthernetHandleSet) GLOBAL_MALLOC(sizeof(struct sEthernetHandleSet)); + + if (result != NULL) { + result->handles = NULL; + result->nhandles = 0; + } + + return result; +} + +void +EthernetHandleSet_addSocket(EthernetHandleSet self, const EthernetSocket sock) +{ + if (self != NULL && sock != NULL) { + int i = self->nhandles++; + self->handles = (HANDLE *) realloc(self->handles, self->nhandles * sizeof(HANDLE)); + + self->handles[i] = pcap_getevent(sock->rawSocket); + } +} + +int +EthernetHandleSet_waitReady(EthernetHandleSet self, unsigned int timeoutMs) +{ + int result; + + if ((self != NULL) && (self->nhandles > 0)) { + result = WaitForMultipleObjects(self->nhandles, self->handles, 0, timeoutMs); + } + else { + result = -1; + } + + return result; +} + +void +EthernetHandleSet_destroy(EthernetHandleSet self) +{ + if (self->handles) + free(self->handles); + + GLOBAL_FREEMEM(self); +} + static char* getInterfaceName(int interfaceIndex) { @@ -215,8 +269,6 @@ getAdapterMacAddress(char* pcapAdapterName, uint8_t* macAddress) } } - - void Ethernet_getInterfaceMACAddress(const char* interfaceId, uint8_t* addr) { @@ -338,6 +390,28 @@ Ethernet_isSupported() return false; } +EthernetHandleSet +EthernetHandleSet_new(void) +{ + return NULL; +} + +void +EthernetHandleSet_addSocket(EthernetHandleSet self, const EthernetSocket sock) +{ +} + +int +EthernetHandleSet_waitReady(EthernetHandleSet self, unsigned int timeoutMs) +{ + return 0; +} + +void +EthernetHandleSet_destroy(EthernetHandleSet self) +{ +} + void Ethernet_getInterfaceMACAddress(const char* interfaceId, uint8_t* addr) {