3

I'm modernizing a legacy application that stores IPv4 addresses in a fixed-size array of unsigned longs. The addresses are stored in host byte order. That is, it is ntohl()'d when coming from the socket API and htonl()'d when going to the socket API.

Now in order to support IPv6 as well, I'm wondering what to do with this array. Whether I should store the string representation, and make it an array of char[INET6_ADDRSTRLEN] or even a std::vector<std::string> or std::set<std::string> to support more addresses.

Or, I could store the in6_addr structs, which is probably way more efficient to work with than a std::string, but then I'm wondering how does network and host byte order apply here?

Michael Hampton
  • 9,737
  • 4
  • 55
  • 96
Philipp
  • 957
  • 1
  • 6
  • 20

1 Answers1

0

in6_addr does require the address to be in network byte order. in6_addr internally stores ipv6 address as a union of 16 chars, 8 shorts, 4 ints.