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 IPAddressNumber`and make the difference after the number of bytes from the vector.
The third approach was to use int128_t/uint128_t or __int128_t from gcc.
For this last case, I would like to know from which version of GCC these types are supported, for which platforms (especially IA-32/IA-64) and also if there are any known bugs. Also, which of the above solutions might be the most convenient one?