From 8a5dc0ba12123d68fefd2a3ceac58fc909fc3fc2 Mon Sep 17 00:00:00 2001 From: luojun1 Date: Thu, 27 Oct 2022 10:59:51 +0800 Subject: [PATCH] Force sockaddr_storage to the desired alignment First configure nuttx to support ipv4 and ipv6 dual stack, then start two simulators and run Iperf ipv4 udp speed test, unaligned access exception to sockaddr_in occours. The root cause is that struct sockaddr_storage isn't set to the desired alignment. Signed-off-by: luojun1 --- include/sys/socket.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index d54c38f542..e81b5fa359 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -279,6 +279,12 @@ #define SCM_CREDENTIALS 0x02 /* rw: struct ucred */ #define SCM_SECURITY 0x03 /* rw: security label */ +/* Desired design of maximum size and alignment (see RFC2553) */ + +#define SS_MAXSIZE 128 /* Implementation specific max size */ +#define SS_ALIGNSIZE (sizeof(FAR struct sockaddr *)) + /* Implementation specific desired alignment */ + /**************************************************************************** * Type Definitions ****************************************************************************/ @@ -292,9 +298,10 @@ struct sockaddr_storage { - sa_family_t ss_family; /* Address family */ - char ss_data[126]; /* 126-bytes of address data */ -}; + sa_family_t ss_family; /* Address family */ + char ss_data[SS_MAXSIZE - sizeof(sa_family_t)]; +} +aligned_data(SS_ALIGNSIZE); /* Force desired alignment */ /* The sockaddr structure is used to define a socket address which is used * in the bind(), connect(), getpeername(), getsockname(), recvfrom(), and