Under IPv4
I have been parsing the string representation of IP addresses to Int32
and storing them as INT
in the SQL Server
Just as an IPv4 address is really a 32 bit number, an IPv6 address is really a 128 bit number. There are different string representations of the addresses, but the actual address is the number, not the string.
So, you don't convert an IP address to a number, you parse a string representation of the address into the actual address.
Not even a decimal
can hold a 128 bit number, so that leaves three obvious alternatives:
bigint
fieldsvarchar
fieldbinary
fieldNeither is as convenient as storing an IPv4 address in an int
, so you have to consider their limitations against what you need to do with the addresses.