![]() |
jsocketpp 1.0
A cross-platform C++20 socket library.
|
Internal types, platform abstractions, and utility functions used across the jsocketpp library. More...

Namespaces | |
| namespace | jsocketpp::net |
| Endianness utilities for network byte order conversion. | |
Classes | |
| struct | jsocketpp::BufferView |
| Represents a raw writable memory region for scatter/gather I/O. More... | |
Typedefs | |
| using | jsocketpp::Port = std::uint16_t |
| Type alias representing a TCP or UDP port number (1–65535). | |
Functions | |
| bool | jsocketpp::isIPv4MappedIPv6 (const sockaddr_in6 *addr6) |
| Checks if a given sockaddr_in6 represents an IPv4-mapped IPv6 address. | |
| sockaddr_in | jsocketpp::convertIPv4MappedIPv6ToIPv4 (const sockaddr_in6 &addr6) |
| Converts an IPv4-mapped IPv6 address to a pure IPv4 sockaddr_in. | |
| void | jsocketpp::internal::resolveNumericHostPort (const sockaddr *sa, const socklen_t len, std::string &host, Port &port) |
| Resolve numeric host and port from a socket address. | |
Variables | |
| constexpr std::size_t | jsocketpp::DefaultBufferSize = 4096 |
| Default internal buffer size (in bytes) for socket read operations. | |
| constexpr std::size_t | jsocketpp::DefaultDatagramReceiveSize = 8192 |
| Fallback receive size (in bytes) for UDP datagrams when the exact size is unknown. | |
| constexpr std::size_t | jsocketpp::MaxDatagramPayloadSafe = 65507 |
| Maximum UDP payload size (in bytes) that is safely valid across common stacks. | |
| constexpr std::size_t | jsocketpp::MaxUdpPayloadIPv4 = 65507 |
| Maximum UDP payload size (in bytes) over IPv4. | |
| constexpr std::size_t | jsocketpp::MaxUdpPayloadIPv6 = 65527 |
| Theoretical maximum UDP payload size (in bytes) over IPv6. | |
Internal types, platform abstractions, and utility functions used across the jsocketpp library.
This group contains foundational components of the jsocketpp socket library, including common type aliases, byte-order conversion utilities, and cross-platform compatibility helpers.
Components in this group are typically not used directly by application-level code, but are essential for internal implementation and protocol correctness.
| using jsocketpp::Port = std::uint16_t |
Type alias representing a TCP or UDP port number (1–65535).
This alias provides strong typing for network port numbers across the jsocketpp library. It improves readability and makes function signatures semantically clearer when dealing with socket operations.
Using Port instead of a plain uint16_t or unsigned short helps:
|
inline |
Converts an IPv4-mapped IPv6 address to a pure IPv4 sockaddr_in.
This function extracts the embedded IPv4 address from an IPv4-mapped IPv6 address. It preserves the port number and fills a fully valid sockaddr_in.
| addr6 | A sockaddr_in6 known to be IPv4-mapped. |
|
inline |
Checks if a given sockaddr_in6 represents an IPv4-mapped IPv6 address.
IPv4-mapped IPv6 addresses allow IPv6-only sockets to interoperate with IPv4 clients by embedding an IPv4 address inside a special IPv6 format:
This function identifies such addresses so they can be normalized to pure IPv4.
| addr6 | Pointer to a sockaddr_in6 structure. |
|
inline |
Resolve numeric host and port from a socket address.
Calls getnameinfo() with NI_NUMERICHOST | NI_NUMERICSERV (and NI_NUMERICSCOPE where available) to obtain the sender’s numeric IP and service strings without DNS lookups. Parses the service string to a Port and validates it fits the type’s range. On failure, throws using the library’s cross-platform getnameinfo error pattern.
| [in] | sa | Pointer to a valid sockaddr (e.g., sockaddr_in/sockaddr_in6). |
| [in] | len | Size of the structure pointed to by sa. |
| [out] | host | Receives the numeric host string (e.g., "192.0.2.10", "fe80::1eth0"). |
| [out] | port | Receives the numeric service string (e.g., "8080"). |
| SocketException | If getnameinfo() fails. |
|
inlineconstexpr |
Default internal buffer size (in bytes) for socket read operations.
This constant defines the default size (4096 bytes / 4 KB) of the internal read buffer used across various socket classes in the library unless explicitly overridden.
Override this value by:
Increase if:
Decrease if:
|
inlineconstexpr |
Fallback receive size (in bytes) for UDP datagrams when the exact size is unknown.
This constant defines the default number of bytes we ask the OS to deliver when receiving a UDP datagram and the platform cannot report the pending datagram's exact size (via FIONREAD or the POSIX MSG_PEEK|MSG_TRUNC probe) and the caller has not provisioned _internalBuffer (i.e., its size is 0).
|
inlineconstexpr |
Maximum UDP payload size (in bytes) that is safely valid across common stacks.
This constant represents a conservative upper bound for a single UDP payload that is widely supported across platforms and socket APIs. It equals the IPv4 maximum payload:
65,535 (IPv4 total length) − 20 (minimum IPv4 header) − 8 (UDP header) = 65,507 bytes
MaxDatagramPayloadSafe to prevent oversizing.
|
inlineconstexpr |
Maximum UDP payload size (in bytes) over IPv4.
Computed as: 65,535 (IPv4 total length) − 20 (IPv4 header) − 8 (UDP header) = 65,507 bytes. Use this when you know the socket/address family is IPv4.
|
inlineconstexpr |
Theoretical maximum UDP payload size (in bytes) over IPv6.
Computed as: 65,535 (IPv6 payload length, excludes the 40-byte IPv6 header) − 8 (UDP header) = 65,527 bytes.