Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

sockaddr_in6 address structure of the AF_INET6 address family

&pagelevel(5)&pagelevel

With the AF_INET6 address family, a name comprises a 16-byte Internet address and a port number. You use the sockaddr_in6 address structure for the AF_INET6 address family. This structure has additional variants for #define SCOPE_ID and #define SIN6_LEN.

The sockaddr_in6 structure is declared in the <netinet.in.h> header as follows:

struct sockaddr_in6 {
   short            sin6_family;             /* address family AF_INET6 */
   u_short          sin6_port;               /* 16-bit port number */
   u_int            sin6_flowinfo
   struct in6_addr  sin6_addr;               /* IPv6 address */
   char             sin6_zero[8];
   };

Structure variant of sockaddr_in6 with #define SCOPE_ID set to support Open Source:

struct sockaddr_in6 {
   short            sin6_family;             /* address family AF_INET6 */
   u_short          sin6_port;               /* 16 bit port number */
   u_int            sin6_flowinfo
   struct in6_addr  sin6_addr;               /* IPv6 address*/
   u_int32_t        sin6_scope_id;
   };

Structure variant of sockaddr_in6 with #define SIN6_LEN set to support BSD 4.4 systems:

struct sockaddr_in6 {
   u_int8_t            sin6_len;             /* structure length */
   sa_family_t         sin6_family;          /* address family AF_INET6 */
   in_port_t           sin6_port;            /* 16 bit port number */
   u_int32_t           sin6_flowinfo
   struct in6_addr     sin6_addr;            /* IPv6 address */
   u_int32_t           sin6_scope_id;
   };

You can supply a variable server of type struct sockaddr_in6 with a name by using the following statements:

struct sockaddr_in6 server;
struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
...
server.sin6_family = AF_INET6;
server.sin6_port = htons(8888);
   memcpy(server.sin6_addr.s6_addr, in6addr_any.s6_addr, 16);

A pointer to the variable server can now be passed as the current parameter, e.g. with a bind() call, to bind the name to a socket:

bind(..., &server, ...)   /* bind() call with type conversion */ 

Memory space allocation

Memory space allocation with associated initialization for the in6addr_any variable must take place in the code of the application. The following declaration is made available in the include file <netinet.in.h>:

extern const struct in6_addr in6addr_any;

in6addr_any has the value ::0. A corresponding constant IN6ADDR_ANY_INIT is defined in <netinet.in.h>.