Commit eaea0f45 authored by aligungr's avatar aligungr

IPv6 support

parent ac447032
......@@ -30,7 +30,7 @@ static_assert(sizeof(long long) == sizeof(uint64_t));
static std::atomic<int> g_idCounter = 1;
static bool IPv6FromString(const char *szAddress, std::vector<uint8_t>& address)
static bool IPv6FromString(const char *szAddress, uint8_t *address)
{
auto asciiToHex = [](char c) -> int {
c |= 0x20;
......@@ -46,9 +46,7 @@ static bool IPv6FromString(const char *szAddress, std::vector<uint8_t>& address)
uint8_t colons = 0;
uint8_t pos = 0;
address.clear();
std::vector<uint8_t> emptyAddress{16};
address.insert(address.begin(), emptyAddress.begin(), emptyAddress.end());
memset(address, 0, 16);
for (uint8_t i = 1; i <= 39; i++)
{
......@@ -62,12 +60,12 @@ static bool IPv6FromString(const char *szAddress, std::vector<uint8_t>& address)
else if (szAddress[i] == '\0')
break;
}
for (uint8_t i = 0; i <= 39 && pos < address.size(); i++)
for (uint8_t i = 0; i <= 39 && pos < 16; i++)
{
if (szAddress[i] == ':' || szAddress[i] == '\0')
{
address.at(pos) = acc >> 8;
address.at(pos + 1) = acc;
address[pos] = acc >> 8;
address[pos + 1] = acc;
acc = 0;
if (colons && i && szAddress[i - 1] == ':')
......@@ -199,7 +197,7 @@ OctetString utils::IpToOctetString(const std::string &address)
else if (ipVersion == 6)
{
std::vector<uint8_t> data{16};
if (!IPv6FromString(address.c_str(), data))
if (!IPv6FromString(address.c_str(), data.data()))
return {};
return OctetString(std::move(data));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment