mirror of https://github.com/PCSX2/pcsx2.git
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:
parent
4eb57cde0e
commit
11e67c9db0
|
@ -175,16 +175,25 @@ UINT DEV9ThreadProc() {
|
||||||
}*/
|
}*/
|
||||||
NetAdapter* GetNetAdapter()
|
NetAdapter* GetNetAdapter()
|
||||||
{
|
{
|
||||||
|
NetAdapter* na;
|
||||||
if(config.Eth[0]=='p')
|
if(config.Eth[0]=='p')
|
||||||
{
|
{
|
||||||
return new PCAPAdapter();
|
na = new PCAPAdapter();
|
||||||
}
|
}
|
||||||
else if (config.Eth[0]=='t')
|
else if (config.Eth[0]=='t')
|
||||||
{
|
{
|
||||||
return new TAPAdapter();
|
na = new TAPAdapter();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (!na->isInitialised())
|
||||||
|
{
|
||||||
|
delete na;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return na;
|
||||||
}
|
}
|
||||||
s32 _DEV9open()
|
s32 _DEV9open()
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,8 @@ DWORD WINAPI NetRxThread(LPVOID lpThreadParameter)
|
||||||
|
|
||||||
void tx_put(NetPacket* pkt)
|
void tx_put(NetPacket* pkt)
|
||||||
{
|
{
|
||||||
nif->send(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
|
//pkt must be copied if its not processed by here, since it can be allocated on the callers stack
|
||||||
}
|
}
|
||||||
void InitNet(NetAdapter* ad)
|
void InitNet(NetAdapter* ad)
|
||||||
|
@ -65,5 +66,6 @@ void TermNet()
|
||||||
emu_printf(".done\n");
|
emu_printf(".done\n");
|
||||||
|
|
||||||
delete nif;
|
delete nif;
|
||||||
|
nif = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,6 +34,7 @@ class NetAdapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool blocks()=0;
|
virtual bool blocks()=0;
|
||||||
|
virtual bool isInitialised() = 0;
|
||||||
virtual bool recv(NetPacket* pkt)=0; //gets a packet
|
virtual bool recv(NetPacket* pkt)=0; //gets a packet
|
||||||
virtual bool send(NetPacket* pkt)=0; //sends the packet and deletes it when done
|
virtual bool send(NetPacket* pkt)=0; //sends the packet and deletes it when done
|
||||||
virtual ~NetAdapter(){}
|
virtual ~NetAdapter(){}
|
||||||
|
|
|
@ -168,6 +168,7 @@ class PCAPAdapter : public NetAdapter
|
||||||
public:
|
public:
|
||||||
PCAPAdapter();
|
PCAPAdapter();
|
||||||
virtual bool blocks();
|
virtual bool blocks();
|
||||||
|
virtual bool isInitialised();
|
||||||
//gets a packet.rv :true success
|
//gets a packet.rv :true success
|
||||||
virtual bool recv(NetPacket* pkt);
|
virtual bool recv(NetPacket* pkt);
|
||||||
//sends the packet and deletes it when done (if successful).rv :true success
|
//sends the packet and deletes it when done (if successful).rv :true success
|
||||||
|
|
|
@ -381,6 +381,10 @@ bool TAPAdapter::blocks()
|
||||||
{
|
{
|
||||||
return true; //we use blocking io
|
return true; //we use blocking io
|
||||||
}
|
}
|
||||||
|
bool TAPAdapter::isInitialised()
|
||||||
|
{
|
||||||
|
return (htap != NULL);
|
||||||
|
}
|
||||||
u8 broadcast_adddrrrr[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
|
u8 broadcast_adddrrrr[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
|
||||||
//gets a packet.rv :true success
|
//gets a packet.rv :true success
|
||||||
bool TAPAdapter::recv(NetPacket* pkt)
|
bool TAPAdapter::recv(NetPacket* pkt)
|
||||||
|
|
|
@ -31,6 +31,7 @@ class TAPAdapter : public NetAdapter
|
||||||
public:
|
public:
|
||||||
TAPAdapter();
|
TAPAdapter();
|
||||||
virtual bool blocks();
|
virtual bool blocks();
|
||||||
|
virtual bool isInitialised();
|
||||||
//gets a packet.rv :true success
|
//gets a packet.rv :true success
|
||||||
virtual bool recv(NetPacket* pkt);
|
virtual bool recv(NetPacket* pkt);
|
||||||
//sends the packet and deletes it when done (if successful).rv :true success
|
//sends the packet and deletes it when done (if successful).rv :true success
|
||||||
|
|
|
@ -117,10 +117,13 @@ int pcap_io_init(char *adapter)
|
||||||
errbuf // error buffer
|
errbuf // error buffer
|
||||||
)) == NULL)
|
)) == NULL)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, errbuf);
|
||||||
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", adapter);
|
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", adapter);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dlt = pcap_datalink(adhandle);
|
dlt = pcap_datalink(adhandle);
|
||||||
dlt_name = (char*)pcap_datalink_val_to_name(dlt);
|
dlt_name = (char*)pcap_datalink_val_to_name(dlt);
|
||||||
|
|
||||||
|
@ -326,7 +329,8 @@ void pcap_io_close()
|
||||||
fclose(packet_log);
|
fclose(packet_log);
|
||||||
if(dump_pcap)
|
if(dump_pcap)
|
||||||
pcap_dump_close(dump_pcap);
|
pcap_dump_close(dump_pcap);
|
||||||
pcap_close(adhandle);
|
if (adhandle)
|
||||||
|
pcap_close(adhandle);
|
||||||
pcap_io_running=0;
|
pcap_io_running=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,6 +433,10 @@ bool PCAPAdapter::blocks()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool PCAPAdapter::isInitialised()
|
||||||
|
{
|
||||||
|
return pcap_io_running;
|
||||||
|
}
|
||||||
//gets a packet.rv :true success
|
//gets a packet.rv :true success
|
||||||
bool PCAPAdapter::recv(NetPacket* pkt)
|
bool PCAPAdapter::recv(NetPacket* pkt)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue