diff --git a/pcsx2/DEV9/net.cpp b/pcsx2/DEV9/net.cpp index 32e417c18c..6e81118aa0 100644 --- a/pcsx2/DEV9/net.cpp +++ b/pcsx2/DEV9/net.cpp @@ -67,13 +67,12 @@ NetAdapter* GetNetAdapter() case NetApi::TAP: na = static_cast(new TAPAdapter()); break; -#else +#endif case NetApi::PCAP_Switched: na = static_cast(new PCAPAdapter()); break; default: return 0; -#endif } if (!na->isInitialised()) diff --git a/pcsx2/DEV9/pcap_io.cpp b/pcsx2/DEV9/pcap_io.cpp index 5fb8865efe..30721d89aa 100644 --- a/pcsx2/DEV9/pcap_io.cpp +++ b/pcsx2/DEV9/pcap_io.cpp @@ -35,14 +35,11 @@ #define PCAP_NETMASK_UNKNOWN 0xffffffff #endif -#ifdef _WIN32 -#define mac_address char* -#else pcap_t* adhandle; pcap_dumper_t* dump_pcap; char errbuf[PCAP_ERRBUF_SIZE]; mac_address broadcast_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -#endif + int pcap_io_running = 0; extern u8 eeprom[]; @@ -114,7 +111,6 @@ int GetMACAddress(char* adapter, mac_address* addr) int pcap_io_init(char* adapter, mac_address virtual_mac) { -#ifndef _WIN32 struct bpf_program fp; char filter[1024] = "ether broadcast or ether dst "; int dlt; @@ -172,7 +168,6 @@ int pcap_io_init(char* adapter, mac_address virtual_mac) pcap_io_running = 1; Console.WriteLn("Adapter Ok."); -#endif return 0; } @@ -190,7 +185,6 @@ int gettimeofday(struct timeval* tv, void* tz) int pcap_io_send(void* packet, int plen) { -#ifndef _WIN32 if (pcap_io_running <= 0) return -1; @@ -204,13 +198,10 @@ int pcap_io_send(void* packet, int plen) } return pcap_sendpacket(adhandle, (u_char*)packet, plen); -#endif - return 0; } int pcap_io_recv(void* packet, int max_len) { -#ifndef _WIN32 static struct pcap_pkthdr* header; static const u_char* pkt_data1; @@ -226,26 +217,22 @@ int pcap_io_recv(void* packet, int max_len) return header->len; } -#endif return -1; } void pcap_io_close() { -#ifndef _WIN32 if (dump_pcap) pcap_dump_close(dump_pcap); if (adhandle) pcap_close(adhandle); pcap_io_running = 0; -#endif } int pcap_io_get_dev_num() { int i = 0; -#ifndef _WIN32 pcap_if_t* alldevs; pcap_if_t* d; @@ -263,13 +250,11 @@ int pcap_io_get_dev_num() pcap_freealldevs(alldevs); -#endif return i; } char* pcap_io_get_dev_name(int num) { -#ifndef _WIN32 pcap_if_t* alldevs; pcap_if_t* d; int i = 0; @@ -293,13 +278,11 @@ char* pcap_io_get_dev_name(int num) } pcap_freealldevs(alldevs); -#endif return NULL; } char* pcap_io_get_dev_desc(int num) { -#ifndef _WIN32 pcap_if_t* alldevs; pcap_if_t* d; int i = 0; @@ -323,7 +306,6 @@ char* pcap_io_get_dev_desc(int num) } pcap_freealldevs(alldevs); -#endif return NULL; } @@ -331,10 +313,14 @@ char* pcap_io_get_dev_desc(int num) PCAPAdapter::PCAPAdapter() : NetAdapter() { -#ifndef _WIN32 if (config.ethEnable == 0) return; +#ifdef _WIN32 + if (!load_pcap()) + return; +#endif + mac_address hostMAC; mac_address newMAC; @@ -351,9 +337,6 @@ PCAPAdapter::PCAPAdapter() { SysMessage("Can't open Device '%s'\n", config.Eth); } -#else - Console.Error("pcap not supported on windows\n"); -#endif } bool PCAPAdapter::blocks() { @@ -398,7 +381,11 @@ std::vector PCAPAdapter::GetAdapters() { std::vector nic; - #ifndef _WIN32 +#ifdef _WIN32 + if (!load_pcap()) + return nic; +#endif + pcap_if_t* alldevs; pcap_if_t* d; @@ -412,13 +399,31 @@ std::vector PCAPAdapter::GetAdapters() { AdapterEntry entry; entry.type = NetApi::PCAP_Switched; +#ifdef _WIN32 + //guid + wchar_t wEth[sizeof(config.Eth)] = {0}; + mbstowcs(wEth, d->name, sizeof(config.Eth) - 1); + entry.guid = std::wstring(wEth); + + //NPCAP 1.10 is using an version of pcap that dosn't + //allow us to set it to use UTF8 + //see https://github.com/nmap/npcap/issues/276 + //But use MultiByteToWideChar so we can later switch to UTF8 + int len_desc = strlen(d->description) + 1; + int len_buf = MultiByteToWideChar(CP_ACP, 0, d->description, len_desc, nullptr, 0); + + wchar_t* buf = new wchar_t[len_buf]; + MultiByteToWideChar(CP_ACP, 0, d->description, len_desc, buf, len_buf); + entry.name = std::wstring(buf); + delete[] buf; +#else entry.name = std::string(d->name); entry.guid = std::string(d->name); +#endif nic.push_back(entry); d = d->next; } - #endif return nic; } diff --git a/pcsx2/DEV9/pcap_io.h b/pcsx2/DEV9/pcap_io.h index 556f66ef45..669c10c604 100644 --- a/pcsx2/DEV9/pcap_io.h +++ b/pcsx2/DEV9/pcap_io.h @@ -14,9 +14,7 @@ */ #pragma once -#if !defined(_WIN32) #include "pcap.h" -#endif #include "net.h" #ifdef __cplusplus @@ -24,7 +22,7 @@ extern "C" { #endif -#ifndef _WIN32 +//#ifndef _WIN32 #pragma pack(push, 1) typedef struct _ip_address { @@ -156,7 +154,7 @@ extern mac_address broadcast_mac; #define mac_compare(a, b) (memcmp(&(a), &(b), 6)) #define ip_compare(a, b) (memcmp(&(a), &(b), 4)) -#endif +//#endif /* int pcap_io_init(char *adapter); int pcap_io_send(void* packet, int plen);