Frage

ich weiß, eine Methode, dies zu tun,

const struct in6_addr naddr6 = { { 
                0x3f, 0xfe, 0x05, 0x01,
                0x00, 0x08, 0x00, 0x00, 
                0x02, 0x60, 0x97, 0xff,
                0xfe, 0x40, 0xef, 0xab
}};

konnte aber nicht mit diesem,

const struct in6_addr naddr6 = 
                { { { 0x3ffe0501, 0x00080000, 0x026097ff, 0xfe40efab } } }; 

und es scheint, dass ich konnte entweder 1/2/3 paris von brackets.Why?

Dank.

War es hilfreich?

Lösung

Da eine Notwendigkeit anzuzeigen, die Form der Adresse wird Adressierung (C99 gezeigt verwendet wird):

const struct in6_addr naddr6 = 
    { { .u6_addr32 = { 0x3ffe0501, 0x00080000, 0x026097ff, 0xfe40efab } } };

Die erste Klammer Paar ist für die in6_addr Struktur, die zweite für die Union:

struct in6_addr
  {
    union
      {
 uint8_t u6_addr8[16];
 uint16_t u6_addr16[8];
 uint32_t u6_addr32[4];
      } in6_u;
  };

Andere Tipps

Der tragbare Weg, dies zu tun, ist in etwa so:

struct in6_addr s6 = { };
if (!IN6_IS_ADDR_UNSPECIFIED(&s6))
  inet_pton(AF_INET6, "2001:db8::1", &s6);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top