summaryrefslogtreecommitdiffstats
path: root/src/core/network/network.h
diff options
context:
space:
mode:
authorSönke Holz <sholz8530@gmail.com>2021-08-16 10:32:25 +0200
committerSönke Holz <sholz8530@gmail.com>2021-08-16 10:32:25 +0200
commit70419f7a17880fd1e7834e7fe6e1aad14b0565bb (patch)
treee1eb243069df47057ba98c77dcce4588bf34ae31 /src/core/network/network.h
parentconfiguration: fix mingw-w64 build (diff)
downloadyuzu-70419f7a17880fd1e7834e7fe6e1aad14b0565bb.tar
yuzu-70419f7a17880fd1e7834e7fe6e1aad14b0565bb.tar.gz
yuzu-70419f7a17880fd1e7834e7fe6e1aad14b0565bb.tar.bz2
yuzu-70419f7a17880fd1e7834e7fe6e1aad14b0565bb.tar.lz
yuzu-70419f7a17880fd1e7834e7fe6e1aad14b0565bb.tar.xz
yuzu-70419f7a17880fd1e7834e7fe6e1aad14b0565bb.tar.zst
yuzu-70419f7a17880fd1e7834e7fe6e1aad14b0565bb.zip
Diffstat (limited to 'src/core/network/network.h')
-rw-r--r--src/core/network/network.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/network/network.h b/src/core/network/network.h
index cfa68d478..fdd3e4655 100644
--- a/src/core/network/network.h
+++ b/src/core/network/network.h
@@ -11,6 +11,12 @@
#include "common/common_funcs.h"
#include "common/common_types.h"
+#ifdef _WIN32
+#include <winsock2.h>
+#elif YUZU_UNIX
+#include <netinet/in.h>
+#endif
+
namespace Network {
class Socket;
@@ -93,6 +99,19 @@ public:
~NetworkInstance();
};
+#ifdef _WIN32
+constexpr IPv4Address TranslateIPv4(in_addr addr) {
+ auto& bytes = addr.S_un.S_un_b;
+ return IPv4Address{bytes.s_b1, bytes.s_b2, bytes.s_b3, bytes.s_b4};
+}
+#elif YUZU_UNIX
+constexpr IPv4Address TranslateIPv4(in_addr addr) {
+ const u32 bytes = addr.s_addr;
+ return IPv4Address{static_cast<u8>(bytes), static_cast<u8>(bytes >> 8),
+ static_cast<u8>(bytes >> 16), static_cast<u8>(bytes >> 24)};
+}
+#endif
+
/// @brief Returns host's IPv4 address
/// @return human ordered IPv4 address (e.g. 192.168.0.1) as an array
std::optional<IPv4Address> GetHostIPv4Address();