aboutsummaryrefslogtreecommitdiff
path: root/src/common/socket_types.h
blob: 5b1e4d7b1d6ffc98a8898e03076e740c0ffed1b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <optional>
#include <string>

#include "common/common_types.h"

namespace Network {

/// Address families
enum class Domain : u8 {
    Unspecified, ///< Represents 0, used in getaddrinfo hints
    INET,        ///< Address family for IPv4
};

/// Socket types
enum class Type {
    Unspecified, ///< Represents 0, used in getaddrinfo hints
    STREAM,
    DGRAM,
    RAW,
    SEQPACKET,
};

/// Protocol values for sockets
enum class Protocol : u8 {
    Unspecified, ///< Represents 0, usable in various places
    IP,
    ICMP,
    TCP,
    UDP,
    IPV6,
    RAW,
    IGMP,
    GGP,
    IPV4,
    ST,
    EGP,
    PIGP,
    RCCMON,
    NVPII,
    PUP,
    ARGUS,
    EMCON,
    XNET,
    CHAOS,
    MUX,
    MEAS,
    HMP,
    PRM,
    IDP,
    TRUNK1,
    TRUNK2,
    LEAF1,
    LEAF2,
    RDP,
    IRTP,
    TP,
    BLT,
    NSP,
    INP,
    DCCP,
    //TODO: 3PC,
    IDPR,
    XTP,
    DDP,
    CMTP,
    TPXX,
    IL,
    SDRP,
    ROUTING,
    FRAGMENT,
    IDRP,
    RSVP,
    GRE,
    MHRP,
    BHA,
    ESP,
    AH,
    INLSP,
    SWIPE,
    NHRP,
    MOBILE,
    TLSP,
    SKIP,
    ICMPV6,
    NONE,
    DSTOPTS,
    AHIP,
    CFTP,
    HELLO,
    SATEXPAK,
    KRYPTOLAN,
    RVD,
    IPPC,
    ADFS,
    SATMON,
    VISA,
    IPCV,
    CPNX,
    CPHB,
    WSN,
    PVP,
    BRSATMON,
    ND,
    WBMON,
    WBEXPAK,
    EON,
    VMTP,
    SVMTP,
    VINES,
    TTP,
    IGP,
    DGP,
    TCF,
    IGRP,
    OSPFIGP,
    SRPC,
    LARP,
    MTP,
    AX25,
    IPEIP,
    MICP,
    SCCSP,
    ETHERIP,
    ENCAP,
    APES,
    GMTP,
    IPCOMP,
    SCTP,
    MH,
    UDPLITE,
    HIP,
    SHIM6,
    PIM,
    CARP,
    PGM,
    MPLS,
    PFSYNC
};

/// Shutdown mode
enum class ShutdownHow {
    RD,
    WR,
    RDWR,
};

/// Array of IPv4 address
using IPv4Address = std::array<u8, 4>;

/// Cross-platform sockaddr structure
struct SockAddrIn {
    Domain family;
    IPv4Address ip;
    u16 portno;
};

constexpr u32 FLAG_MSG_PEEK = 0x2;
constexpr u32 FLAG_MSG_DONTWAIT = 0x80;
constexpr u32 FLAG_O_NONBLOCK = 0x800;

/// Cross-platform addrinfo structure
struct AddrInfo {
    Domain family;
    Type socket_type;
    Protocol protocol;
    SockAddrIn addr;
    std::optional<std::string> canon_name;
};

} // namespace Network