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?

+3


source to share


1 answer


in6_addr requires the address to be in network byte order. in6_addr internally stores the ipv6 address as a concatenation of 16 characters, 8 shorts, 4 ints.



0


source







All Articles