Skip to content

struct sockaddr_storage

A generic structure to store socket address information. More...

#include <sys/socket.h>

Public Attributes

Name
uint8_ts2_len
sa_family_tss_family
char[2]s2_data1
uint32_t[3]s2_data2

Detailed Description

cpp
struct sockaddr_storage;

A generic structure to store socket address information.

The sockaddr_storage structure is used to store socket address information for various protocols. It provides a flexible and generic way to represent socket addresses without tying it to any specific address family or protocol.

The structure consists of the following members:

  • s2_len: The length of the structure in bytes.
  • ss_family: The socket address family.
  • s2_data1[2]: Reserved storage.
  • s2_data2[3]: Reserved storage.

The length and storage members are reserved for future use and are required to be set to zero when the structure is initialized.

The socket address family is stored in the ss_family member as defined by the sa_family_t typedef, and it indicates the specific protocol family to which the socket address belongs. The sa_family_t typedef is an unsigned 8-bit integer used to represent the socket address family.

Example usage:

cpp
struct sockaddr_storage addr;
addr.s2_len = 0;
addr.ss_family = AF_INET;
memset(addr.s2_data1, 0, sizeof(addr.s2_data1));
memset(addr.s2_data2, 0, sizeof(addr.s2_data2));

Public Attributes Documentation

variable s2_len

cpp
uint8_t sockaddr_storage::s2_len

variable ss_family

cpp
sa_family_t sockaddr_storage::ss_family

variable s2_data1

cpp
char sockaddr_storage::s2_data1[2]

variable s2_data2

cpp
uint32_t sockaddr_storage::s2_data2[3]