How to cast sockaddr to sockaddr_in on Arm

I have the following code copied from another place to get the client port from connecting to the server socket. On Intel's 64-bit Intel Arch, this compilation is no problem,

struct sockaddr *sa; struct sockaddr_in *sin; unsigned short sin_port; sa = conn->local_sockaddr; sin = (struct sockaddr_in *) sa; sin_port = ntohs(sin->sin_port); 

In Arm, he complains that โ€œa mistake: casting increases the desired alignment of the target typeโ€, which seems reasonable.

I donโ€™t think I can ignore this. Is there a way to tell GCC to correct the alignment so that I can read the port?

+2
source share

All Articles