1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

Merge pull request #17152 from maribu/sys/posix/sockets

sys/posix/socket: align struct sockaddr{,_storage}
This commit is contained in:
chrysn 2021-11-16 13:55:27 +01:00 committed by GitHub
commit 69dadf61e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -23,13 +23,9 @@ ifeq ($(ROMABLE),1)
MIPS_HAL_LDFLAGS += -T bootcode.ld
endif
# define build specific options
# Remove -std=gnu99 once the MIPS toolchain headers are updated to include upstream
# newlib commit 81c17949f0419d1c4fee421c60987ea1149522ae
# https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=commitdiff;h=81c17949f0419d1c4fee421c60987ea1149522ae
# Otherwise we get an error about a missing declaration of strnlen in some parts.
ifeq (, $(filter -std=%, $(CFLAGS)))
CFLAGS += -std=gnu99
CFLAGS += -std=gnu11
endif
CFLAGS_CPU = -EL -mabi=$(ABI)
CFLAGS_LINK = -ffunction-sections -fno-builtin -fshort-enums -fdata-sections

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 */
};