Check if WinPcap initialised correctly

Don't start the RX thread if it hasn't.

Also additional null checks to prevent crashes.
This commit is contained in:
TheLastRar 2015-11-14 14:25:34 +00:00
parent 4eb57cde0e
commit 11e67c9db0
7 changed files with 30 additions and 4 deletions

View File

@ -175,16 +175,25 @@ UINT DEV9ThreadProc() {
}*/
NetAdapter* GetNetAdapter()
{
NetAdapter* na;
if(config.Eth[0]=='p')
{
return new PCAPAdapter();
na = new PCAPAdapter();
}
else if (config.Eth[0]=='t')
{
return new TAPAdapter();
na = new TAPAdapter();
}
else
return 0;
if (!na->isInitialised())
{
delete na;
return 0;
}
return na;
}
s32 _DEV9open()
{

View File

@ -42,6 +42,7 @@ DWORD WINAPI NetRxThread(LPVOID lpThreadParameter)
void tx_put(NetPacket* pkt)
{
if (nif!=NULL)
nif->send(pkt);
//pkt must be copied if its not processed by here, since it can be allocated on the callers stack
}
@ -65,5 +66,6 @@ void TermNet()
emu_printf(".done\n");
delete nif;
nif = NULL;
}
}

View File

@ -34,6 +34,7 @@ class NetAdapter
{
public:
virtual bool blocks()=0;
virtual bool isInitialised() = 0;
virtual bool recv(NetPacket* pkt)=0; //gets a packet
virtual bool send(NetPacket* pkt)=0; //sends the packet and deletes it when done
virtual ~NetAdapter(){}

View File

@ -168,6 +168,7 @@ class PCAPAdapter : public NetAdapter
public:
PCAPAdapter();
virtual bool blocks();
virtual bool isInitialised();
//gets a packet.rv :true success
virtual bool recv(NetPacket* pkt);
//sends the packet and deletes it when done (if successful).rv :true success

View File

@ -381,6 +381,10 @@ bool TAPAdapter::blocks()
{
return true; //we use blocking io
}
bool TAPAdapter::isInitialised()
{
return (htap != NULL);
}
u8 broadcast_adddrrrr[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
//gets a packet.rv :true success
bool TAPAdapter::recv(NetPacket* pkt)

View File

@ -31,6 +31,7 @@ class TAPAdapter : public NetAdapter
public:
TAPAdapter();
virtual bool blocks();
virtual bool isInitialised();
//gets a packet.rv :true success
virtual bool recv(NetPacket* pkt);
//sends the packet and deletes it when done (if successful).rv :true success

View File

@ -117,10 +117,13 @@ int pcap_io_init(char *adapter)
errbuf // error buffer
)) == NULL)
{
fprintf(stderr, errbuf);
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", adapter);
return -1;
}
dlt = pcap_datalink(adhandle);
dlt_name = (char*)pcap_datalink_val_to_name(dlt);
@ -326,6 +329,7 @@ void pcap_io_close()
fclose(packet_log);
if(dump_pcap)
pcap_dump_close(dump_pcap);
if (adhandle)
pcap_close(adhandle);
pcap_io_running=0;
}
@ -429,6 +433,10 @@ bool PCAPAdapter::blocks()
{
return false;
}
bool PCAPAdapter::isInitialised()
{
return pcap_io_running;
}
//gets a packet.rv :true success
bool PCAPAdapter::recv(NetPacket* pkt)
{