1 // Copyright 2020 yuzu emulator team 2 // Licensed under GPLv2 or any later version 3 // Refer to the license.txt file included. 4 5 #pragma once 6 7 #include <array> 8 #include <utility> 9 10 #include "common/common_types.h" 11 12 namespace Network { 13 14 class Socket; 15 16 /// Error code for network functions 17 enum class Errno { 18 SUCCESS, 19 BADF, 20 INVAL, 21 MFILE, 22 NOTCONN, 23 AGAIN, 24 }; 25 26 /// Address families 27 enum class Domain { 28 INET, ///< Address family for IPv4 29 }; 30 31 /// Socket types 32 enum class Type { 33 STREAM, 34 DGRAM, 35 RAW, 36 SEQPACKET, 37 }; 38 39 /// Protocol values for sockets 40 enum class Protocol { 41 ICMP, 42 TCP, 43 UDP, 44 }; 45 46 /// Shutdown mode 47 enum class ShutdownHow { 48 RD, 49 WR, 50 RDWR, 51 }; 52 53 /// Array of IPv4 address 54 using IPv4Address = std::array<u8, 4>; 55 56 /// Cross-platform sockaddr structure 57 struct SockAddrIn { 58 Domain family; 59 IPv4Address ip; 60 u16 portno; 61 }; 62 63 /// Cross-platform poll fd structure 64 65 enum class PollEvents : u16 { 66 // Using Pascal case because IN is a macro on Windows. 67 In = 1 << 0, 68 Pri = 1 << 1, 69 Out = 1 << 2, 70 Err = 1 << 3, 71 Hup = 1 << 4, 72 Nval = 1 << 5, 73 }; 74 75 DECLARE_ENUM_FLAG_OPERATORS(PollEvents); 76 77 struct PollFD { 78 Socket* socket; 79 PollEvents events; 80 PollEvents revents; 81 }; 82 83 class NetworkInstance { 84 public: 85 explicit NetworkInstance(); 86 ~NetworkInstance(); 87 }; 88 89 /// @brief Returns host's IPv4 address 90 /// @return Pair of an array of human ordered IPv4 address (e.g. 192.168.0.1) and an error code 91 std::pair<IPv4Address, Errno> GetHostIPv4Address(); 92 93 } // namespace Network 94