[ntp:questions] Pool returns IPv6 address to IPv4 query
Casper H.S. Dik
Casper.Dik at OrSPaMcle.COM
Thu Nov 21 10:16:04 UTC 2013
Rob <nomail at example.com> writes:
>Uwe Klein <uwe at klein-habertwedt.de> wrote:
>>> However, what I don't understand is why an IPv6 address does not fit
>>> into a struct sockaddr, and why this fact is so badly documented.
>>> It took me a lot of time to find why my queried IPv6 addresses were
>> struct sockaddr was a catch all and you had to also hand the size of the
>> storage into the call.
>> int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
>Yes, that is what I mean. But it no longer works.
Of course it still works; however, you may have missed that
"struct sockaddr" isn't the same as "struct sockaddr_in"; these
days you'd start with a "struct sockaddr_storage" and with
socklen_t namelen = sizeof (struct sockaddr_in)
On return you'd determine what type of connection you got
and you cast it to the proper type.
More information about the questions