Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IPv6 address 28 bytes length???

85 views
Skip to first unread message

Max

unread,
Dec 18, 2003, 6:37:38 AM12/18/03
to
My task is to get all ip addresses of all interfaces on
local computer

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?

Bob Bradley

unread,
Dec 18, 2003, 7:30:24 PM12/18/03
to
In article <060301c3c55b$56e415b0$a401...@phx.gbl>,
"Max" <anon...@discussions.microsoft.com> wrote:

> 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).

Morozov Max

unread,
Dec 19, 2003, 5:25:28 AM12/19/03
to
> 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).

Great!!! Big thanx :))))


Morozov Max

unread,
Dec 19, 2003, 6:16:51 AM12/19/03
to
> 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?

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!!


0 new messages