diff --git a/pcsx2/DEV9/DEV9.cpp b/pcsx2/DEV9/DEV9.cpp index 27228d5247..e72ad17eb4 100644 --- a/pcsx2/DEV9/DEV9.cpp +++ b/pcsx2/DEV9/DEV9.cpp @@ -1090,26 +1090,10 @@ void ApplyConfigIfRunning(Config oldConfig) return; //Eth - if (config.ethEnable) - { - if (oldConfig.ethEnable) - { - //Reload Net if adapter changed - if (strcmp(oldConfig.Eth, config.Eth) != 0 || - oldConfig.EthApi != config.EthApi) - { - TermNet(); - InitNet(); - } - } - else - InitNet(); - } - else if (oldConfig.ethEnable) - TermNet(); + ReconfigureLiveNet(&oldConfig); - //Hdd - //Hdd Validate Path + //Hdd + //Hdd Validate Path #ifdef _WIN32 ghc::filesystem::path hddPath(std::wstring(config.Hdd)); #else diff --git a/pcsx2/DEV9/DEV9.h b/pcsx2/DEV9/DEV9.h index 86c1782ca7..eceba30695 100644 --- a/pcsx2/DEV9/DEV9.h +++ b/pcsx2/DEV9/DEV9.h @@ -56,7 +56,7 @@ bool rx_fifo_can_rx(); #define HDD_MIN_GB 8 #define HDD_MAX_GB 120 -typedef struct +struct Config { char Eth[256]; NetApi EthApi; @@ -69,7 +69,7 @@ typedef struct int hddEnable; int ethEnable; -} Config; +}; EXTERN Config config; diff --git a/pcsx2/DEV9/Win32/tap-win32.cpp b/pcsx2/DEV9/Win32/tap-win32.cpp index c5032f3577..03162ffaab 100644 --- a/pcsx2/DEV9/Win32/tap-win32.cpp +++ b/pcsx2/DEV9/Win32/tap-win32.cpp @@ -665,6 +665,17 @@ bool TAPAdapter::send(NetPacket* pkt) else return false; } + +void TAPAdapter::reloadSettings() +{ + IP_ADAPTER_ADDRESSES adapter; + std::unique_ptr buffer; + if (TAPGetWin32Adapter(config.Eth, &adapter, &buffer)) + ReloadInternalServer(&adapter); + else + ReloadInternalServer(nullptr); +} + void TAPAdapter::close() { SetEvent(cancel); diff --git a/pcsx2/DEV9/Win32/tap.h b/pcsx2/DEV9/Win32/tap.h index 4e9e2885f9..00ee17954d 100644 --- a/pcsx2/DEV9/Win32/tap.h +++ b/pcsx2/DEV9/Win32/tap.h @@ -34,6 +34,7 @@ public: virtual bool recv(NetPacket* pkt); //sends the packet and deletes it when done (if successful).rv :true success virtual bool send(NetPacket* pkt); + virtual void reloadSettings(); virtual void close(); virtual ~TAPAdapter(); static std::vector GetAdapters(); diff --git a/pcsx2/DEV9/net.cpp b/pcsx2/DEV9/net.cpp index d5bcb03d9a..bb3aac21b6 100644 --- a/pcsx2/DEV9/net.cpp +++ b/pcsx2/DEV9/net.cpp @@ -121,6 +121,31 @@ void InitNet() #endif } +void ReconfigureLiveNet(Config* oldConfig) +{ + //Eth + if (config.ethEnable) + { + if (oldConfig->ethEnable) + { + //Reload Net if adapter changed + if (strcmp(oldConfig->Eth, config.Eth) != 0 || + oldConfig->EthApi != config.EthApi) + { + TermNet(); + InitNet(); + return; + } + else + nif->reloadSettings(); + } + else + InitNet(); + } + else if (oldConfig->ethEnable) + TermNet(); +} + void TermNet() { if (RxRunning) @@ -257,6 +282,16 @@ void NetAdapter::InitInternalServer(ifaddrs* adapter) } } +#ifdef _WIN32 +void NetAdapter::ReloadInternalServer(PIP_ADAPTER_ADDRESSES adapter) +#elif defined(__POSIX__) +void NetAdapter::ReloadInternalServer(ifaddrs* adapter) +#endif +{ + if (adapter == nullptr) + Console.Error("DEV9: ReloadInternalServer() got nullptr for adapter"); +} + bool NetAdapter::InternalServerRecv(NetPacket* pkt) { return false; diff --git a/pcsx2/DEV9/net.h b/pcsx2/DEV9/net.h index 5e3a17530c..e5fa84d110 100644 --- a/pcsx2/DEV9/net.h +++ b/pcsx2/DEV9/net.h @@ -33,6 +33,8 @@ #include "PacketReader/IP/IP_Address.h" +struct Config; + // first three recognized by Xlink as Sony PS2 const u8 defaultMAC[6] = {0x00, 0x04, 0x1F, 0x82, 0x30, 0x31}; @@ -97,6 +99,7 @@ public: virtual bool isInitialised() = 0; virtual bool recv(NetPacket* pkt); //gets a packet virtual bool send(NetPacket* pkt); //sends the packet and deletes it when done + virtual void reloadSettings() = 0; virtual void close(){}; virtual ~NetAdapter(); @@ -106,8 +109,10 @@ protected: #ifdef _WIN32 void InitInternalServer(PIP_ADAPTER_ADDRESSES adapter); + void ReloadInternalServer(PIP_ADAPTER_ADDRESSES adapter); #elif defined(__POSIX__) void InitInternalServer(ifaddrs* adapter); + void ReloadInternalServer(ifaddrs* adapter); #endif private: @@ -120,6 +125,7 @@ private: void tx_put(NetPacket* ptr); void InitNet(); +void ReconfigureLiveNet(Config* oldConfig); void TermNet(); const char* NetApiToString(NetApi api); diff --git a/pcsx2/DEV9/pcap_io.cpp b/pcsx2/DEV9/pcap_io.cpp index 6b6f1a4324..459283ab0f 100644 --- a/pcsx2/DEV9/pcap_io.cpp +++ b/pcsx2/DEV9/pcap_io.cpp @@ -427,6 +427,29 @@ bool PCAPAdapter::send(NetPacket* pkt) return true; } } + +void PCAPAdapter::reloadSettings() +{ +#ifdef _WIN32 + IP_ADAPTER_ADDRESSES adapter; + std::unique_ptr buffer; + if (PCAPGetWin32Adapter(config.Eth, &adapter, &buffer)) + ReloadInternalServer(&adapter); + else + ReloadInternalServer(nullptr); +#elif defined(__POSIX__) + ifaddrs adapter; + ifaddrs* buffer; + if (PCAPGetIfAdapter(config.Eth, &adapter, &buffer)) + { + ReloadInternalServer(&adapter); + freeifaddrs(buffer); + } + else + ReloadInternalServer(nullptr); +#endif +} + PCAPAdapter::~PCAPAdapter() { pcap_io_close(); diff --git a/pcsx2/DEV9/pcap_io.h b/pcsx2/DEV9/pcap_io.h index 18bc67b3d9..8dd7adc585 100644 --- a/pcsx2/DEV9/pcap_io.h +++ b/pcsx2/DEV9/pcap_io.h @@ -181,6 +181,7 @@ public: virtual bool recv(NetPacket* pkt); //sends the packet and deletes it when done (if successful).rv :true success virtual bool send(NetPacket* pkt); + virtual void reloadSettings(); virtual ~PCAPAdapter(); static std::vector GetAdapters(); };