IPv6 sockaddr issues

Jeffrey M. Vinocur jeff at litech.org
Sun Nov 17 03:40:41 UTC 2002


Ok, I tracked down my stupid bug.  I'm just not sure what to do about it.  
(It only worked before by happenstance -- the next thing on the stack must 
not have been that important.)

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.

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.  
So the conclusion I'm coming to is that in authprogs/libauth.h, our struct
should only mention struct sockaddr, but if necessary we just allocate 
something larger and cast it to fit?

I'll go ahead and do that; I think it will work, but somebody tell me if 
I'm going about this all wrong.

-- 
Jeffrey M. Vinocur
jeff at litech.org



More information about the inn-workers mailing list