Uthernet: check pcap_dispatch() for -ve (error) result too (#1095)

This commit is contained in:
tomcw 2022-04-29 21:03:25 +01:00
parent 93ea5b3e60
commit a5c41dd8ca

View File

@ -64,6 +64,7 @@ typedef int (*pcap_findalldevs_t)(pcap_if_t **, char *);
typedef void (*pcap_freealldevs_t)(pcap_if_t *);
typedef int (*pcap_sendpacket_t)(pcap_t *p, u_char *buf, int size);
typedef const char *(*pcap_lib_version_t)(void);
typedef char* (*pcap_geterr_t)(pcap_t* p);
static pcap_open_live_t p_pcap_open_live;
static pcap_close_t p_pcap_close;
@ -74,6 +75,7 @@ static pcap_freealldevs_t p_pcap_freealldevs;
static pcap_sendpacket_t p_pcap_sendpacket;
static pcap_datalink_t p_pcap_datalink;
static pcap_lib_version_t p_pcap_lib_version;
static pcap_geterr_t p_pcap_geterr;
static HINSTANCE pcap_library = NULL;
@ -95,6 +97,7 @@ void TfePcapFreeLibrary(void)
p_pcap_sendpacket = NULL;
p_pcap_datalink = NULL;
p_pcap_lib_version = NULL;
p_pcap_geterr = NULL;
}
}
@ -135,6 +138,7 @@ BOOL TfePcapLoadLibrary(void)
GET_PROC_ADDRESS_AND_TEST(pcap_sendpacket);
GET_PROC_ADDRESS_AND_TEST(pcap_datalink);
GET_PROC_ADDRESS_AND_TEST(pcap_lib_version);
GET_PROC_ADDRESS_AND_TEST(pcap_geterr);
LogOutput("%s\n", p_pcap_lib_version());
LogFileOutput("%s\n", p_pcap_lib_version());
}
@ -156,6 +160,7 @@ BOOL TfePcapLoadLibrary(void)
#define p_pcap_sendpacket pcap_sendpacket
#define p_pcap_datalink pcap_datalink
#define p_pcap_lib_version pcap_lib_version
#define p_pcap_geterr pcap_geterr
static BOOL TfePcapLoadLibrary(void)
{
@ -451,17 +456,23 @@ void TfePcapPacketHandler(u_char *param, const struct pcap_pkthdr *header, const
static
int tfe_arch_receive_frame(pcap_t * TfePcapFP, TFE_PCAP_INTERNAL *pinternal)
{
int ret = -1;
const char* error = "";
/* check if there is something to receive */
/* RGJ changed from void to u_char for AppleWin */
if ((*p_pcap_dispatch)(TfePcapFP, 1, TfePcapPacketHandler, (u_char *)pinternal)!=0) {
/* RGJ changed from void to u_char for AppleWin */
int ret = (*p_pcap_dispatch)(TfePcapFP, 1, TfePcapPacketHandler, (u_char*)pinternal);
if (ret > 0) {
/* Something has been received */
ret = pinternal->rxlength;
}
else { // GH#1095: -ve values are errors
if (ret == -1)
error = (*p_pcap_geterr)(TfePcapFP); // "return the error text pertaining to the last pcap library error."
ret = -1;
}
#ifdef TFE_DEBUG_ARCH
if(g_fh) fprintf( g_fh, "tfe_arch_receive_frame() called, returns %d.\n", ret );
if(g_fh) fprintf( g_fh, "tfe_arch_receive_frame() called, returns %d (%s).\n", ret, error );
#endif
return ret;