我确实知道一种方法,
const struct in6_addr naddr6 = { {
0x3f, 0xfe, 0x05, 0x01,
0x00, 0x08, 0x00, 0x00,
0x02, 0x60, 0x97, 0xff,
0xfe, 0x40, 0xef, 0xab
}};
但不能用这个,
const struct in6_addr naddr6 =
{ { { 0x3ffe0501, 0x00080000, 0x026097ff, 0xfe40efab } } };
看起来我可以是brackets.Why的1/2/3的巴黎?
谢谢。
发布于 2009-11-10 22:15:46
因为需要指出它正在寻址的地址形式(使用C99显示):
const struct in6_addr naddr6 =
{ { .u6_addr32 = { 0x3ffe0501, 0x00080000, 0x026097ff, 0xfe40efab } } };
第一对括号用于in6_addr结构,第二对用于联合:
struct in6_addr
{
union
{
uint8_t u6_addr8[16];
uint16_t u6_addr16[8];
uint32_t u6_addr32[4];
} in6_u;
};
发布于 2009-11-21 05:54:00
可移植的方法如下所示:
struct in6_addr s6 = { };
if (!IN6_IS_ADDR_UNSPECIFIED(&s6))
inet_pton(AF_INET6, "2001:db8::1", &s6);
https://stackoverflow.com/questions/1708030
复制相似问题