### Create New TcpKeepalive Configuration Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Example of creating a new, empty TcpKeepalive configuration where all options are initially disabled. ```rust let keepalive = TcpKeepalive::new(); socket.set_tcp_keepalive(keepalive)?; ``` -------------------------------- ### priority Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the SO_PRIORITY option. This option is available on Linux, Android, and Fuchsia. ```APIDOC ## priority ### Description Get the `SO_PRIORITY` option. ### Method `priority` ### Returns - `io::Result` ``` -------------------------------- ### Create and Bind a UDP Socket Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Illustrates the creation of a UDP socket, binding it to a local address, and preparing it to receive datagrams. This snippet shows the basic setup for a UDP server. ```rust use socket2::{Socket, Domain, Type}; let socket = Socket::new(Domain::IPV4, Type::DGRAM, None)?; let addr: std::net::SocketAddr = "127.0.0.1:5353".parse()?; socket.bind(&addr.into())?; let mut buf = [0u8; 512]; loop { let (n, peer) = socket.recv_from(&mut buf)?; handle_request(&buf[..n], peer)?; } ``` -------------------------------- ### only_v6 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IPV6_V6ONLY` option for IPv6. ```APIDOC ## only_v6 ### Description Get the `IPV6_V6ONLY` option (IPv6-only mode). ### Method `only_v6` ### Returns - **bool** - The current state of the `IPV6_V6ONLY` option. ``` -------------------------------- ### multicast_all_v4 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IP_MULTICAST_ALL` option for IPv4 (Linux only). ```APIDOC ## multicast_all_v4 ### Description Get the `IP_MULTICAST_ALL` option (Linux only). ### Method `multicast_all_v4` ### Returns - **bool** - The current state of the `IP_MULTICAST_ALL` option. ``` -------------------------------- ### tos_v4 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IP_TOS` option for IPv4. ```APIDOC ## tos_v4 ### Description Get the `IP_TOS` option (IPv4 Type of Service). ### Method `tos_v4` ### Returns - **u32** - The current IPv4 Type of Service value. ``` -------------------------------- ### tcp_nodelay Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `TCP_NODELAY` option for TCP. ```APIDOC ## tcp_nodelay ### Description Get the `TCP_NODELAY` option (disable Nagle's algorithm). ### Method `tcp_nodelay` ### Returns - **bool** - The current state of the `TCP_NODELAY` option. ``` -------------------------------- ### recv_any_interface Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get raw socket option for receiving on any interface (Linux, Android). ```APIDOC ## recv_any_interface ### Description Get raw socket option for receiving on any interface (Linux, Android). ### Method `recv_any_interface` ### Returns - **bool** - The current state of the receive any interface option. ``` -------------------------------- ### Get IPv4 Multicast All Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IP_MULTICAST_ALL option for IPv4. This is only available on Linux and requires the 'all' feature. ```rust #[cfg(all(feature = "all", target_os = "linux"))] pub fn multicast_all_v4(&self) -> io::Result ``` -------------------------------- ### Create a new IPv4 TCP socket Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Use `Socket::new` to create a new socket with automatic platform-specific flag settings. This example creates a TCP socket over IPv4, letting the system choose the protocol. ```rust use socket2::{Socket, Domain, Type}; let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; // TCP socket over IPv4, protocol selected automatically ``` -------------------------------- ### Specify Network Interface for Multicast Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Shows how to use `InterfaceIndexOrAddress` to specify a network interface for multicast operations, either by its numeric index or its assigned IPv4 address. It also includes examples for letting the system choose the interface. ```rust use socket2::InterfaceIndexOrAddress; use std::net::Ipv4Addr; // By index let if_by_index = InterfaceIndexOrAddress::Index(1); // By address let if_by_addr = InterfaceIndexOrAddress::Address(Ipv4Addr::new(192, 168, 1, 1)); // Let system choose let if_auto = InterfaceIndexOrAddress::Index(0); // Join multicast on specific interface // socket.join_multicast_v4_n(&group_addr, &if_by_index)?; ``` -------------------------------- ### Explicit UDP Socket Creation Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Example of creating a socket explicitly specifying the UDP protocol, typically used with datagram types. ```rust // Explicit UDP (usually implicit with DGRAM) let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?; ``` -------------------------------- ### Get IPv4 TOS Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IP_TOS option for IPv4 (Type of Service). This function is not available on WASI. ```rust #[cfg(not(target_os = "wasi"))] pub fn tos_v4(&self) -> io::Result ``` -------------------------------- ### Explicit TCP Socket Creation Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Example of creating a socket explicitly specifying the TCP protocol, typically used with stream types. ```rust // Explicit TCP (usually implicit with STREAM) let socket = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP))?; ``` -------------------------------- ### View SockAddrStorage as sockaddr_in Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Safely views the SockAddrStorage as a mutable reference to a `sockaddr_in` structure. The target type `T` must be a valid sockaddr type and its size must not exceed the storage size. This example sets the port for the sockaddr_in. ```rust use socket2::SockAddrStorage; use libc::sockaddr_in; let mut storage = SockAddrStorage::zeroed(); let addr_in = unsafe { storage.view_as::() }; addr_in.sin_port = 8080_u16.to_be(); ``` -------------------------------- ### Set TCP Keepalive Time Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Example of setting the time before the first TCP keepalive probe is sent. Note that sub-second values are truncated and platform mappings vary. ```rust let keepalive = TcpKeepalive::new() .with_time(Duration::from_secs(60)); socket.set_tcp_keepalive(keepalive)?; ``` -------------------------------- ### header_included_v4 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the IP_HDRINCL option for IPv4 sockets. This option is used for raw sockets where the user supplies the IP header. ```APIDOC ## header_included_v4 ### Description Get the `IP_HDRINCL` option (user supplies IP header for raw sockets). ### Method `header_included_v4` ### Returns - `io::Result` ``` -------------------------------- ### Get address family Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Get the address family constant (e.g., AF_INET, AF_INET6, AF_UNIX). ```rust let domain = addr.domain(); match domain { socket2::Domain::IPV4 => println!("IPv4"), socket2::Domain::IPV6 => println!("IPv6"), _ => {} } ``` -------------------------------- ### Create a Socket with Specific Domain, Type, and Protocol Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Illustrates the creation of a raw socket using specific constants for domain (e.g., IPV4), type (e.g., STREAM), and protocol (e.g., TCP). This provides fine-grained control over socket creation. ```rust let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; socket.bind(&addr)?; socket.listen(128)?; let (peer, peer_addr) = socket.accept()?; ``` -------------------------------- ### Get Control Buffer Length Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Use `control_len` to get the number of bytes actually filled in the control buffer. This is important for determining the amount of ancillary data that was received. ```rust pub fn control_len(&self) -> usize ``` ```rust let msg = MsgHdrMut::new() .with_control(&mut control_buf); let bytes = socket.recvmsg(&mut msg, 0)?; let control_bytes = msg.control_len(); ``` -------------------------------- ### Create Raw Socket with Manual Control Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Shows how to create a raw socket using `Socket::new_raw` for full manual control over flags, bypassing automatic platform-specific configurations. ```rust // Full manual control over flags let socket = Socket::new_raw(Domain::IPV4, Type::STREAM, None)?; // Now manually set flags as needed ``` -------------------------------- ### Get Raw Socket Receive Any Interface Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves a raw socket option to receive packets on any interface. Available on Linux and Android with the 'all' feature. ```rust #[cfg(all(feature = "all", any(target_os = "linux", target_os = "android")))] pub fn recv_any_interface(&self) -> io::Result ``` -------------------------------- ### unicast_hops_v6 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IPV6_UNICAST_HOPS` option for IPv6. ```APIDOC ## unicast_hops_v6 ### Description Get the `IPV6_UNICAST_HOPS` option (hop limit for IPv6). ### Method `unicast_hops_v6` ### Returns - **u32** - The current unicast hop limit. ``` -------------------------------- ### Create TCP and UDP Sockets Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Demonstrates creating TCP and UDP sockets using `Socket::new`. The protocol can be explicitly specified or auto-selected by the system. ```rust use socket2::{Socket, Domain, Type, Protocol}; // TCP socket (protocol auto-selected) let tcp = Socket::new(Domain::IPV4, Type::STREAM, None)?; // Explicit protocol let tcp_explicit = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP))?; // UDP socket let udp = Socket::new(Domain::IPV4, Type::DGRAM, None?); ``` -------------------------------- ### Get IP_HDRINCL Option (IPv4) Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IP_HDRINCL option, used for raw sockets where the user supplies the IP header. This is available on most platforms except Redox, esp-idf, WASI, and Horizon. ```rust #[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf", target_os = "wasi", target_os = "horizon"))))] pub fn header_included_v4(&self) -> io::Result ``` -------------------------------- ### multicast_hops_v6 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IPV6_MULTICAST_HOPS` option for IPv6. ```APIDOC ## multicast_hops_v6 ### Description Get the `IPV6_MULTICAST_HOPS` option. ### Method `multicast_hops_v6` ### Returns - **u32** - The current multicast hop limit. ``` -------------------------------- ### Create and Bind a TCP Socket Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Demonstrates the creation of a new TCP socket, binding it to a specific address, and setting it to listen for incoming connections. Reuse address option is enabled to allow quick restarts. ```rust use socket2::{Socket, Domain, Type}; use std::net::SocketAddr; let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; socket.set_reuse_address(true)?; let addr: SocketAddr = "127.0.0.1:8080".parse()?; socket.bind(&addr.into())?; socket.listen(128)?; loop { let (peer, peer_addr) = socket.accept()?; handle_client(peer, peer_addr)?; } ``` -------------------------------- ### Get SO_OOBINLINE socket option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the `SO_OOBINLINE` option, which determines if out-of-band data is included in the normal receive data stream. This option is not available on Redox or WASI. ```rust #[cfg(not(any(target_os = "redox", target_os = "wasi")))] pub fn out_of_band_inline(&self) -> io::Result ``` -------------------------------- ### multicast_loop_v6 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IPV6_MULTICAST_LOOP` option for IPv6. ```APIDOC ## multicast_loop_v6 ### Description Get the `IPV6_MULTICAST_LOOP` option. ### Method `multicast_loop_v6` ### Returns - **bool** - The current state of the `IPV6_MULTICAST_LOOP` option. ``` -------------------------------- ### Enable Pass Credentials Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Enable SO_PASSCRED on Linux/Cygwin to receive SCM_CREDENTIALS control messages. ```rust #[cfg(any(target_os = "linux", target_os = "cygwin"))] pub fn set_passcred(&self, passcred: bool) -> io::Result<()>{ // implementation omitted } ``` -------------------------------- ### Bind and Listen for Connections Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Binds a socket to a local address and prepares it to accept incoming connections. The backlog parameter determines the maximum number of pending connections that can be queued. ```rust use socket2::{Socket, SockAddr, Type}; use std::io; use std::os::raw::c_int; fn main() -> io::Result<()> { let addr: SockAddr = "127.0.0.1:8080".parse().unwrap(); let socket = Socket::new(addr.domain(), Type::STREAM.into(), None)?; socket.bind(&addr)?; socket.listen(128)?; println!("Listening on: {:?}", socket.local_addr()?); // ... accept connections ... Ok(()) } ``` -------------------------------- ### ttl_v4 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IP_TTL` option for IPv4. ```APIDOC ## ttl_v4 ### Description Get the `IP_TTL` option (IPv4 TTL). ### Method `ttl_v4` ### Returns - **u32** - The current IPv4 TTL value. ``` -------------------------------- ### Create Unix Domain Socket Address Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Demonstrates the creation of a Unix domain socket address. This is specific to Unix-like systems and is used for inter-process communication on the same machine. ```rust // Unix domain (Unix only) let addr = SockAddr::unix("/tmp/socket")?; ``` -------------------------------- ### accept Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Accepts a new incoming connection on a listening socket. This method is used by servers to establish a connection with a client. It returns a new `Socket` instance for the connection and the peer's address. The flags are set similarly to the `new()` constructor. ```APIDOC ## accept ### Description Accepts a new incoming connection. Sets the same flags as `new()`. ### Method `accept` ### Returns - `io::Result<(Socket, SockAddr)>` — The connected socket and peer address, or error. ### Platform Notes - Uses `accept4(2)` with `SOCK_CLOEXEC` on Linux and related systems - Falls back to `accept(2)` on other systems ### Example ```rust let (peer_socket, peer_addr) = listener_socket.accept()?; ``` ``` -------------------------------- ### multicast_ttl_v4 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IP_MULTICAST_TTL` option for IPv4. ```APIDOC ## multicast_ttl_v4 ### Description Get the `IP_MULTICAST_TTL` option (TTL for multicast packets). ### Method `multicast_ttl_v4` ### Returns - **u32** - The current multicast TTL value. ``` -------------------------------- ### Enable IPv4 Transparent Proxying (Linux) Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Enable IP_TRANSPARENT on Linux/Android for transparent proxying. Requires CAP_NET_ADMIN capability. ```rust #[cfg(all(feature = "all", any(target_os = "linux", target_os = "android")))] pub fn set_ip_transparent_v4(&self, transparent: bool) -> io::Result<()>{ // implementation omitted } ``` -------------------------------- ### multicast_loop_v4 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the `IP_MULTICAST_LOOP` option for IPv4. ```APIDOC ## multicast_loop_v4 ### Description Get the `IP_MULTICAST_LOOP` option. ### Method `multicast_loop_v4` ### Returns - **bool** - The current state of the `IP_MULTICAST_LOOP` option. ``` -------------------------------- ### listen Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Marks the socket as ready to accept incoming connections. This function is essential for server-side sockets that need to listen for clients. It takes a backlog parameter to specify the maximum number of pending connections that can be queued. ```APIDOC ## listen ### Description Marks socket as ready to accept incoming connections. ### Method `listen` ### Parameters #### Path Parameters - **backlog** (*c_int*) - Required - Maximum pending connections ### Corresponds to `listen(2)` on Unix and Windows ### Example ```rust socket.bind(&addr.into())?; socket.listen(128)?; ``` ``` -------------------------------- ### Connect to a TCP Address with Timeout Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Shows how to establish a TCP connection to a specified address with a defined timeout duration. This is useful for preventing applications from hanging indefinitely during connection attempts. ```rust use socket2::{Socket, Domain, Type}; use std::time::Duration; let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; let addr: std::net::SocketAddr = "192.0.2.1:80".parse()?; match socket.connect_timeout(&addr.into(), Duration::from_secs(5)) { Ok(_) => println!("Connected"), Err(e) => eprintln!("Connection failed: {}", e), } ``` -------------------------------- ### send_buffer_size Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the SO_SNDBUF option, which represents the send buffer size. ```APIDOC ## send_buffer_size ### Description Get the `SO_SNDBUF` option (send buffer size). ### Method `send_buffer_size` ### Returns - `io::Result` ``` -------------------------------- ### Enable Broadcast Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Enable SO_BROADCAST for sending UDP packets to broadcast addresses. ```rust pub fn set_broadcast(&self, broadcast: bool) -> io::Result<()>{ // implementation omitted } ``` -------------------------------- ### recv_buffer_size Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the SO_RCVBUF option, which represents the receive buffer size. ```APIDOC ## recv_buffer_size ### Description Get the `SO_RCVBUF` option (receive buffer size). ### Method `recv_buffer_size` ### Returns - `io::Result` ``` -------------------------------- ### Connect with Timeout Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/errors.md Demonstrates connecting to a socket address with a specified timeout. If the connection times out (TimedOut error), it prints an error message and returns the error. ```rust use std::time::Duration; fn connect_with_timeout( socket: &Socket, addr: &socket2::SockAddr, ) -> io::Result<()> { match socket.connect_timeout(addr, Duration::from_secs(5)) { Ok(_) => Ok(()), Err(e) if e.kind() == io::ErrorKind::TimedOut => { eprintln!("Connection timed out"); Err(e) } Err(e) => Err(e), } } ``` -------------------------------- ### SockAddr::domain Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Gets the corresponding `Domain` enum value for the SockAddr. ```APIDOC ## SockAddr::domain ### Description Get the corresponding `Domain` for this address. ### Method `pub const fn domain(&self) -> Domain` ### Returns `Domain` — The domain type. ### Example ```rust let domain = addr.domain(); match domain { socket2::Domain::IPV4 => println!("IPv4"), socket2::Domain::IPV6 => println!("IPv6"), _ => {} } ``` ``` -------------------------------- ### Raw Construction of Socket Address Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Illustrates the raw construction of a SockAddr using a closure that initializes the address storage via a system call. This is an advanced method for creating socket addresses. ```rust // Raw construction let (_, addr) = unsafe { SockAddr::try_init(|storage, len| { // Initialize via syscall Ok(()) })? }; ``` -------------------------------- ### Handling Socket Creation Errors Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/errors.md Shows how to handle potential errors when creating a new socket, specifically checking for `PermissionDenied` and `OutOfMemory` error kinds. ```rust match Socket::new(Domain::IPV4, Type::STREAM, None) { Ok(socket) => { /* use socket */ }, Err(e) => match e.kind() { io::ErrorKind::PermissionDenied => eprintln!("Need privileges"), io::ErrorKind::OutOfMemory => eprintln!("Out of memory"), _ => eprintln!("Error: {}", e), } } ``` -------------------------------- ### Enable All Socket2 Features Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Configure the `socket2` crate to enable all available features in a Cargo.toml file. This is necessary to use platform-specific APIs. ```toml socket2 = { version = "0.6", features = ["all"] } ``` -------------------------------- ### Get SO_SNDBUF Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the SO_SNDBUF option, which represents the send buffer size. ```rust pub fn send_buffer_size(&self) -> io::Result ``` -------------------------------- ### Get SO_RCVBUF Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the SO_RCVBUF option, which represents the receive buffer size. ```rust pub fn recv_buffer_size(&self) -> io::Result ``` -------------------------------- ### Socket::connect Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Initiates a connection to the specified address. This is used by clients to establish a connection to a server. ```APIDOC ## Socket::connect ### Description Initiates a connection to the specified address. This is used by clients to establish a connection to a server. ### Method `connect` ### Parameters #### Path Parameters - **address** (&SockAddr) - Required - The remote address to connect to ### Corresponds to `connect(2)` on Unix and Windows ### Notes - For non-blocking sockets, returns immediately with `WouldBlock` or `EINPROGRESS` - Socket options cannot be set while connecting (Windows restriction) ### Example ```rust let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; socket.bind(&"127.0.0.1:0".parse::().unwrap().into())?; let addr: SockAddr = "127.0.0.1:8080".parse::().unwrap().into(); socket.connect(&addr)?; ``` ``` -------------------------------- ### Initialize SockAddr via callback (unsafe) Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Initialize a SockAddr by calling a function with raw pointers. The caller's function must properly initialize the storage and set the length. ```rust use socket2::SockAddr; use std::io; let ((), addr) = unsafe { SockAddr::try_init(|storage, len| { // Call system function like getsockname // *len must be set correctly Ok(()) }) }?; ``` -------------------------------- ### control_len Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Gets the number of bytes of control data that were actually received in the control buffer. ```APIDOC ## control_len ### Description Get the number of bytes of control data received. ### Method `control_len` ### Returns `usize` — Bytes in control buffer that were filled. ### Notes Use this to determine how much ancillary data was actually received. ### Example ```rust let msg = MsgHdrMut::new() .with_control(&mut control_buf); let bytes = socket.recvmsg(&mut msg, 0)?; let control_bytes = msg.control_len(); ``` ``` -------------------------------- ### Socket::new Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Creates a new socket and sets platform-specific flags automatically. This is the primary way to create a new socket with common flags set. ```APIDOC ## Socket::new ### Description Creates a new socket and sets platform-specific flags automatically. This is the primary way to create a new socket with common flags set. ### Method `new` ### Parameters #### Path Parameters - **domain** (Domain) - Required - Communication domain (IPv4, IPv6, Unix, etc.) - **ty** (Type) - Required - Socket type (stream, datagram, raw, etc.) - **protocol** (Option) - Optional - Protocol (TCP, UDP, etc.) or `None` for system default ### Returns `io::Result` — The newly created socket or an error. ### Platform-Specific Behavior - **Unix:** Sets `FD_CLOEXEC` (close-on-exec) and on Apple platforms sets `NOSIGPIPE` - **Windows:** Makes the socket non-inheritable ### Corresponds to `socket(2)` on Unix, `WSASocketW` on Windows ### Example ```rust use socket2::{Socket, Domain, Type}; let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; // TCP socket over IPv4, protocol selected automatically ``` ``` -------------------------------- ### write_timeout Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the SO_SNDTIMEO option, which is the timeout for send calls. Returns None if blocking indefinitely. ```APIDOC ## write_timeout ### Description Get the `SO_SNDTIMEO` option. Returns `None` if blocking indefinitely. ### Method `write_timeout` ### Returns - `io::Result>` ``` -------------------------------- ### Socket Creation & Lifecycle Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/README.md Functions for creating, duplicating, binding, connecting, listening, accepting, and querying socket information. ```APIDOC ## Socket Creation & Lifecycle ### Description Functions for creating, duplicating, binding, connecting, listening, accepting, and querying socket information. ### Methods - `Socket::new()`: Create socket with platform flags. - `Socket::new_raw()`: Create without platform flags. - `Socket::pair()`: Create connected pair. - `Socket::pair_raw()`: Create connected pair without flags. - `Socket::try_clone()`: Duplicate socket handle. - `Socket::bind(address)`: Bind to address. - `Socket::connect(address)`: Connect to peer. - `Socket::connect_timeout(address, timeout)`: Connect with timeout. - `Socket::listen()`: Mark as listener. - `Socket::accept()`: Accept incoming connection. - `Socket::accept_raw()`: Accept without platform flags. - `Socket::local_addr()`: Query local address. - `Socket::peer_addr()`: Query peer address. - `Socket::r#type()`: Query socket type. - `Socket::shutdown()`: Shutdown read/write. ``` -------------------------------- ### reuse_address Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the SO_REUSEADDR option, which controls whether the socket can be bound to an address that is in a TIME_WAIT state. ```APIDOC ## reuse_address ### Description Get the `SO_REUSEADDR` option. ### Method `reuse_address` ### Returns - `io::Result` ``` -------------------------------- ### Create a pair of connected Unix domain sockets Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Use `Socket::pair` to create two connected sockets. This is available on Unix-like systems and requires the `all` feature. It sets common flags like `CLOEXEC`. ```rust #[cfg(all(feature = "all", unix))] { use socket2::{Socket, Domain, Type}; let (socket1, socket2) = Socket::pair(Domain::UNIX, Type::STREAM, None)?; } ``` -------------------------------- ### read_timeout Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the SO_RCVTIMEO option, which is the timeout for receive calls. Returns None if blocking indefinitely. ```APIDOC ## read_timeout ### Description Get the `SO_RCVTIMEO` option. Returns `None` if blocking indefinitely. ### Method `read_timeout` ### Returns - `io::Result>` ``` -------------------------------- ### Get TCP NoDelay Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the TCP_NODELAY option. This option disables Nagle's algorithm. ```rust pub fn tcp_nodelay(&self) -> io::Result ``` -------------------------------- ### Create SockAddr from raw storage (unsafe) Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Create a SockAddr from raw storage and length. Caller must ensure the address family matches the storage type, the length is correct for the address type, and the storage is properly initialized. ```rust use socket2::{SockAddr, SockAddrStorage}; use std::mem::size_of; let storage = SockAddrStorage::zeroed(); let len = size_of::() as u32; let addr = unsafe { SockAddr::new(storage, len) }; ``` -------------------------------- ### Get SO_KEEPALIVE socket option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the `SO_KEEPALIVE` option, which determines if keep-alive probes are enabled for the socket. ```rust pub fn keepalive(&self) -> io::Result ``` -------------------------------- ### Get IPv6 Only Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IPV6_V6ONLY option. When false, dual-stack sockets can accept both IPv4 and IPv6 traffic. ```rust pub fn only_v6(&self) -> io::Result ``` -------------------------------- ### Configure TcpListener using SockRef Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Creates a `SockRef` from a `TcpListener` to configure socket options like `SO_REUSEADDR`. This demonstrates applying `socket2`'s configuration capabilities to listener sockets. ```rust use std::net::TcpListener; use socket2::SockRef; let listener = TcpListener::bind("127.0.0.1:0")?; let sock_ref = SockRef::from(&listener); sock_ref.set_reuse_address(true)?; ``` -------------------------------- ### Connect a socket to a remote address Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Use the `connect` method to establish a connection to a remote address. For non-blocking sockets, this may return `WouldBlock` or `EINPROGRESS` immediately. ```rust let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; socket.bind(&"127.0.0.1:0".parse::().unwrap().into())?; let addr: SockAddr = "127.0.0.1:8080".parse::().unwrap().into(); socket.connect(&addr)?; ``` -------------------------------- ### Socket Options - Generic (SOL_SOCKET) Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/README.md Functions for configuring generic socket options. ```APIDOC ## Socket Options - Generic (SOL_SOCKET) ### Description Functions for configuring generic socket options. ### Methods - `Socket::broadcast()` / `set_broadcast(enabled)`: SO_BROADCAST. - `Socket::keepalive()` / `set_keepalive(enabled)`: SO_KEEPALIVE. - `Socket::tcp_keepalive()` / `set_tcp_keepalive(duration)`: TCP keepalive (advanced). - `Socket::linger()` / `set_linger(linger)`: SO_LINGER. - `Socket::out_of_band_inline()` / `set_out_of_band_inline(enabled)`: SO_OOBINLINE. - `Socket::reuse_address()` / `set_reuse_address(enabled)`: SO_REUSEADDR. - `Socket::recv_buffer_size()` / `set_recv_buffer_size(size)`: SO_RCVBUF. - `Socket::send_buffer_size()` / `set_send_buffer_size(size)`: SO_SNDBUF. - `Socket::read_timeout()` / `set_read_timeout(duration)`: SO_RCVTIMEO. - `Socket::write_timeout()` / `set_write_timeout(duration)`: SO_SNDTIMEO. - `Socket::take_error()`: SO_ERROR. - `Socket::passcred()` / `set_passcred(enabled)`: SO_PASSCRED (Linux/Cygwin). - `Socket::priority()` / `set_priority(priority)`: SO_PRIORITY (Linux/Android/Fuchsia). ``` -------------------------------- ### ip_transparent_v4 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Get the IP_TRANSPARENT option for IPv4 sockets. This option is available on Linux and Android and allows for transparent proxying. ```APIDOC ## ip_transparent_v4 ### Description Get the `IP_TRANSPARENT` option (Linux/Android only). ### Method `ip_transparent_v4` ### Returns - `io::Result` ``` -------------------------------- ### Get IP_TRANSPARENT Option (IPv4) Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IP_TRANSPARENT option, used for transparent proxying. This is available on Linux and Android. ```rust #[cfg(all(feature = "all", any(target_os = "linux", target_os = "android")))] pub fn ip_transparent_v4(&self) -> io::Result ``` -------------------------------- ### SockAddr Methods Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/README.md Provides methods for creating, initializing, and inspecting socket addresses, including type checks and conversions. ```APIDOC ## SockAddr Methods ### Description Methods for creating, initializing, and inspecting socket addresses. ### Methods - `SockAddr::new()` — Create from storage and length (Unsafe) - `SockAddr::try_init()` — Initialize via callback (Unsafe) - `SockAddr::unix()` — Create Unix domain address - `SockAddr::family()` — Get address family - `SockAddr::domain()` — Get corresponding Domain - `SockAddr::len()` — Get address length - `SockAddr::as_ptr()` — Get raw pointer - `SockAddr::as_socket()` — Convert to std::net::SocketAddr - `SockAddr::as_storage()` — Get raw storage - `SockAddr::is_ipv4()` — Type check for IPv4 - `SockAddr::is_ipv6()` — Type check for IPv6 - `SockAddr::is_unix()` — Type check for Unix domain socket ### Traits Implemented - `Clone` — Clone addresses - `Debug` — Debug formatting - `From`, `From`, `From` ``` -------------------------------- ### Create Zeroed SockAddrStorage Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Creates a new SockAddrStorage with all bytes initialized to zero. This is useful for initializing storage before viewing it as a specific sockaddr type. ```rust use socket2::SockAddrStorage; let mut storage = SockAddrStorage::zeroed(); ``` -------------------------------- ### Get SO_REUSEADDR Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the SO_REUSEADDR option, which controls whether to allow binding to addresses in a TIME_WAIT state. ```rust pub fn reuse_address(&self) -> io::Result ``` -------------------------------- ### SockAddrStorage Methods Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Provides methods for creating, inspecting, and viewing raw socket address storage. ```APIDOC ## SockAddrStorage Raw socket address storage for direct system calls. **Import:** `use socket2::SockAddrStorage;` ### Methods #### zeroed ```rust pub fn zeroed() -> Self ``` Create a zeroed storage (all bytes are zero). **Returns:** `SockAddrStorage` — Zeroed storage. **Example:** ```rust use socket2::SockAddrStorage; let mut storage = SockAddrStorage::zeroed(); ``` #### size_of ```rust pub fn size_of(&self) -> socklen_t ``` Get the size of this storage in bytes. **Returns:** `socklen_t` — Always the same (platform-dependent, typically 128 bytes). #### view_as (unsafe) ```rust pub unsafe fn view_as(&mut self) -> &mut T ``` View this storage as another sockaddr type. | Parameter | Type | Description | |-----------|------|-------------| | T | — | Target type (e.g., `sockaddr_in`, `sockaddr_in6`) | **Returns:** `&mut T` — Mutable reference to the same memory as target type. **Safety:** - `T` must be a valid sockaddr type for this platform - Size of `T` must not exceed storage size **Example:** ```rust use socket2::SockAddrStorage; use libc::sockaddr_in; let mut storage = SockAddrStorage::zeroed(); let addr_in = unsafe { storage.view_as::() }; addr_in.sin_port = 8080_u16.to_be(); ``` ``` -------------------------------- ### Get IPv4 TTL Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IP_TTL option for IPv4, which sets the Time-To-Live for outgoing unicast IP packets. ```rust pub fn ttl_v4(&self) -> io::Result ``` -------------------------------- ### Accept Incoming Connection Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Accepts a new incoming connection on a listening socket. This operation returns a new socket for communication with the peer and the peer's address. It uses `accept4` with `SOCK_CLOEXEC` on Linux for efficiency and security. ```rust let (peer_socket, peer_addr) = listener_socket.accept()?; ``` -------------------------------- ### Get IPv4 Multicast TTL Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IP_MULTICAST_TTL option for IPv4, which determines the Time-To-Live for outgoing multicast packets. ```rust pub fn multicast_ttl_v4(&self) -> io::Result ``` -------------------------------- ### Get SO_SNDTIMEO Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the SO_SNDTIMEO option, which is the timeout for send operations. Returns None if the socket is blocking indefinitely. ```rust pub fn write_timeout(&self) -> io::Result> ``` -------------------------------- ### Join a Multicast Group Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Demonstrates joining a specific IPv4 multicast group on a UDP socket. This is essential for applications that need to send or receive data from multiple recipients simultaneously using multicast. ```rust use std::net::Ipv4Addr; let socket = Socket::new(Domain::IPV4, Type::DGRAM, None)?; socket.set_reuse_address(true)?; let addr: std::net::SocketAddr = "0.0.0.0:5353".parse()?; socket.bind(&addr.into())?; // Join multicast group 224.0.0.1 let group = Ipv4Addr::new(224, 0, 0, 1); let interface = Ipv4Addr::UNSPECIFIED; socket.join_multicast_v4(&group, &interface)?; ``` -------------------------------- ### Get SO_RCVTIMEO Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the SO_RCVTIMEO option, which is the timeout for receive operations. Returns None if the socket is blocking indefinitely. ```rust pub fn read_timeout(&self) -> io::Result> ``` -------------------------------- ### Configure Standard Library Socket with Socket2 Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/getting-started.md Adapt a standard library `TcpListener` socket using `socket2::SockRef`. This allows applying advanced socket options not directly available through the standard library API. ```rust use std::net::TcpListener; use socket2::SockRef; let listener = TcpListener::bind("127.0.0.1:8080")?; let socket = SockRef::from(&listener); socket.set_reuse_address(true)?; socket.set_tcp_nodelay(true)?; socket.set_nonblocking(true)? ``` -------------------------------- ### Create and Configure MsgHdr with Buffers Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Demonstrates creating a message header and setting the data buffers for a sendmsg operation. Requires the MsgHdr struct. ```rust use std::io::IoSlice; let data1 = b"Hello "; let data2 = b"World"; let bufs = [ IoSlice::new(data1), IoSlice::new(data2), ]; let msg = MsgHdr::new() .with_buffers(&bufs); ``` -------------------------------- ### Get SO_PRIORITY Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the SO_PRIORITY option, which affects packet queueing discipline. This is available on Linux, Android, and Fuchsia. ```rust #[cfg(all(feature = "all", any(target_os = "linux", target_os = "android", target_os = "fuchsia")))] pub fn priority(&self) -> io::Result ``` -------------------------------- ### Create Unix domain socket address Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Create a Unix domain socket address from a path. Returns an error if the path exceeds SUN_LEN. ```rust use socket2::SockAddr; let addr = SockAddr::unix("/tmp/mysocket")?; ``` -------------------------------- ### keepalive Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Gets the `SO_KEEPALIVE` socket option using the `keepalive` method. This option determines if keep-alive messages are enabled for the socket. ```APIDOC ## keepalive ### Description Get the `SO_KEEPALIVE` option. ### Method `keepalive` ### Parameters None ### Response #### Success Response - **bool** - `true` if keep-alive is enabled, `false` otherwise. #### Response Example ```rust // Example usage (assuming `socket` is a reference to a Socket) let is_keepalive_enabled = socket.keepalive()?; println!("Keepalive enabled: {}", is_keepalive_enabled); ``` ``` -------------------------------- ### SockAddr::try_init Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-addresses.md Initializes a SockAddr by calling a provided function with raw pointers to storage and length. This is an unsafe operation requiring the caller's function to correctly initialize the storage and set the length. ```APIDOC ## SockAddr::try_init ### Description Initialize a `SockAddr` by calling a function with raw pointers. ### Method `unsafe fn try_init(init: F) -> io::Result<(T, SockAddr)>` where F: FnOnce(*mut SockAddrStorage, *mut socklen_t) -> io::Result, ### Parameters #### Path Parameters - **init** (Fn(storage, len) -> Result) - Required - Function to initialize storage ### Returns `io::Result<(T, SockAddr)>` — Function result and the initialized address. ### Safety Caller's function must properly initialize the storage and set the length. ### Example ```rust use socket2::SockAddr; use std::io; let ((), addr) = unsafe { SockAddr::try_init(|storage, len| { // Call system function like getsockname // *len must be set correctly Ok(()) }) }?; ``` ``` -------------------------------- ### Get SO_PASSCRED socket option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the `SO_PASSCRED` option, which is used on Linux and Cygwin to obtain credentials of the sender of a message. ```rust #[cfg(any(target_os = "linux", target_os = "cygwin"))] pub fn passcred(&self) -> io::Result ``` -------------------------------- ### Get SO_BROADCAST socket option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the `SO_BROADCAST` option, which indicates whether the socket is allowed to send broadcast messages. ```rust pub fn broadcast(&self) -> io::Result ``` -------------------------------- ### High-Performance TCP Server Configuration Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Sets up a TCP socket for high performance by enabling address reuse, large buffers, disabling Nagle's algorithm, and setting non-blocking mode. ```rust use socket2::{Socket, Domain, Type, TcpKeepalive}; use std::time::Duration; let socket = Socket::new(Domain::IPV4, Type::STREAM, None)?; socket.set_reuse_address(true)?; socket.set_recv_buffer_size(256 * 1024)?; // 256KB socket.set_send_buffer_size(256 * 1024)?; // 256KB socket.set_tcp_nodelay(true)?; // Low latency socket.set_nonblocking(true)?; // Non-blocking for event loop socket.bind(&addr)?; socket.listen(1024)?; // Large backlog ``` -------------------------------- ### TcpKeepalive::with_time Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Sets the time before keepalive probes start. This method updates the keepalive configuration and returns the modified configuration. ```APIDOC ## TcpKeepalive::with_time ### Description Set the time before keepalive probes start. ### Parameters - **time** (`Duration`) - Time before first probe ### Returns `Self` — Updated configuration. ### Platform Mapping: - **macOS/iOS:** `TCP_KEEPALIVE` - **Other Unix:** `TCP_KEEPIDLE` - **Windows:** `tcp_keepalive.keepalivetime` ### Notes Some platforms only support second precision; subsecond values are truncated. ### Example ```rust let keepalive = TcpKeepalive::new() .with_time(Duration::from_secs(60)); socket.set_tcp_keepalive(keepalive)?; ``` ``` -------------------------------- ### Create a Unix Domain Sequenced Packet Socket Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Creates a new socket for Unix domain communication using the sequenced packet type. Requires the 'all' feature and is not available on espidf, WASI, or Horizon. ```rust #[cfg(all(feature = "all", not(any(target_os = "espidf", target_os = "wasi", target_os = "horizon"))))] { let socket = Socket::new(Domain::UNIX, Type::SEQPACKET, None)?; } ``` -------------------------------- ### Create an IPv4 Raw Socket with ICMPv4 Protocol Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Creates a raw socket for IPv4 communication, specifying the ICMPv4 protocol for direct access. Requires the 'all' feature and is not available on Redox, espidf, WASI, or Horizon. Note: Requires elevated privileges. ```rust #[cfg(all(feature = "all", target_os = "linux"))] { use socket2::Protocol; let socket = Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::ICMPV4))?; } ``` -------------------------------- ### Get IPv6 Unicast Hops Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IPV6_UNICAST_HOPS option, which sets the hop limit for outgoing IPv6 unicast packets. ```rust pub fn unicast_hops_v6(&self) -> io::Result ``` -------------------------------- ### Get IPv6 Multicast Hops Option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the IPV6_MULTICAST_HOPS option, which sets the hop limit for outgoing IPv6 multicast packets. ```rust pub fn multicast_hops_v6(&self) -> io::Result ``` -------------------------------- ### Set IPv4 Multicast All Interfaces (Linux) Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Set IP_MULTICAST_ALL on Linux to deliver multicast to all interfaces. ```rust #[cfg(all(feature = "all", target_os = "linux"))] pub fn set_multicast_all_v4(&self, multicast_all: bool) -> io::Result<()>{ // implementation omitted } ``` -------------------------------- ### broadcast Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Gets the `SO_BROADCAST` socket option using the `broadcast` method. This option controls whether to allow sending to broadcast addresses. ```APIDOC ## broadcast ### Description Get the `SO_BROADCAST` option (allow sending to broadcast addresses). ### Method `broadcast` ### Parameters None ### Response #### Success Response - **bool** - `true` if broadcast is enabled, `false` otherwise. #### Response Example ```rust // Example usage (assuming `socket` is a reference to a Socket) let is_broadcast_enabled = socket.broadcast()?; println!("Broadcast enabled: {}", is_broadcast_enabled); ``` ``` -------------------------------- ### Configure TCP Keepalive Parameters Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/configuration.md Sets detailed TCP keepalive parameters like idle time, probe interval, and retries using `set_tcp_keepalive`. Ensure `SO_KEEPALIVE` is enabled first. ```rust use socket2::TcpKeepalive; use std::time::Duration; let keepalive = TcpKeepalive::new() .with_time(Duration::from_secs(60)) // Start after 60s idle .with_interval(Duration::from_secs(5)) // Probe every 5s .with_retries(3); // Max 3 probes socket.set_keepalive(true)?; socket.set_tcp_keepalive(keepalive)?; ``` -------------------------------- ### Get SO_LINGER socket option Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-socket.md Retrieves the `SO_LINGER` option, which controls how socket closures are handled. Returns `None` if linger is disabled. ```rust pub fn linger(&self) -> io::Result> ``` -------------------------------- ### DCCP Protocol Definition Source: https://github.com/rust-lang/socket2/blob/master/_autodocs/api-reference-enums.md Defines the DCCP protocol constant. Requires the 'all' feature and is only available on Linux. ```rust #[cfg(all(feature = "all", target_os = "linux"))] pub const DCCP: Protocol = Protocol(/* IPPROTO_DCCP */); ```