Efficient way to store IPv4/IPv6 addresses
I am working on a C/C++ networking project that it should be able to both use the IPv4 and IPv6 networking stacks. The project works only on Linux. So, I tried to find an efficient way to store the IP addresses and differentiate between the protocol families. The first approach was to have a union: struct ip_addr { uint8_t fam; // socket family type union { struct in_addr ipv4_sin_addr; struct in6_addr ipv6_sin_addr; }addr; }; The second approach was to define a typedef std::vector<unsigned char> IPAddressNumber and make the difference after the number of bytes from the vector. The third