I'm using GetAdaptersAddresses functions and I've got as
a result unicast addresses not only 16 bytes long, but
also 28 bytes long!!!
Some results:
Automatic Tunneling Pseudo-Interface
17.0.0.0.0.0.0.0.FE.80.0.0.0.0.0.0.0.0.5E.FE.C0.A8.0.4.2.0
.0.0
Loopback Pseudo-Interface
17.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.0 -
this is ::1 but with prefixes and posfixes!!!
Flag GAA_FLAG_INCLUDE_PREFIX not set. How to extract real
address? How can I determine how long prefix and postfix
are?
Also I've got some problems, while getting IPv4 addresses
via the same function - it looks like
2.0.0.0.C0.A8.0.4.0.0.0.0.0.0.0.0. My IPv4 address is
inside that IPv6 address. Is positions of v4 address
inside v6 address fixed?
> I'm using GetAdaptersAddresses functions and I've got as
> a result unicast addresses not only 16 bytes long, but
> also 28 bytes long!!!
The address that is returned is a sockaddr variant, not a raw IP
address. 28 bytes is the size of the entire sockaddr_in6, but to get
just the address you need to look at sockaddr_in6.sin6_addr.
When you are iterating through the addresses in the IP_ADAPTER_ADDRESSES
structure (e.g. starting with IP_ADAPTER_ADDRESSES.FirstUnicastAddress),
you should look at SOCKADDR->lpSockAddr->sa_family and if it is
AF_INET6, then cast the pointer as a sockaddr_in6 * and access the
IPv6-specific fields that way (similarly with sockaddr_in * for AF_INET).
> Also I've got some problems, while getting IPv4 addresses
> via the same function - it looks like
> 2.0.0.0.C0.A8.0.4.0.0.0.0.0.0.0.0. My IPv4 address is
> inside that IPv6 address. Is positions of v4 address
> inside v6 address fixed?
You may be seeing an IPv4-mapped IPv6 address. For example, the
Automatic Tunneling Pseudo-Interface on my machine reports an
IPv4-mapped IPv6 address (e.g. fe80:5efe:1.2.3.4%2).
Great!!! Big thanx :))))
According to Bob Bradley's answer, this byte array must be converted into
sockaddr_in structure and we'll got:
sin_family=2 (AF_INET)
sin_port=0
sin_addr=/*192.168.0.4*/
sin_zero={0,...0}
Addresses returned by GetAdaptersAddresses are sockaddr structures of
WinSock
Big thanx to Bob Bradley!!