Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
51
Добавлен:
11.04.2015
Размер:
22.9 Mб
Скачать

402 Understanding IPv6, Second Edition

Address Data Structures

The term sockets defines a protocol-specific data structure that holds elements of a socket address. For IPv4, this structure is sockaddr_in. Sockets also defines a protocol-independent structure (sockaddr) for the protocol-specific structures to be cast into. The identifying field (the address family) in the protocol-specific structure overlays the family field in the generic structure. Because IPv6 addresses are different than IPv4 addresses, a new protocol-specific structure for IPv6 is required.

The data structures sockaddr and sockaddr_in are the same size, which could lead you into making incorrect assumptions about the size of their related address structures. The IPv6 address structure, sockaddr_in6, is larger by necessity. For example, the sockaddr structure cannot be used to allocate storage for sockaddr_in6.

in6_addr

struct in6_addr { union {

u_char Byte[16]; ushort Word[8]; } u;

};

The socket address structure contains information above and beyond the address for the socket. One portion of the structure, however, needs to be the address. In IPv4’s address structure, this address is contained in in_addr. A larger structure, in6_addr, has been defined to hold the larger IPv6 address.

sockaddr_in6

In addition to the larger address size, there are other members that must be represented in the socket address structure for IPv6. Although the IPv4 sockaddr_in structure has unused space, it is not enough to contain this additional information. The sockaddr_in6 structure is used to contain an IPv6 address.

struct sockaddr_in6

{

sa_family_t

sin6_family;

in_port_t

sin6_port;

uint32_t

sin6_flowinfo;

struct in6_addr

sin6_addr;

uint32_t

sin6_scope_id;

};

 

In addition to the family, port, and address information, this structure contains sin6_flowinfo and sin6_scope_id members. sin6_flowinfo contains the traffic class and the flow label from and for the IPv6 header. sin6_scope_id contains the scope ID, which is used to identify a set of interfaces that are appropriate for the address carried in the address field.

Соседние файлы в папке Lecture 2_10