Your suggested alternative will not align the entire structure to the 8-byte (64-bit) border that you mentioned as RFC2553 requirement.
In general, the structure takes on the strictest alignment required by any of its members. Since sa_family_t is probably u16_t , which requires only 2-byte alignment and char array requires no more than 1-byte alignment, the alternative you suggest requires only 2-byte alignment. (The compiler would probably give at least 4- and possibly 8-byte alignment anyway, but you cannot be sure.)
The actual definition style is an attempt to make sure that each byte in the structure is part of some named field, i.e. that the compiler does not insert any fields between fields. This is necessary (sort of), so _SS_PAD2SIZE has a value that can be calculated in terms of the sizes of all the other members.
However, I find this definition rather complicated. I'm sure the following works just as well, and it is a little easier to understand:
struct sockaddr_storage { union { sa_family_t u_family; uint64_t u_pad[_SS_MAXSIZE / sizeof(uint64_t)]; } __ss_u; # define __ss_family __ss_u.u_family };
Here, the union receives the requirements for alignment of its strictly strictly aligned element, which then extends to the covering structure. Please note that in this version I have only one required field (although it is buried in the union) and one filling array, which is the exact size, I want the whole structure to be. The only slightly difficult part is defining the __ss_family macro. It is possible that the macro trick does not strictly comply with the RFC requirements, but there will be few (if any) ways to notice the difference.
Dale hagglund
source share