tech-net archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: struct sockaddr_storage issues
On Fri, 23 Dec 2022 21:58:27 +0000
Taylor R Campbell <campbell+netbsd-tech-net%mumble.net@localhost> wrote:
> You should pass sizeof(struct sockaddr_in) or sizeof(struct
> sockaddr_in6) on all platforms and you won't have these portability
> issues.
Exactly the conclusion I came to as well while refactoring the code to
be IPv4 and IPv6 agnostic. Because socket APIs are so old, they seem to
have a lot of portability wrinkles. My understanding is that sockaddr
structure should not really be used for storage, it was invented to be
used as a generic pointer, when "pointer to void" concept did not exist
in C. As you point out, the real structures for sizeof() operator
should be sockaddr_in and sockaddr_in6, which can be embedded in the
common sockaddr_storage structure.
Thanks for the detailed explanation previously.
Home |
Main Index |
Thread Index |
Old Index