What's the best way to store a set of IPv6 addresses?
I am upgrading a legacy application that stores IPv4 addresses in a fixed-size unsigned array. Addresses are stored in host byte order. That is, it is ntohl()
'd when exiting the socket API and htonl()
' d when navigating to the socket API.
Now, to support IPv6, I'm wondering what to do with this array. Should I store the string representation and make it an array char[INET6_ADDRSTRLEN]
or even std::vector<std::string>
or std::set<std::string>
to support more addresses.
Or I could store structs in6_addr
, which is probably more efficient for handling what std::string
, but then I'm wondering how the network and host byte ordering applies here?
source to share