I want to be able to store both IPv4 and IPv6 addresses in my table. What is the most efficient way to store the IP address of a user regardless of whether it is an IPv4 or IPv6 address?
This will be used in a production environment, so future proof'd suggestions are preferred.
IPv4 and IPv6 must coexist for some number of years, and their coexistence must be transparent to end users. If an IPv4-to-IPv6 transition is successful, end users should not even notice it. A dual-stack device is a device with network interfaces that can originate and understand both IPv4 and IPv6 packets.
“IPv4 and IPv6 addresses are not compatible. Pawlik [NRO chairma] said it was technically feasible to make the two types of IP address talk to each other, but it would be best for companies and ISPs to switch to IPv6 as soon as possible, to keep networks stable and avoid complexity when IPv4 addresses run out.”
Yes you can have both IPv4 and IPv6 addresses associated with the same dns name. As a general rule services should be made available over both ipv4 and ipv6 and the same public facing DNS name used for both.
What Is It? Dual stack means that devices are able to run IPv4 and IPv6 in parallel. It allows hosts to simultaneously reach IPv4 and IPv6 content, so it offers a very flexible coexistence strategy.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With