18 #include <boost/regex.hpp>
21 std::pair<std::string, std::string>
parse_network_address(
const std::string& address,
const std::string& default_port)
23 const char* address_re =
"\\[([[:xdigit:]:]*)\\](:([[:alnum:]]*))?|([[:alnum:]\\-_\\.]{1,253})(:([[:alnum:]]*))?";
26 boost::regex_match(address, m, boost::regex(address_re));
28 if(!m[1].str().empty()) {
29 return { m[1], m[3].str().empty() ? default_port : m[3] };
31 if(!m[4].str().empty()) {
32 return { m[4], m[6].str().empty() ? default_port : m[6] };
35 throw std::runtime_error(
"invalid address");
std::pair< std::string, std::string > parse_network_address(const std::string &address, const std::string &default_port)
Parse a host:port style network address, supporting [] notation for ipv6 addresses.