Skip to main content

relibc/header/sys_socket/
constants.rs

1use crate::platform::types::c_int;
2
3// Socket types
4
5/// Byte-stream socket.
6pub const SOCK_STREAM: c_int = 1;
7/// Datagram socket.
8pub const SOCK_DGRAM: c_int = 2;
9/// Raw Protocol Interface.
10pub const SOCK_RAW: c_int = 3;
11/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/socket.2.html>.
12///
13/// Provides a reliable datagram layer that does not guarantee ordering.
14pub const SOCK_RDM: c_int = 4;
15/// Sequenced-packet socket.
16pub const SOCK_SEQPACKET: c_int = 5;
17
18// End of socket types
19
20// Socket creation flags (for use in `socket()`, `socketpair()` and `accept4()`)
21
22/// Create a socket file descriptor with the `O_NONBLOCK` flag atomically set
23/// on the new open file description.
24pub const SOCK_NONBLOCK: c_int = 0o4_000;
25/// Create a socket file descriptor wit the `FD_CLOEXEC` flag atomically set
26/// on that file descriptor.
27pub const SOCK_CLOEXEC: c_int = 0o2_000_000;
28
29// End of socket creation flags
30
31// `level` argument of `getsockopt()` and `setsockopt()`
32
33/// Options to be accessed at socket level, not protocol level.
34pub const SOL_SOCKET: c_int = 1;
35
36// End of `level` argument
37
38// `option_name` argument for `getsockopt()` and `setsockopt()`
39
40/// Debugging information is recorded.
41pub const SO_DEBUG: c_int = 1;
42/// Reuse of local addresses is supported.
43pub const SO_REUSEADDR: c_int = 2;
44/// Socket type.
45pub const SO_TYPE: c_int = 3;
46/// Socket error status.
47pub const SO_ERROR: c_int = 4;
48/// Bypass normal routing.
49pub const SO_DONTROUTE: c_int = 5;
50/// Transmission of broadcast messages is supported.
51pub const SO_BROADCAST: c_int = 6;
52/// Send buffer size.
53pub const SO_SNDBUF: c_int = 7;
54/// Receive buffer size.
55pub const SO_RCVBUF: c_int = 8;
56/// Connections are kept alive with periodic messages.
57pub const SO_KEEPALIVE: c_int = 9;
58/// Out-of-band data is transmitted inline.
59pub const SO_OOBINLINE: c_int = 10;
60/// Non-POSIX, found in LwIP.
61///
62/// Don't create UDP checksum.
63pub const SO_NO_CHECK: c_int = 11;
64/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/socket.7.html>.
65///
66/// Set the protocol-defined priority for all packets to be sent on this
67/// socket.
68pub const SO_PRIORITY: c_int = 12;
69/// Socket lingers on close.
70pub const SO_LINGER: c_int = 13;
71/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/socket.7.html>.
72///
73/// Enable BSD bug-to-bug compatibility.
74pub const SO_BSDCOMPAT: c_int = 14;
75/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/socket.7.html>.
76///
77/// Permits multiple `AF_INET` or `AF_INET6` sockets to be bound to an
78/// identical socket address.
79pub const SO_REUSEPORT: c_int = 15;
80/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/socket.7.html>.
81///
82/// Enable or disable the receiving of the `SCM_CREDENTIALS` control message.
83pub const SO_PASSCRED: c_int = 16;
84/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/socket.7.html>.
85///
86/// Return the credentials of the peer process connected to this socket.
87pub const SO_PEERCRED: c_int = 17;
88/// Receive "low water mark".
89pub const SO_RCVLOWAT: c_int = 18;
90/// Send "low water mark".
91pub const SO_SNDLOWAT: c_int = 19;
92/// Receive timeout.
93pub const SO_RCVTIMEO: c_int = 20;
94/// Send timeout.
95pub const SO_SNDTIMEO: c_int = 21;
96/// Socket is accepting connections.
97pub const SO_ACCEPTCONN: c_int = 30;
98/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/SO_PEERSEC.2const.html>.
99///
100/// Get the security context of a peer socket.
101pub const SO_PEERSEC: c_int = 31;
102/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/socket.7.html>.
103///
104/// A privileged (`CAP_NET_ADMIN`) process can perform the same task as
105/// `SO_SNDBUF`, but the `wmem_max` limit can be overridden.
106pub const SO_SNDBUFFORCE: c_int = 32;
107/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/socket.7.html>.
108///
109/// A privileged (`CAP_NET_ADMIN`) process can perform the same task as
110/// `SO_RCVBUF`, but the `rmem_max` limit can be overridden.
111pub const SO_RCVBUFFORCE: c_int = 33;
112/// Socket protocol.
113pub const SO_PROTOCOL: c_int = 38;
114/// Socket domain.
115pub const SO_DOMAIN: c_int = 39;
116
117// End of `option_name` argument
118
119/// The maximum backlog queue length.
120pub const SOMAXCONN: c_int = 128;
121
122// `msg_flags`
123
124/// Control data truncated.
125pub const MSG_CTRUNC: c_int = 8;
126/// Send without using routing tables.
127pub const MSG_DONTROUTE: c_int = 4;
128/// Terminates a record (if supported by the protocol).
129pub const MSG_EOR: c_int = 128;
130/// Out-of-band data.
131pub const MSG_OOB: c_int = 1;
132/// Leave received data in queue.
133pub const MSG_PEEK: c_int = 2;
134/// Normal data truncated.
135pub const MSG_TRUNC: c_int = 32;
136/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/send.2.html>.
137///
138/// Enables nonblocking operation.
139pub const MSG_DONTWAIT: c_int = 64;
140/// Attempt to fill the read buffer.
141pub const MSG_WAITALL: c_int = 256;
142/// No SIGPIPE generated when an attempt to send is made on a stream-oriented
143/// socket that is no longer connected.
144pub const MSG_NOSIGNAL: c_int = 0x4000;
145/// Atomically set the `FD_CLOEXEC` flag on any file descriptors created via
146/// `SCM_RIGHTS` during `recvmsg()`.
147pub const MSG_CMSG_CLOEXEC: c_int = 0x40000000;
148
149// End of `mag_flags`
150
151/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/IP_ADD_SOURCE_MEMBERSHIP.2const.html>.
152///
153/// Join a multicast group and allow receiving data only from a specified
154/// source.
155pub const IP_ADD_SOURCE_MEMBERSHIP: c_int = 70;
156/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/IP_DROP_SOURCE_MEMBERSHIP.2const.html>.
157///
158/// Leave a source-specific multicast group.
159pub const IP_DROP_SOURCE_MEMBERSHIP: c_int = 71;
160/// Non-POSIX, see <https://datatracker.ietf.org/doc/html/rfc3678#section-5.1.2>.
161///
162/// Join a source-specific group.
163pub const MCAST_JOIN_SOURCE_GROUP: c_int = 46;
164/// Non-POSIX, see <https://datatracker.ietf.org/doc/html/rfc3678#section-5.1.2>.
165///
166/// Leave a source-specific group.
167pub const MCAST_LEAVE_SOURCE_GROUP: c_int = 47;
168
169// Address family constants (AF)
170
171/// Internet domain sockets for use with IPv4 sockets.
172pub const AF_INET: c_int = 2;
173/// Internet domain sockets for use with IPv6 sockets.
174pub const AF_INET6: c_int = 10;
175/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/unix.7.html>.
176///
177/// Alias for `AF_UNIX`.
178pub const AF_LOCAL: c_int = AF_UNIX;
179/// UNIX domain sockets.
180pub const AF_UNIX: c_int = 1;
181/// Unspecified.
182pub const AF_UNSPEC: c_int = 0;
183
184// End of AF constants
185
186// Protocol family constants (PF)
187// Constants historically used by BSDs, identical to AF constants.
188// Recommended to use AF constants everywhere instead.
189// See <https://www.man7.org/linux/man-pages/man2/socket.2.html>.
190
191/// See `AF_INET`.
192pub const PF_INET: c_int = 2;
193/// See `AF_INET6`.
194pub const PF_INET6: c_int = 10;
195/// See `AF_LOCAL`.
196pub const PF_LOCAL: c_int = PF_UNIX;
197/// See `AF_UNIX`.
198pub const PF_UNIX: c_int = 1;
199/// See `AF_UNSPEC`.
200pub const PF_UNSPEC: c_int = 0;
201
202// End of PF constants
203
204/// Disables further receive operations.
205pub const SHUT_RD: c_int = 0;
206/// Disables further send and receive operations.
207pub const SHUT_RDWR: c_int = 2;
208/// Disables further send operations.
209pub const SHUT_WR: c_int = 1;
210
211// `cmsg_type` value when `cmsg_level` is `SOL_SOCKET`
212
213/// Indicates that the data array contains the access rights to be sent or
214/// received.
215pub const SCM_RIGHTS: c_int = 1;
216/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man7/unix.7.html>.
217///
218/// Send or receive UNIX credentials.
219pub const SCM_CREDENTIALS: c_int = 2;
220
221// End of `cmsg_type` value