I would recommend storing each address in IPv6 format. There is an official mapping for this: IPv4-address IPv6 with mapping . It works as follows:
Take, for example, the IPv4 address 192.0.2.44
The IPv4 mapped IPv6 address will be ::ffff:192.0.2.44
Which can also be written as ::ffff:c000:022c ( 192 decimal c0 hexadecimal, etc.)
You can use the inet_pton() function to parse such addresses, and on my local system, the inet_ntop() function also outputs them in the most readable format ( ::ffff:192.0.2.44 ). Thus, you have only one format for working in your application.
Also see this related answer .
Sander steffann
source share