socket_types.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <optional>
  5. #include <string>
  6. #include "common/common_types.h"
  7. namespace Network {
  8. /// Address families
  9. enum class Domain : u8 {
  10. Unspecified, ///< Represents 0, used in getaddrinfo hints
  11. INET, ///< Address family for IPv4
  12. };
  13. /// Socket types
  14. enum class Type {
  15. Unspecified, ///< Represents 0, used in getaddrinfo hints
  16. STREAM,
  17. DGRAM,
  18. RAW,
  19. SEQPACKET,
  20. };
  21. /// Protocol values for sockets
  22. enum class Protocol : u8 {
  23. Unspecified, ///< Represents 0, usable in various places
  24. ICMP,
  25. TCP,
  26. UDP,
  27. };
  28. /// Shutdown mode
  29. enum class ShutdownHow {
  30. RD,
  31. WR,
  32. RDWR,
  33. };
  34. /// Array of IPv4 address
  35. using IPv4Address = std::array<u8, 4>;
  36. /// Cross-platform sockaddr structure
  37. struct SockAddrIn {
  38. Domain family;
  39. IPv4Address ip;
  40. u16 portno;
  41. };
  42. constexpr u32 FLAG_MSG_PEEK = 0x2;
  43. constexpr u32 FLAG_MSG_DONTWAIT = 0x80;
  44. constexpr u32 FLAG_O_NONBLOCK = 0x800;
  45. /// Cross-platform addrinfo structure
  46. struct AddrInfo {
  47. Domain family;
  48. Type socket_type;
  49. Protocol protocol;
  50. SockAddrIn addr;
  51. std::optional<std::string> canon_name;
  52. };
  53. } // namespace Network