Impl `sockaddr_storage`, structs in `netinet.h`
Impl sockaddr_storage
, structs in netinet.h
glib
fails to compile due to these missing structs. See my glib
patch for more info.
The implemented structs are relatively straightforward except sockaddr_storage
. That struct is designed to address a limitation with sockaddr
in that it is too small to store IPv6 addresses. sockaddr_storage
is ostensibly future-proof. I read glibc
and musl
's source code as well as the linked libc
issues to check correctness.
The implementation itself can be derived from the Posix standard itself or musl
alone:
From the Posix standard:
struct sockaddr_storage {
sa_family_t ss_family; /* Address family. */
/*
* Following fields are implementation-defined.
*/
char _ss_pad1[_SS_PAD1SIZE];
/* 6-byte pad; this is to make implementation-defined
pad up to alignment field that follows explicit in
the data structure. */
int64_t _ss_align; /* Field to force desired structure
storage alignment. */
char _ss_pad2[_SS_PAD2SIZE];
/* 112-byte pad to achieve desired size,
_SS_MAXSIZE value minus size of ss_family
__ss_pad1, __ss_align fields is 112. */
};
From musl
's sys_socket/socket.h
:
struct sockaddr_storage {
sa_family_t ss_family;
char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)];
unsigned long __ss_align;
};
Useful sources:
Edited by Josh Megnauth