Get the latest tech news
The trouble with struct sockaddr's fake flexible array
many faces of struct sockaddr The sockaddr structure dates back to the beginning of the BSD socket API; it is used to hold an address corresponding to one side of a network connection. The 4.2 BSD networking implementation notes from 1983 give its format as: struct sockaddr { short sa_family; char sa_data[14]; }; The sa_family field describes which address family is in use — AF_INET for an IPv4 address, for example.
That has the result of placing a flexible array in the middle of the embedding structure, which is problematic for fairly obvious reasons; the compiler no longer knows what the offsets to the members after struct sockaddr should be. It also, as Cook noted in the cover letter, is still lying to the compiler in cases where the backing structure is actually smaller than struct sockaddr_storage, " these remain just as safe as they used to be. This series shows that truly eliminating the use of this structure's sa_data field as a flexible array in disguise will involve a fair amount of work and code churn.
Or read this on Hacker News