luojun1234 commented on PR #8285:
URL: https://github.com/apache/nuttx/pull/8285#issuecomment-1413221778
> @xiaoxiang781216 why `struct sockaddr` does not need similar alignment
requirement? What was the place of error during iperf test?
1.iperf2/iperf2/include/Settings.hpp:
`typedef struct thread_Settings
{
...
// structs or miscellaneous
iperf_sockaddr peer; ==>the peer socket Addr
Socklen_t size_peer;
iperf_sockaddr local; ==>the local socket Addr
Socklen_t size_local;
...
}`
2.iperf2/iperf2/include/headers.h:
` #ifdef HAVE_IPV6
#define REPORT_ADDRLEN (INET6_ADDRSTRLEN + 1)
typedef struct sockaddr_storage iperf_sockaddr;
#else
#define REPORT_ADDRLEN (INET_ADDRSTRLEN + 1)
typedef struct sockaddr_in iperf_sockaddr;
#endif`
3.Configure nuttx to support dual stack, in the logic of iperf souce code,
sockaddr_storage is cast to sockaddr_in(as follow), unaligned access
occurs(sockaddr_in requires 4-byte alignment)
`
void Settings_GenerateClientSettings( thread_Settings *server,
thread_Settings **client,
client_hdr *hdr ) {
...
if ( server->mLocalhost != NULL ) {
(*client)->mLocalhost = new char[strlen( server->mLocalhost ) +
1];
strcpy( (*client)->mLocalhost, server->mLocalhost );
}
(*client)->mHost = new char[REPORT_ADDRLEN];
if ( ((sockaddr*)&server->peer)->sa_family == AF_INET ) {
inet_ntop( AF_INET, &((sockaddr_in*)&server->peer)->sin_addr,
<== type casting
(*client)->mHost, REPORT_ADDRLEN);
}
#ifdef HAVE_IPV6
else {
inet_ntop( AF_INET6, &((sockaddr_in6*)&server->peer)->sin6_addr,
(*client)->mHost, REPORT_ADDRLEN);
}
#endif
} else {
*client = NULL;
}
}
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]