## Crate socket2

Source
Expand description

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::{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§

CcidEndpoints
  See `Socket::dccp_available_ccids`.
Domain
  Specification of the communication domain for a socket.
MaybeUninitSlice
  A version of `IoSliceMut` that allows the buffer to be uninitialised.
MsgHdr
  Configuration of a `sendmsg(2)` system call.
MsgHdrMut
  Configuration of a `recvmsg(2)` system call.
Protocol
  Protocol specification used for creating sockets via `Socket::new`.
RecvFlags
  Flags for incoming messages.
SockAddr
  The address of a socket.
SockAddrStorage
  Rust version of the `sockaddr_storage` type.
SockFilter
  Berkeley Packet Filter (BPF).
SockRef
  A reference to a `Socket` that can be used to configure socket types other than the `Socket` type itself.
Socket
  Owned wrapper around a system socket.
TcpKeepalive
  Configures a socket’s TCP keepalive parameters.
Type
  Specification of communication semantics on a socket.

## Enums§

InterfaceIndexOrAddress
  A local interface specified by its index or an address assigned to it.

## Type Aliases§

sa_family_t
  The integer type for the `ss_family` field on this platform.
socklen_t
  The integer type used with `getsockname` on this platform.