Should I use binary(16)
or varbinary(16)
?
I know I can use getAddress()
in java.net.InetAddress
(Java) or System.Net.IPAddress
(C#) to get a byte[]
representation of both IPv4
and IPv6
, but if I need to insert IPv4
i.e. binary(4)
into a binary(16)
field in SQL Server
, do I need to worry about padding or anything?
With the dual-stack solution, every networking device, server, switch, router, and firewall in an ISP's network will be configured with both IPv4 and IPv6 connectivity capabilities. Most importantly, dual-stack technology allows ISPs to process IPv4 and IPv6 data traffic simultaneously.
As with MS SQL Server you can store IP address, both IPv4 and IPv6, either as varchar or as numeric. As already mentioned, the binary representation is much more preferable than any other as it reflects the true nature of an IP address. SELECT (split_part('192.168. 1.1', '.
PostgreSQL offers data types to store IPv4, IPv6, and MAC addresses, as shown in Table 8.21. It is better to use these types instead of plain text types to store network addresses, because these types offer input error checking and specialized operators and functions (see Section 9.12).
It's completely normal to have multiple IPv6 addresses on one device. A device generates new 64 bits every once in a while and uses that in the IPv6 address. Because new addresses are generated regularly the addresses are marked as temporary interfaces.
IF you store a binary(4)
in a binary(16)
column you'll get back, when you read it, a padded value of length 16. If you want to have dynamic length you must use a varbinary(16)
. This type retains the length of the data inserted, at the cost of adding extra 2 bytes on-disk (the actual length).
Use v4-in-v6 address embedding to convert your ipv4 addresses to ipv6 format; then you can treat them all identically.
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