SOCKADDR_STORAGE structure
The SOCKADDR_STORAGE structure stores socket address information. Since the SOCKADDR_STORAGE structure is sufficiently large to store address information for IPv4, IPv6, or other address families, its use promotes protocol-family and protocol-version independence and simplifies cross-platform development. Use the SOCKADDR_STORAGE structure in place of the sockaddr structure.
Syntax
typedef struct sockaddr_storage {
short ss_family;
char __ss_pad1[_SS_PAD1SIZE];
__int64 __ss_align;
char __ss_pad2[_SS_PAD2SIZE];
} SOCKADDR_STORAGE, *PSOCKADDR_STORAGE;
Members
ss_family
Address family of the socket, such as AF_INET.On Windows Vista and later, the datatype for this member is defined as an ADDRESS_FAMILY.
__ss_pad1
Reserved. Defined as a 48-bit pad that ensures SOCKADDR_STORAGE achieves 64-bit alignment.__ss_align
Reserved. Used by the compiler to align the structure.__ss_pad2
Reserved. Used by the compiler to align the structure.
Remarks
In the Microsoft Windows Software Development Kit (SDK), the version of this structure for use on Windows Vista and later is defined as SOCKADDR_STORAGE_LH. In the Windows SDK, the version of this structure to be used on earlier systems including Windows XP and later is defined as SOCKADDR_STORAGE_XP. When compiling an application if the target platform is Windows Vista and later (NTDDI_VERSION >= NTDDI_LONGHORN, _WIN32_WINNT >= 0x0600, or WINVER >= 0x0600), the SOCKADDR_STORAGE_LH structure is typedefed to the SOCKADDR_STORAGE structure. When compiling an application if the target platform is not Windows Vista and later, the SOCKADDR_STORAGE_XP structure is typedefed to the SOCKADDR_STORAGE structure.
The SOCKADDR_STORAGE_LH structure defines the data type of first member of the structure as an ADDRESS_FAMILY.
Application developers normally use only the ss_family member of the SOCKADDR_STORAGE. The remaining members ensure that the SOCKADDR_STORAGE can contain either an IPv6 or IPv4 address and the structure is padded appropriately to achieve 64-bit alignment. Such alignment enables protocol-specific socket address data structures to access fields within a SOCKADDR_STORAGE structure without alignment problems. With its padding, the SOCKADDR_STORAGE structure is 128 bytes in length.
The first member field of the SOCKADDR_STORAGE structure is isomorphic with the sockaddr structure to enable a simplified transition from the sockaddr structure to the SOCKADDR_STORAGE structure.
For more information about platform-independent SOCKADDR_STORAGE implementation recommendations, refer to RFC 2553, available at www.ietf.org.
On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the SOCKADDR_STORAGE structure is defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.
Requirements
Minimum supported client |
Windows XP [desktop apps only] |
Minimum supported server |
Windows Server 2003 [desktop apps only] |
Header |
Ws2def.h (include Winsock2.h); Winsock2.h on Windows Server 2003 and Windows XP |