Skip to content

Commit

Permalink
No longer using pcap_dispatch for receiving network packets.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikechambers84 committed Jul 29, 2021
1 parent 402797d commit 7cc495c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
3 changes: 0 additions & 3 deletions XTulator/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ int main(int argc, char *argv[]) {
}


#ifdef USE_NE2000
pcap_rxPacket();
#endif
curloop = 0;
}
}
Expand Down
26 changes: 6 additions & 20 deletions XTulator/modules/io/pcap-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ pthread_t pcap_dispatchThreadID;
#include "ne2000.h"
#include "pcap-win32.h"

volatile uint8_t pcap_havePacket = 0;
pcap_t* pcap_adhandle;

volatile u_char pcap_packetData[2048];
volatile uint32_t pcap_len = 0;

NE2000_t* pcap_ne2000 = NULL;

void pcap_listdevs() {
Expand Down Expand Up @@ -118,6 +114,8 @@ int pcap_init(NE2000_t* ne2000, int dev) {

pcap_ne2000 = ne2000;



#ifdef _WIN32
_beginthread((void*)pcap_dispatchThread, 0, NULL);
#else
Expand All @@ -128,31 +126,19 @@ int pcap_init(NE2000_t* ne2000, int dev) {
}

void pcap_dispatchThread() {
while (running) {
pcap_loop(pcap_adhandle, 0, pcap_rx_handler, NULL);
/*while (running) {
pcap_dispatch(pcap_adhandle, 1, pcap_rx_handler, NULL);
if (pcap_havePacket == 0) {
utility_sleep(1);
}
}
}*/
}

void pcap_rx_handler(u_char* param, const struct pcap_pkthdr* header, const u_char* pkt_data) {
(void)(param); //unused variable

while (pcap_havePacket) {}

pcap_len = header->caplen;
if (pcap_len > 2048) return;
memcpy((void*)pcap_packetData, pkt_data, header->caplen);
pcap_havePacket = 1;
//debug_log(DEBUG_INFO, "len:%d\n", header->len);
}

void pcap_rxPacket() {
if (pcap_havePacket) {
ne2000_rx_frame(pcap_ne2000, (void*)pcap_packetData, pcap_len);
pcap_havePacket = 0;
}
ne2000_rx_frame(pcap_ne2000, (void*)pkt_data, header->caplen);
}

void pcap_txPacket(u_char* data, int len) {
Expand Down
3 changes: 0 additions & 3 deletions XTulator/modules/io/pcap-win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ void pcap_rx_handler(u_char* param, const struct pcap_pkthdr* header, const u_ch
void pcap_listdevs();
int pcap_init(NE2000_t* ne2000, int dev);
void pcap_dispatchThread();
void pcap_rxPacket();
void pcap_txPacket(u_char* data, int len);

extern volatile uint8_t pcap_havePacket;

#endif //USE_NE2000

#endif //_PCAP_WIN32_H_

0 comments on commit 7cc495c

Please sign in to comment.