boost::corosio::parse_endpoint

Parse an endpoint from a string.

Synopsis

[[nodiscard]]
std::error_code
parse_endpoint(
    std::string_view s,
    endpoint& ep) noexcept;

Description

This function parses an endpoint string in one of the following formats:

  • IPv4 without port: `192.168.1.1`

  • IPv4 with port: `192.168.1.1:8080`

  • IPv6 without port: `::1` or `2001:db8::1`

  • IPv6 with port (bracketed): `[::1]:8080`

Example

endpoint ep;
if (auto ec = parse_endpoint("192.168.1.1:8080", ep); !ec) {
    // ep.is_v4() == true
    // ep.port() == 8080
}

if (auto ec = parse_endpoint("[::1]:443", ep); !ec) {
    // ep.is_v6() == true
    // ep.port() == 443
}

Return Value

An error code (empty on success).

Parameters

Name Description

s

The string to parse.

ep

The endpoint to store the result.

Created with MrDocs