|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
A raw IP socket. More...
Classes | |
| struct | config |
| Raw socket configuration. More... | |
Public Member Functions | |
| raw_socket (ip_protocol protocol) | |
| Creates a new raw IPv4 socket for the given IP protocol. | |
| raw_socket (ip_protocol protocol, address_family fam) | |
| Creates a new raw socket for the given protocol and address family. | |
| raw_socket (const config &cfg) | |
| Creates a new raw socket with the given configuration. | |
| size_t | send (std::span< const std::byte > buf) |
| Sends a raw packet on a connected socket. | |
| result< size_t > | try_send (std::span< const std::byte > buf) |
| Sends a raw packet on a connected socket. | |
Static Public Member Functions | |
| static result< raw_socket > | make (ip_protocol protocol) |
| Creates a new raw IPv4 socket for the given IP protocol. | |
| static result< raw_socket > | make (ip_protocol protocol, address_family fam) |
| Creates a new raw socket for the given protocol and address family. | |
| static result< raw_socket > | make (const config &cfg) |
| Creates a new raw socket with the given configuration. | |
A raw IP socket.
The protocol (e.g. ip_protocol::icmp) selects the IP-layer protocol for which the socket is opened. Use send_to / recv_from for connectionless addressing, or connect() to set a default peer.
On IPv4 a received packet includes the 20-byte IP header that the stack prepends; the header is not part of an outgoing send and is added by the stack. As with datagram_socket, a send larger than the link can carry returns errc::message_too_long, and a receive into too small a buffer returns errc::message_too_long rather than truncating.
Ownership is exclusive: the socket is non-copyable and move-only. A moved-from socket may only be destroyed, move-assigned, or queried via is_open() (→ false) and idf_handle() (→ -1); calling any other method on it is undefined behavior. The destructor closes the socket if open.
Definition at line 50 of file raw_socket.hpp.
|
explicit |
Creates a new raw IPv4 socket for the given IP protocol.
| protocol | IP-layer protocol (e.g. ip_protocol::icmp). |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
| idfxx::net::raw_socket::raw_socket | ( | ip_protocol | protocol, |
| address_family | fam | ||
| ) |
Creates a new raw socket for the given protocol and address family.
| protocol | IP-layer protocol. |
| fam | Address family. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
Creates a new raw socket with the given configuration.
| cfg | Socket configuration. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
|
static |
Creates a new raw socket with the given configuration.
| cfg | Socket configuration. |
|
static |
Creates a new raw IPv4 socket for the given IP protocol.
| protocol | IP-layer protocol (e.g. ip_protocol::icmp). |
|
static |
Creates a new raw socket for the given protocol and address family.
| protocol | IP-layer protocol. |
| fam | Address family. |
Sends a raw packet on a connected socket.
| buf | Data to send. |
CONFIG_COMPILER_CXX_EXCEPTIONS is enabled. | std::system_error | on failure. |
buf.size() on success, since a raw packet is sent in full or not at all. Definition at line 158 of file raw_socket.hpp.
References idfxx::unwrap().
Sends a raw packet on a connected socket.
| buf | Data to send. |
buf.size() on success, since a raw packet is sent in full or not at all — or an error.