![]() |
jsocketpp 1.0
A cross-platform C++20 socket library.
|
Public utility functions for working with socket addresses, conversions, and formatting. More...

Functions | |
| std::string | jsocketpp::addressToString (const sockaddr_storage &addr) |
| Converts a socket address to a human-readable "IP:port" string. | |
| void | jsocketpp::stringToAddress (const std::string &str, sockaddr_storage &addr) |
| Parses an "IP:port" string into a sockaddr_storage structure. | |
Public utility functions for working with socket addresses, conversions, and formatting.
This module includes general-purpose helpers that simplify common socket-related tasks such as:
These functions are protocol-agnostic and can be used with TCP, UDP, and Unix domain sockets.
| std::string jsocketpp::addressToString | ( | const sockaddr_storage & | addr | ) |
Converts a socket address to a human-readable "IP:port" string.
This utility function transforms a sockaddr_storage structure into a string representation using getnameinfo(), suitable for logging, diagnostics, or display. It supports both IPv4 (AF_INET) and IPv6 (AF_INET6) addresses and outputs the address in the form:
For unknown or unsupported address families, the function returns "unknown".
| [in] | addr | A fully populated sockaddr_storage containing the IP address and port. |
| SocketException | If getnameinfo() fails to resolve the IP or port for the provided address. |
| void jsocketpp::stringToAddress | ( | const std::string & | str, |
| sockaddr_storage & | addr ) |
Parses an "IP:port" string into a sockaddr_storage structure.
This utility function takes a string of the form "host:port" and resolves it into a platform-compatible sockaddr_storage structure using getaddrinfo(). It supports both IPv4 and IPv6 addresses, including:
The resulting structure can be passed directly to socket functions like connect(), bind(), or sendto().
| [in] | str | The string to parse, in the format "ip:port". Must not include brackets around IPv6 addresses. |
| [out] | addr | The output sockaddr_storage structure to populate. |
| SocketException |
|