IPv6的格式在C#中的int和其存储在SQL Server格式、int、Server、SQL

2023-09-10 23:56:36 作者:- 终将陌路°/21

的IPv4 我一直在解析字符串再知识产权的presentation地址,的Int32 键,将它们存储为 INT SQL服务器

Under IPv4 I have been parsing the string representation of IP addresses to Int32 and storing them as INT in the SQL Server.

现在,用的IPv6 我试图找出是否有解析字符串再的presentation标准或接受的方式IPv6的两个的Int64 使用 C#

Now, with IPv6 I'm trying to find out if there's a standard or accepted way to parse the string representation of IPv6 to two Int64 using C#?

另外如何人在 SQL服务器存储这些价值观 - 以 BIGINT 的两个领域。

Also how are people storing those values in the SQL Server - as two fields of BIGINT?

推荐答案

正如IPv4地址的确是一个32位的数字,一个IPv6地址确实是一个128位的数字。有不同串重新$ P $地址的psentations,但实际地址是多少,而不是字符串。

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.

所以,你不要一个IP地址转换为数字,你解析字符串重新地址的presentation到实际的地址。

So, you don't convert an IP address to a number, you parse a string representation of the address into the actual address.

甚至没有一个十进制可容纳一个128位的数字,使叶片三个明显的替代方案:

Not even a decimal can hold a 128 bit number, so that leaves three obvious alternatives:

数值存储分割成两 BIGINT 字段 存储地址的字符串再presentation在 VARCHAR 字段 数值存储在一个16字节的字段 store the numeric value split into two bigint fields store a string representation of the address in a varchar field store the numeric value in a 16 byte binary field

无论是作为方便,在 INT 存储IPv4地址,所以你必须要考虑反对什么,你需要做的地址的局限性。

Neither 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.