Supoort bracketed IPv6 in init_ipv6_port.

GitOrigin-RevId: 5452157d85fa5628a07e82fec20c92e8b0836508
This commit is contained in:
levlam 2020-05-16 17:30:16 +03:00
parent 06b053ff3e
commit 705ab4d415

View File

@ -310,6 +310,11 @@ Status IPAddress::init_ipv6_port(CSlice ipv6, int port) {
if (port <= 0 || port >= (1 << 16)) {
return Status::Error(PSLICE() << "Invalid [port=" << port << "]");
}
string ipv6_plain;
if (ipv6.size() > 2 && ipv6[0] == '[' && ipv6.back() == ']') {
ipv6_plain.assign(ipv6.begin() + 1, ipv6.size() - 2);
ipv6 = ipv6_plain;
}
std::memset(&ipv6_addr_, 0, sizeof(ipv6_addr_));
ipv6_addr_.sin6_family = AF_INET6;
ipv6_addr_.sin6_port = htons(static_cast<uint16>(port));