What platforms have sin_len in the generic sockaddr structure? The one I've always seen is sa_len, and that's consistent with sa_family in terms of field name prefixes.
sockaddr -> sa_ sockaddr_in -> sin_ sockaddr_in6 -> sin6_ sockaddr_storage -> ss_ I suspect you'd do fine if you ditched the test for sockaddr.sin_len and tested either sockaddr_in.sin_len or sockaddr.sa_len. (And I'd expect an OS to be consistent as to whether the _len field exists for each of the various socket address structures.) At first glance, the IPv6 flavor of the code looks okay on this score... Ken