Debian Codegraph @

rt/+dragonfly/socket.ha

raw
1 // SPDX-License-Identifier: MPL-2.0
2 // (c) Hare authors <https://harelang.org>
3
4 export type sa_family_t = u8;
5 export type socklen_t = u32;
6
7 export type in_addr = struct {
8 s_addr: u32
9 };
10
11 // Socket address, internet style.
12 export type sockaddr_in = struct {
13 sin_len: u8,
14 sin_family: sa_family_t,
15 sin_port: u16,
16 sin_addr: in_addr,
17 __pad: [8]u8,
18 };
19
20 // IPv6 address
21 export type in6_addr = struct {
22 // 128-bit IP6 address
23 union {
24 s6_addr: [16]u8,
25 s6_addr16: [8]u16,
26 s6_addr32: [4]u32,
27 }
28 };
29
30 export type sockaddr_in6 = struct {
31 sin6_len: u8, // length of this struct
32 sin6_family: sa_family_t, // AF_INET6
33 sin6_port: u16, // Transport layer port #
34 sin6_flowinfo: u32, // IP6 flow information
35 sin6_addr: in6_addr, // IP6 address
36 sin6_scope_id: u32, // scope zone index
37 };
38
39 export def UNIX_PATH_MAX: size = 104;
40
41 // Definitions for UNIX IPC domain
42 export type sockaddr_un = struct {
43 sun_len: u8, // sockaddr len including NUL
44 sun_family: sa_family_t, // AF_UNIX
45 sun_path: [UNIX_PATH_MAX]u8, // path name (gag)
46 };
47
48 // The definition in Dragonfly (sys/socket.h) is slightly different
49 // but the one below makes more sense.
50 export type sockaddr = struct {
51 union {
52 in: sockaddr_in,
53 in6: sockaddr_in6,
54 un: sockaddr_un,
55 },
56 };
57
58 export def SCM_RIGHTS: int = 0x01; // access rights (array of int)
59 export def SCM_TIMESTAMP: int = 0x02; // timestamp (struct timeval)
60 export def SCM_CREDENTIALS: int = 0x03; // process cred (struct cmsgcred)
61
62 // Message header for recvmsg and sendmsg calls.
63 // Used value-result for recvmsg, value only for sendmsg.
64 export type msghdr = struct {
65 msg_name: nullable *opaque, // optional address
66 msg_namelen: socklen_t, // size of address
67 msg_iov: nullable *[*]iovec, // scatter/gather array
68 msg_iovlen: int, // # elements in msg_iov
69 msg_control: nullable *opaque, // ancillary data, see below
70 msg_controllen: socklen_t, // ancillary data buffer len
71 msg_flags: int // flags on received message
72 };
73
74 // Header for ancillary data objects in msg_control buffer.
75 // Used for additional information with/about a datagram
76 // not expressible by flags. The format is a sequence
77 // of message elements headed by cmsghdr structures.
78 export type cmsghdr = struct {
79 cmsg_len: socklen_t, // data byte count, including hdr
80 cmsg_level: int, // originating protocol
81 cmsg_type: int, // protocol-specific type
82 };
83
84 export type cmsg = struct {
85 hdr: cmsghdr,
86 cmsg_data: [*]u8,
87 };
88
89 export def AF_UNSPEC: sa_family_t = 0; // unspecified
90 export def AF_UNIX: sa_family_t = 1; // local to host (pipes, portals)
91 export def AF_LOCAL: sa_family_t = AF_UNIX;
92 export def AF_INET: sa_family_t = 2; // internetwork: UDP, TCP, etc.
93 export def AF_IMPLINK: sa_family_t = 3; // arpanet imp addresses
94 export def AF_PUP: sa_family_t = 4; // pup protocols: e.g. BSP
95 export def AF_CHAOS: sa_family_t = 5; // mit CHAOS protocols
96 export def AF_NETBIOS: sa_family_t = 6; // SMB protocols
97 export def AF_ISO: sa_family_t = 7; // ISO protocols
98 export def AF_OSI: sa_family_t = AF_ISO;
99 export def AF_ECMA: sa_family_t = 8; // European computer manufacturers
100 export def AF_DATAKIT: sa_family_t = 9; // datakit protocols
101 export def AF_CCITT: sa_family_t = 10; // CCITT protocols, X.25 etc
102 export def AF_SNA: sa_family_t = 11; // IBM SNA
103 export def AF_DECnet: sa_family_t = 12; // DECnet
104 export def AF_DLI: sa_family_t = 13; // DEC Direct data link interface
105 export def AF_LAT: sa_family_t = 14; // LAT
106 export def AF_HYLINK: sa_family_t = 15; // NSC Hyperchannel
107 export def AF_APPLETALK: sa_family_t = 16; // Apple Talk
108 export def AF_ROUTE: sa_family_t = 17; // Internal Routing Protocol
109 export def AF_LINK: sa_family_t = 18; // Link layer interface
110 export def pseudo_AF_XTP: sa_family_t = 19; // eXpress Transfer Protocol (no AF)
111 export def AF_COIP: sa_family_t = 20; // connection-oriented IP, aka ST II
112 export def AF_CNT: sa_family_t = 21; // Computer Network Technology
113 export def pseudo_AF_RTIP: sa_family_t = 22; // Help Identify RTIP packets
114 export def AF_IPX: sa_family_t = 23; // Novell Internet Protocol
115 export def AF_SIP: sa_family_t = 24; // Simple Internet Protocol
116 export def pseudo_AF_PIP: sa_family_t = 25; // Help Identify PIP packets
117 export def AF_ISDN: sa_family_t = 26; // Integrated Services Digital Network
118 export def AF_E164: sa_family_t = AF_ISDN; // CCITT E.164 recommendation
119 export def pseudo_AF_KEY: sa_family_t = 27; // Internal key-management function
120 export def AF_INET6: sa_family_t = 28; // IPv6
121 export def AF_NATM: sa_family_t = 29; // native ATM access
122 export def AF_ATM: sa_family_t = 30; // ATM
123 // Used by BPF to not rewrite headers in interface output routine
124 export def pseudo_AF_HDRCMPLT: sa_family_t = 31;
125 export def AF_NETGRAPH: sa_family_t = 32; // Netgraph sockets
126 export def AF_BLUETOOTH: sa_family_t = 33; // Bluetooth
127 export def AF_MPLS: sa_family_t = 34; // Multi-Protocol Label Switching
128 export def AF_IEEE80211: sa_family_t = 35; // IEEE 802.11 protocol
129 export def AF_ARP: sa_family_t = 36; // (rev.) addr. res. prot. (RFC 826)
130 export def AF_MAX: sa_family_t = 37;
131
132 export def SOCK_STREAM: int = 1; // stream socket
133 export def SOCK_DGRAM: int = 2; // datagram socket
134 export def SOCK_RAW: int = 3; // raw-protocol interface
135 export def SOCK_RDM: int = 4; // reliably-delivered message
136 export def SOCK_SEQPACKET: int = 5; // sequenced packet stream
137
138 //
139 // Creation flags, OR'ed into socket() and socketpair() type argument.
140 //
141
142 export def SOCK_CLOEXEC: int = 0x10000000;
143 export def SOCK_NONBLOCK: int = 0x20000000;
144 export def SOCK_CLOFORK: int = 0x40000000;
145 // For kern_accept(): don't inherit FNONBLOCK or FASYNC.
146 export def SOCK_KERN_NOINHERIT: int = 0x00100000;
147
148
149 //
150 // Protocols (RFC 1700) that are part of standards
151 //
152
153 export def IPPROTO_IP: int = 0; // dummy for IP
154 export def IPPROTO_ICMP: int = 1; // control message protocol
155 export def IPPROTO_TCP: int = 6; // tcp
156 export def IPPROTO_UDP: int = 17; // user datagram protocol
157 export def IPPROTO_IPV6: int = 41; // IP6 header
158 export def IPPROTO_RAW: int = 255; // raw IP packet
159 export def IPPROTO_HOPOPTS: int = 0; // IP6 hop-by-hop options
160 export def IPPROTO_IGMP: int = 2; // group mgmt protocol
161 export def IPPROTO_GGP: int = 3; // gateway^2 (deprecated)
162 export def IPPROTO_IPV4: int = 4; // IPv4 encapsulation
163 export def IPPROTO_ST: int = 7; // Stream protocol II
164 export def IPPROTO_EGP: int = 8; // exterior gateway protocol
165 export def IPPROTO_PIGP: int = 9; // private interior gateway
166 export def IPPROTO_RCCMON: int = 10; // BBN RCC Monitoring
167 export def IPPROTO_NVPII: int = 11; // network voice protocol
168 export def IPPROTO_PUP: int = 12; // pup
169 export def IPPROTO_ARGUS: int = 13; // Argus
170 export def IPPROTO_EMCON: int = 14; // EMCON
171 export def IPPROTO_XNET: int = 15; // Cross Net Debugger
172 export def IPPROTO_CHAOS: int = 16; // Chaos
173 export def IPPROTO_MUX: int = 18; // Multiplexing
174 export def IPPROTO_MEAS: int = 19; // DCN Measurement Subsystems
175 export def IPPROTO_HMP: int = 20; // Host Monitoring
176 export def IPPROTO_PRM: int = 21; // Packet Radio Measurement
177 export def IPPROTO_IDP: int = 22; // xns idp
178 export def IPPROTO_TRUNK1: int = 23; // Trunk-1
179 export def IPPROTO_TRUNK2: int = 24; // Trunk-2
180 export def IPPROTO_LEAF1: int = 25; // Leaf-1
181 export def IPPROTO_LEAF2: int = 26; // Leaf-2
182 export def IPPROTO_RDP: int = 27; // Reliable Data
183 export def IPPROTO_IRTP: int = 28; // Reliable Transaction
184 export def IPPROTO_TP: int = 29; // tp-4 w/ class negotiation
185 export def IPPROTO_BLT: int = 30; // Bulk Data Transfer
186 export def IPPROTO_NSP: int = 31; // Network Services
187 export def IPPROTO_INP: int = 32; // Merit Internodal
188 export def IPPROTO_SEP: int = 33; // Sequential Exchange
189 export def IPPROTO_3PC: int = 34; // Third Party Connect
190 export def IPPROTO_IDPR: int = 35; // InterDomain Policy Routing
191 export def IPPROTO_XTP: int = 36; // XTP
192 export def IPPROTO_DDP: int = 37; // Datagram Delivery
193 export def IPPROTO_CMTP: int = 38; // Control Message Transport
194 export def IPPROTO_TPXX: int = 39; // TP++ Transport
195 export def IPPROTO_IL: int = 40; // IL transport protocol
196 export def IPPROTO_SDRP: int = 42; // Source Demand Routing
197 export def IPPROTO_ROUTING: int = 43; // IP6 routing header
198 export def IPPROTO_FRAGMENT: int = 44; // IP6 fragmentation header
199 export def IPPROTO_IDRP: int = 45; // InterDomain Routing
200 export def IPPROTO_RSVP: int = 46; // resource reservation
201 export def IPPROTO_GRE: int = 47; // General Routing Encap.
202 export def IPPROTO_MHRP: int = 48; // Mobile Host Routing
203 export def IPPROTO_BHA: int = 49; // BHA
204 export def IPPROTO_ESP: int = 50; // IP6 Encap Sec. Payload
205 export def IPPROTO_AH: int = 51; // IP6 Auth Header
206 export def IPPROTO_INLSP: int = 52; // Integ. Net Layer Security
207 export def IPPROTO_SWIPE: int = 53; // IP with encryption
208 export def IPPROTO_NHRP: int = 54; // Next Hop Resolution
209 export def IPPROTO_MOBILE: int = 55; // IP Mobility
210 export def IPPROTO_TLSP: int = 56; // Transport Layer Security
211 export def IPPROTO_SKIP: int = 57; // SKIP
212 export def IPPROTO_ICMPV6: int = 58; // ICMP6
213 export def IPPROTO_NONE: int = 59; // IP6 no next header
214 export def IPPROTO_DSTOPTS: int = 60; // IP6 destination option
215 export def IPPROTO_AHIP: int = 61; // any host internal protocol
216 export def IPPROTO_CFTP: int = 62; // CFTP
217 export def IPPROTO_HELLO: int = 63; // "hello" routing protocol
218 export def IPPROTO_SATEXPAK: int = 64; // SATNET/Backroom EXPAK
219 export def IPPROTO_KRYPTOLAN: int = 65; // Kryptolan
220 export def IPPROTO_RVD: int = 66; // Remote Virtual Disk
221 export def IPPROTO_IPPC: int = 67; // Pluribus Packet Core
222 export def IPPROTO_ADFS: int = 68; // Any distributed FS
223 export def IPPROTO_SATMON: int = 69; // Satnet Monitoring
224 export def IPPROTO_VISA: int = 70; // VISA Protocol
225 export def IPPROTO_IPCV: int = 71; // Packet Core Utility
226 export def IPPROTO_CPNX: int = 72; // Comp. Prot. Net. Executive
227 export def IPPROTO_CPHB: int = 73; // Comp. Prot. HeartBeat
228 export def IPPROTO_WSN: int = 74; // Wang Span Network
229 export def IPPROTO_PVP: int = 75; // Packet Video Protocol
230 export def IPPROTO_BRSATMON: int = 76; // BackRoom SATNET Monitoring
231 export def IPPROTO_ND: int = 77; // Sun net disk proto (temp.)
232 export def IPPROTO_WBMON: int = 78; // WIDEBAND Monitoring
233 export def IPPROTO_WBEXPAK: int = 79; // WIDEBAND EXPAK
234 export def IPPROTO_EON: int = 80; // ISO cnlp
235 export def IPPROTO_VMTP: int = 81; // VMTP
236 export def IPPROTO_SVMTP: int = 82; // Secure VMTP
237 export def IPPROTO_VINES: int = 83; // Banyon VINES
238 export def IPPROTO_TTP: int = 84; // TTP
239 export def IPPROTO_IGP: int = 85; // NSFNET-IGP
240 export def IPPROTO_DGP: int = 86; // dissimilar gateway prot.
241 export def IPPROTO_TCF: int = 87; // TCF
242 export def IPPROTO_IGRP: int = 88; // Cisco/GXS IGRP
243 export def IPPROTO_OSPFIGP: int = 89; // OSPFIGP
244 export def IPPROTO_SRPC: int = 90; // Strite RPC protocol
245 export def IPPROTO_LARP: int = 91; // Locus Address Resoloution
246 export def IPPROTO_MTP: int = 92; // Multicast Transport
247 export def IPPROTO_AX25: int = 93; // AX.25 Frames
248 export def IPPROTO_IPEIP: int = 94; // IP encapsulated in IP
249 export def IPPROTO_MICP: int = 95; // Mobile Int.ing control
250 export def IPPROTO_SCCSP: int = 96; // Semaphore Comm. security
251 export def IPPROTO_ETHERIP: int = 97; // Ethernet IP encapsulation
252 export def IPPROTO_ENCAP: int = 98; // encapsulation header
253 export def IPPROTO_APES: int = 99; // any private encr. scheme
254 export def IPPROTO_GMTP: int = 100; // GMTP
255 export def IPPROTO_IPCOMP: int = 108; // payload compression (IPComp)
256 export def IPPROTO_PIM: int = 103; // Protocol Independent Mcast
257 export def IPPROTO_CARP: int = 112; // CARP
258 export def IPPROTO_PGM: int = 113; // PGM
259 export def IPPROTO_PFSYNC: int = 240; // PFSYNC
260 export def IPPROTO_DIVERT: int = 254; // divert pseudo-protocol
261 export def IPPROTO_MAX: int = 256; //
262 export def IPPROTO_DONE: int = 257; //
263 export def IPPROTO_UNKNOWN: int = 258; //
264
265 export def MSG_OOB: int = 0x00000001; // process out-of-band data
266 export def MSG_PEEK: int = 0x00000002; // peek at incoming message
267 export def MSG_DONTROUTE: int = 0x00000004; // send without using routing tables
268 export def MSG_EOR: int = 0x00000008; // data completes record
269 export def MSG_TRUNC: int = 0x00000010; // data discarded before delivery
270 export def MSG_CTRUNC: int = 0x00000020; // control data lost before delivery
271 export def MSG_WAITALL: int = 0x00000040; // wait for full request or error
272 export def MSG_DONTWAIT: int = 0x00000080; // this message should be nonblocking
273 export def MSG_EOF: int = 0x00000100; // data completes connection
274 export def MSG_UNUSED09: int = 0x00000200; // was: notification message (SCTP)
275 export def MSG_NOSIGNAL: int = 0x00000400; // No SIGPIPE to unconnected socket stream
276 export def MSG_SYNC: int = 0x00000800; // No asynchronized pru_send
277 export def MSG_CMSG_CLOEXEC: int = 0x00001000; // make received fds close-on-exec
278 export def MSG_CMSG_CLOFORK: int = 0x00002000; // make received fds close-on-fork
279 export def MSG_FBLOCKING: int = 0x00010000; // force blocking operation
280 export def MSG_FNONBLOCKING: int = 0x00020000; // force non-blocking operation
281 export def MSG_FMASK: uint = 0xFFFF0000; // force mask
282
283 //
284 // Option flags per-socket.
285 //
286
287 export def SO_DEBUG: int = 0x0001; // turn on debugging info recording
288 export def SO_ACCEPTCONN: int = 0x0002; // socket has had listen()
289 export def SO_REUSEADDR: int = 0x0004; // allow local address reuse
290 export def SO_KEEPALIVE: int = 0x0008; // keep connections alive
291 export def SO_DONTROUTE: int = 0x0010; // just use interface addresses
292 export def SO_BROADCAST: int = 0x0020; // permit sending of broadcast msgs
293 export def SO_USELOOPBACK: int = 0x0040;// bypass hardware when possible
294 export def SO_LINGER: int = 0x0080; // linger on close if data present
295 export def SO_OOBINLINE: int = 0x0100; // leave received OOB data in line
296 export def SO_REUSEPORT: int = 0x0200; // allow local address & port reuse
297 export def SO_TIMESTAMP: int = 0x0400; // timestamp received dgram traffic
298 export def SO_NOSIGPIPE: int = 0x0800; // no SIGPIPE from EPIPE
299 export def SO_ACCEPTFILTER: int = 0x1000;// there is an accept filter
300 export def SO_RERROR: int = 0x2000; // Keep track of receive errors
301 export def SO_PASSCRED: int = 0x4000; // receive credentials
302 export def SO_SNDBUF: int = 0x1001; // send buffer size
303 export def SO_RCVBUF: int = 0x1002; // receive buffer size
304 export def SO_SNDLOWAT: int = 0x1003; // send low-water mark
305 export def SO_RCVLOWAT: int = 0x1004; // receive low-water mark
306 export def SO_SNDTIMEO: int = 0x1005; // send timeout
307 export def SO_RCVTIMEO: int = 0x1006; // receive timeout
308 export def SO_ERROR: int = 0x1007; // get error status and clear
309 export def SO_TYPE: int = 0x1008; // get socket type
310 export def SO_SNDSPACE: int = 0x100a; // get appr. send buffer free space
311 export def SO_USER_COOKIE: int = 0x1015;// user cookie
312 export def SO_CPUHINT: int = 0x1030; // get socket's owner cpuid hint
313
314 //
315 // Level number for (get/set)sockopt() to apply to socket itself.
316 //
317
318 export def SOL_SOCKET: int = 0xffff; // options for socket level