1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/posix/socket: align struct sockaddr{,_storage}

Align the first member of `struct sockaddr` and
`struct sockaddr_storage` as `uint32_t` to elevate the alignment of the
structure to level of `uint32_t`. This is needed as
`struct sockaddr_in` uses an `uint32_t` to store the IPv4 address,
previously resulting in `struct sockaddr_in` currently having a greater
alignment requirement that `struct sockaddr_storage`.
This commit is contained in:
Marian Buschsieweke 2021-11-05 08:49:04 +01:00
parent de2bd172f8
commit 7703b37c6f
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94

View File

@ -38,10 +38,12 @@
#define __SOCKADDR_COMMON_SIZE (sizeof (unsigned short int))
#endif
#include <stdalign.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/uio.h>
#include "architecture.h"
#include "net/af.h"
#include "sys/bytes.h"
@ -120,18 +122,24 @@ typedef unsigned short sa_family_t; /**< address family type */
/**
* @brief Used to define the socket address.
*
* @details This structure is is forced to be aligned as `uint32_t`, as e.g.
* the IPv4 address is stored as `uint32_t`
*/
struct sockaddr {
sa_family_t sa_family; /**< Address family */
alignas(uint32_t) sa_family_t sa_family;/**< Address family */
char sa_data[SOCKADDR_MAX_DATA_LEN]; /**< Socket address (variable length data) */
};
/**
* @brief Implementation based socket address table.
* @extends struct sockaddr
*
* @details This structure is is forced to be aligned as `uint32_t`, as e.g.
* the IPv4 address is stored as `uint32_t`
*/
struct sockaddr_storage {
sa_family_t ss_family; /**< Address family */
alignas(uint32_t) sa_family_t ss_family;/**< Address family */
uint8_t ss_data[SOCKADDR_MAX_DATA_LEN]; /**< Socket address */
};