Efficient way to store IPv4/IPv6 addresses

前端 未结 3 1634
春和景丽
春和景丽 2021-01-12 06:27

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 e

3条回答
  •  情话喂你
    2021-01-12 07:00

    According to this thread __int128_t and __uint128_t were introduced somewhere around version 4.2. And according to GCC's documentation __int128 and its unsigned counterpart unsigned __int128 are supported since GCC 4.6.4.

    Note that an unportable 128-bit integer is definitely not the appropriate type to save and work with IPv6 addresses. As mentioned in the comments there are special data structures for this, like sockaddr_in6.

提交回复
热议问题