Garbled IPv6 printout

Kurt Roeckx kurt at roeckx.be
Sun Mar 31 09:48:20 UTC 2019


On Sat, Mar 30, 2019 at 08:05:41PM -0700, Hal Murray wrote:
> > A sockaddr is not meant to store the address, ...
> 
> But the API wants a sockaddr.
>        int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
> There is no hint in the man page that an IPv6 address won't fit.
> 
> sockaddr ends with
>   sa_data[14];

POSIX defines it as "char sa_data[]" and that it is variable
length. You should really use any of the other compatible sockaddr
structs and cast it to a struct sockaddr *.

> That's not big enough for an IPv6 address.  I assume somebody suggested making it bigger and/or changing the parameters to accept when IPv6 was added.  It would be interesting to review that discussion.

Nobody suggested that sockaddr was ever something that can hold an
IPv4 address or UNIX domain socket, it was never designed to hold
that. Instead you always had the give the proper type and cast it.
A sockaddr_storage was added as part of adding IPv6 support.

If you really want to know all kinds of historic information about
such things, I suggest you read Stevens' TCP/IP Illustrated.


Kurt



More information about the devel mailing list