- Ethernet Socket (Windows): fixed bug and added workaround for problem

on Windows (most GOOSE/SV messages are not received when waiting with
WaitForMultipleObjects - observed with winpcap 4.1.3 and Windows 10
pull/331/head
Michael Zillgith 4 years ago
parent ef1895c2be
commit 40b8f99201

@ -33,6 +33,9 @@
#define DEBUG_HAL_ETHERNET 1 #define DEBUG_HAL_ETHERNET 1
#endif #endif
// Set to 1 to workaround WaitForMutlipleObjects problem (returns timeout even when packets are received)
#define ETHERNET_WIN32_DISABLE_ETHERNET_HANDLESET 1
#if (CONFIG_INCLUDE_ETHERNET_WINDOWS == 1) #if (CONFIG_INCLUDE_ETHERNET_WINDOWS == 1)
@ -137,6 +140,8 @@ EthernetHandleSet_new(void)
void void
EthernetHandleSet_addSocket(EthernetHandleSet self, const EthernetSocket sock) EthernetHandleSet_addSocket(EthernetHandleSet self, const EthernetSocket sock)
{ {
#if ETHERNET_WIN32_DISABLE_ETHERNET_HANDLESET == 1
#else
if (self != NULL && sock != NULL) { if (self != NULL && sock != NULL) {
int i = self->nhandles++; int i = self->nhandles++;
@ -145,11 +150,14 @@ EthernetHandleSet_addSocket(EthernetHandleSet self, const EthernetSocket sock)
self->handles[i] = pcap_getevent(sock->rawSocket); self->handles[i] = pcap_getevent(sock->rawSocket);
} }
#endif
} }
void void
EthernetHandleSet_removeSocket(EthernetHandleSet self, const EthernetSocket sock) EthernetHandleSet_removeSocket(EthernetHandleSet self, const EthernetSocket sock)
{ {
#if ETHERNET_WIN32_DISABLE_ETHERNET_HANDLESET == 1
#else
if ((self != NULL) && (sock != NULL)) { if ((self != NULL) && (sock != NULL)) {
HANDLE h = pcap_getevent(sock->rawSocket); HANDLE h = pcap_getevent(sock->rawSocket);
@ -163,21 +171,33 @@ EthernetHandleSet_removeSocket(EthernetHandleSet self, const EthernetSocket sock
} }
} }
} }
#endif
} }
int int
EthernetHandleSet_waitReady(EthernetHandleSet self, unsigned int timeoutMs) EthernetHandleSet_waitReady(EthernetHandleSet self, unsigned int timeoutMs)
{ {
#if ETHERNET_WIN32_DISABLE_ETHERNET_HANDLESET == 1
return 1;
#else
int result; int result;
if ((self != NULL) && (self->nhandles > 0)) { if ((self != NULL) && (self->nhandles > 0)) {
result = WaitForMultipleObjects(self->nhandles, self->handles, 0, timeoutMs); DWORD ret = WaitForMultipleObjects(self->nhandles, self->handles, 0, timeoutMs);
if (ret == WAIT_TIMEOUT)
result = 0;
else if (ret == WAIT_FAILED)
result = -1;
else
result = (int)ret;
} }
else { else {
result = -1; result = -1;
} }
return result; return result;
#endif
} }
void void
@ -328,7 +348,7 @@ Ethernet_createSocket(const char* interfaceId, uint8_t* destAddress)
char* interfaceName = getInterfaceName(interfaceIndex); char* interfaceName = getInterfaceName(interfaceIndex);
if ((pcapSocket = pcap_open_live(interfaceName, 65536, PCAP_OPENFLAG_PROMISCUOUS, 10, errbuf)) == NULL) if ((pcapSocket = pcap_open_live(interfaceName, 65536, PCAP_OPENFLAG_PROMISCUOUS, 1, errbuf)) == NULL)
{ {
printf("Open ethernet socket failed for device %s\n", interfaceName); printf("Open ethernet socket failed for device %s\n", interfaceName);
free(interfaceName); free(interfaceName);

@ -21,6 +21,7 @@
* See COPYING file for the complete license text. * See COPYING file for the complete license text.
*/ */
#define __STDC_FORMAT_MACROS 1
#include "stack_config.h" #include "stack_config.h"
#include <inttypes.h> #include <inttypes.h>
@ -356,9 +357,12 @@ parseASDU(SVReceiver self, SVSubscriber subscriber, uint8_t* buffer, int length)
if (SVSubscriber_ASDU_hasDatSet(&asdu)) if (SVSubscriber_ASDU_hasDatSet(&asdu))
printf("SV_SUBSCRIBER: DatSet: %s\n", asdu.datSet); printf("SV_SUBSCRIBER: DatSet: %s\n", asdu.datSet);
#ifdef PRIu64
if (SVSubscriber_ASDU_hasRefrTm(&asdu)) if (SVSubscriber_ASDU_hasRefrTm(&asdu))
#ifndef _MSC_VER
printf("SV_SUBSCRIBER: RefrTm[ns]: %"PRIu64"\n", SVSubscriber_ASDU_getRefrTmAsNs(&asdu)); printf("SV_SUBSCRIBER: RefrTm[ns]: %"PRIu64"\n", SVSubscriber_ASDU_getRefrTmAsNs(&asdu));
#else
printf("SV_SUBSCRIBER: RefrTm[ns]: %llu\n", SVSubscriber_ASDU_getRefrTmAsNs(&asdu));
#endif #endif
if (SVSubscriber_ASDU_hasSmpMod(&asdu)) if (SVSubscriber_ASDU_hasSmpMod(&asdu))
printf("SV_SUBSCRIBER: SmpMod: %d\n", SVSubscriber_ASDU_getSmpMod(&asdu)); printf("SV_SUBSCRIBER: SmpMod: %d\n", SVSubscriber_ASDU_getSmpMod(&asdu));

Loading…
Cancel
Save