sys/socket: implement compiler agnostic sockaddr_storage alignment
'aligned_data' is compiler dependent, but Open Group Base Specifications describe compiler agnostic solution that can be used: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
1528b8dcca
commit
282cf2f7d0
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@ -292,9 +293,13 @@
|
|||||||
|
|
||||||
/* Desired design of maximum size and alignment (see RFC2553) */
|
/* Desired design of maximum size and alignment (see RFC2553) */
|
||||||
|
|
||||||
#define SS_MAXSIZE 128 /* Implementation specific max size */
|
#define SS_MAXSIZE 128 /* Implementation-defined maximum size. */
|
||||||
#define SS_ALIGNSIZE (sizeof(FAR struct sockaddr *))
|
#define SS_ALIGNSIZE (sizeof(int64_t)) /* Implementation-defined desired alignment. */
|
||||||
/* Implementation specific desired alignment */
|
|
||||||
|
/* Definitions used for sockaddr_storage structure paddings design */
|
||||||
|
#define SS_PAD1SIZE (SS_ALIGNSIZE - sizeof(sa_family_t))
|
||||||
|
#define SS_PAD2SIZE (SS_MAXSIZE - (sizeof(sa_family_t) + \
|
||||||
|
SS_PAD1SIZE + SS_ALIGNSIZE))
|
||||||
|
|
||||||
/* Network socket control */
|
/* Network socket control */
|
||||||
|
|
||||||
@ -314,10 +319,22 @@
|
|||||||
|
|
||||||
struct sockaddr_storage
|
struct sockaddr_storage
|
||||||
{
|
{
|
||||||
sa_family_t ss_family; /* Address family */
|
sa_family_t ss_family; /* Address family */
|
||||||
char ss_data[SS_MAXSIZE - sizeof(sa_family_t)];
|
|
||||||
}
|
/* Following fields are implementation-defined */
|
||||||
aligned_data(SS_ALIGNSIZE); /* Force desired alignment */
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
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. */
|
||||||
|
}
|
||||||
|
ss_data[1];
|
||||||
|
};
|
||||||
|
|
||||||
/* The sockaddr structure is used to define a socket address which is used
|
/* The sockaddr structure is used to define a socket address which is used
|
||||||
* in the bind(), connect(), getpeername(), getsockname(), recvfrom(), and
|
* in the bind(), connect(), getpeername(), getsockname(), recvfrom(), and
|
||||||
@ -334,8 +351,8 @@ struct sockaddr
|
|||||||
|
|
||||||
struct linger
|
struct linger
|
||||||
{
|
{
|
||||||
int l_onoff; /* Indicates whether linger option is enabled. */
|
int l_onoff; /* Indicates whether linger option is enabled. */
|
||||||
int l_linger; /* Linger time, in seconds. */
|
int l_linger; /* Linger time, in seconds. */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct msghdr
|
struct msghdr
|
||||||
|
Loading…
Reference in New Issue
Block a user