I would recommend to store every address in IPv6 format. There is an official mapping for that: the IPv4-mapped IPv6 address. It works like this:
Take for example IPv4 address 192.0.2.44
The IPv4-mapped IPv6 address would be ::ffff:192.0.2.44
Which can also be written as ::ffff:c000:022c
(192
decimal is 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
). That way you only have one format to deal with in your application.
Also see this related answer.