使用C ++对ipv6地址进行比较操作 [英] Comparison operations on ipv6 address using C++
问题描述
hi
由于IPV6地址有16个字节,并且它们没有数据类型存储在c ++中,
i希望存储IPV6地址,并在IPv6地址和
之间做一些比较请让我知道如何做
hi As IPV6 address has 16 bytes and their is no data type to store it in c++, i wanted to store the IPV6 address, and do some comparisions between to IPv6 address, please let me know how to do it
推荐答案
您可以将它们存储为 unsigned char
s。像 unsigned char ipv6 [16];
例如。然后你可以使用任何数组比较算法进行比较。使用 char *
算法不是一个选项,因为您的ipv6地址的某些字节可能是 0x00
基于字符串的算法的字符串结束字符。
You can store those as plain arrays of unsigned char
s as you would do in C. Like unsigned char ipv6[16];
for example. You could then compare them using any array comparison algorithm out there. Using char*
algorithms wouldn't be an option as some bytes of your ipv6 addresses could be 0x00
and thus interpreted as a string ending character by string-based algorithms.
这篇关于使用C ++对ipv6地址进行比较操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!