Hello All,
 
Does anybody understand why RFCs propose creating struct sockaddr_storage with
code like
 

/*
* Desired design of maximum size and alignment
*/
#define _SS_MAXSIZE 128 /* Implementation specific max size */
#define _SS_ALIGNSIZE (sizeof (int64_t))
               /* Implementation specific desired alignment */
/*
* Definitions used for sockaddr_storage structure paddings design.
*/
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (sa_family_t))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (sa_family_t)+
                              _SS_PAD1SIZE + _SS_ALIGNSIZE))
struct sockaddr_storage {
    sa_family_t  ss_family;     /* address family */
    /* Following fields are implementation specific */
    char _ss_pad1[_SS_PAD1SIZE];
              /* 6 byte pad, this is to make implementation */
              /* specific pad up to alignment field that */
              /* follows explicit in the data structure */
    int64_t _ss_align;     /* field to force desired structure */
                           /* storage alignment */
    char _ss_pad2[_SS_PAD2SIZE];
              /* 112 byte pad to achieve desired size, */
              /* _SS_MAXSIZE value minus size of ss_family */
              /* __ss_pad1, __ss_align fields is 112 */
};
instead of
 
struct sockaddr_storage
{
       union {
             sa_family_t stor_family;
             struct sockaddr_in s4;
             struct sockaddr_in s6;
      }sock_store;
      #define ss_family sock_store.stor_family; 
}
 
Is there a legitimate concern that this would not actually work as desired on some platforms due
to alignment issues when declared using a union?  Doesn't ANSI C guarantee that all members
of the union are at offset zero?  I seem to recall reading that someplace.  And with this definition
wouldn't it guarantee alignment on any platform without platform-specific padding like the RFC
version?
 
Regards,
 
MT
 
 

--------------------------------------------------------------------
IETF IPv6 working group mailing list
ipv6@ietf.org
Administrative Requests: https://www1.ietf.org/mailman/listinfo/ipv6
--------------------------------------------------------------------

Reply via email to