1 | #include "IPv6ToBinary.h" |
2 | #include <Poco/Net/IPAddress.h> |
3 | #include <cstring> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | std::array<char, 16> IPv6ToBinary(const Poco::Net::IPAddress & address) |
10 | { |
11 | std::array<char, 16> res; |
12 | |
13 | if (Poco::Net::IPAddress::IPv6 == address.family()) |
14 | { |
15 | memcpy(res.data(), address.addr(), 16); |
16 | } |
17 | else if (Poco::Net::IPAddress::IPv4 == address.family()) |
18 | { |
19 | /// Convert to IPv6-mapped address. |
20 | memset(res.data(), 0, 10); |
21 | res[10] = '\xFF'; |
22 | res[11] = '\xFF'; |
23 | memcpy(&res[12], address.addr(), 4); |
24 | } |
25 | else |
26 | memset(res.data(), 0, 16); |
27 | |
28 | return res; |
29 | } |
30 | |
31 | } |
32 | |