How-To parse CIDR addresses into socket_address

The liberate::net::socket_address class also permits easy construction from string representations (in CIDR-style notation). We can optionally add a port.

Create from string
1liberate::net::socket_address addr{"192.168.0.1", 443};
2
3assert(address_type::AF_INET4 == addr.type());

From here, we can convert the address back, or access the port, etc.

Access port, string representation
1assert(443 == addr.port());
2assert(addr.cidr_str() == "192.168.0.1");
3assert(addr.full_str() == "192.168.0.1:443");