Crate socket2_plus
source ·Expand description
This library is a superset of socket2 crate and it aims
to provide some features with safe APIs currently missing from socket2. As the result, this
library can be used as a drop-in replacement of socket2.
The following are the additional features or APIs:
Utilities for creating and using sockets.
The goal of this crate is to create and use a socket using advanced configuration options (those that are not available in the types in the standard library) without using any unsafe code.
This crate provides as direct as possible access to the system’s
functionality for sockets, this means little effort to provide
cross-platform utilities. It is up to the user to know how to use sockets
when using this crate. If you don’t know how to create a socket using
libc/system calls then this crate is not for you. Most, if not all,
functions directly relate to the equivalent system call with no error
handling applied, so no handling errors such as EINTR. As a result using
this crate can be a little wordy, but it should give you maximal flexibility
over configuration of sockets.
§Examples
use std::net::{SocketAddr, TcpListener};
use socket2_plus::{Socket, Domain, Type};
// Create a TCP listener bound to two addresses.
let socket = Socket::new(Domain::IPV6, Type::STREAM, None)?;
socket.set_only_v6(false)?;
let address: SocketAddr = "[::1]:12345".parse().unwrap();
socket.bind(&address.into())?;
socket.listen(128)?;
let listener: TcpListener = socket.into();
// ...§Features
This crate has a single feature all, which enables all functions even ones
that are not available on all OSs.
Structs§
- Reference of a control message header in the control buffer in
MsgHdrInit - Specification of the communication domain for a socket.
- A version of
IoSliceMutthat allows the buffer to be uninitialised. - Configuration of a
sendmsg(2)system call. - Configuration of a
recvmsg(2)system call with initialized buffers. - Configuration of a
recvmsg(2)system call. - Represents IN_PKTINFO structure.
- Represents IN6_PKTINFO structure.
- Protocol specification used for creating sockets via
Socket::new. - Recv
Flags Non-Redox Flags for incoming messages. - The address of a socket.
- A reference to a
Socketthat can be used to configure socket types other than theSockettype itself. - Owned wrapper around a system socket.
- Configures a socket’s TCP keepalive parameters.
- Specification of communication semantics on a socket.
Enums§
- A local interface specified by its index or an address assigned to it.
Constants§
- constant for cmsg_level of IPPROTO_IP
- constant for cmsg_level of IPPROTO_IPV6
- constant for cmsghdr type in IPv6
- constant for cmsghdr type
Functions§
- Given a payload of
data_len, returns the number of bytes a control message occupies. i.e. it includes the header, the data and the alignments.
Type Aliases§
- Represents available protocols
- Represents available types of control messages.