IPv6 sockaddr issues
Russ Allbery
rra at stanford.edu
Sat Nov 23 06:47:44 UTC 2002
Jeffrey M Vinocur <jeff at litech.org> writes:
> We're using getaddrinfo(3) in the IPv6 case. It returns (by writing
> into an argument "struct addrinfo **r") a struct addrinfo, defined as:
> struct addrinfo {
> int ai_flags;
> int ai_family;
> int ai_socktype;
> int ai_protocol;
> size_t ai_addrlen;
> struct sockaddr *ai_addr;
> char *ai_canonname;
> struct addrinfo *ai_next;
> };
> I want to copy the contents of r->ai_addr into local storage before
> calling freeaddrinfo(r). But despite the fact that -- on my platform --
> sizeof(struct sockaddr) is 16, it turns out that both r->ai_addrlen and
> SA_LEN(r->ai_addr) are 28. Now, I don't really know anything about this
> sockaddr mess, but I'm quite sure that 28 bytes can't fit into a 16-byte
> struct.
Yeah, this is a common problem with struct sockaddr. It's a really poorly
defined interface and it breaks some of the standard C behavior because
it's often implemented with a struct for which sizeof is smaller than the
actual size of the allocated memory.
> The solution is to use struct sockaddr_storage, from what I understand,
> but obviously we can't depend on that being around on non-IPv6
> platforms.
Can we fake it on platforms that don't have it? I'd rather go that way if
we can, since it seems to be a saner interface.
Other than that, your solution seems fine to me.
--
Russ Allbery (rra at stanford.edu) <http://www.eyrie.org/~eagle/>
Please send questions to the list rather than mailing me directly.
<http://www.eyrie.org/~eagle/faqs/questions.html> explains why.
More information about the inn-workers
mailing list