Owen James
|
IPv6 Link-Local addresses have (possible) scope id embedded inside of them.
|
Owen James
07/30/2008 11:38 AM
post11243
|
IPv6 Link-Local addresses have (possible) scope id embedded inside of them.
On QNX 6.3.2, with the io-pkt-v6-hc network driver installed, running the command ifconfig results in:
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
en0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
address: 00:01:f0:80:03:0b
inet 137.19.61.100 netmask 0xfffffe00 broadcast 137.19.61.255
inet6 fe80::201:f0ff:fe80:30b%en0 prefixlen 64 scopeid 0x2
bc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ssid TST-EMBD1 nwkey 65536:"",0x6912a386e68d04f539c9ce2894d67063,0xfe374224480605fc4803f370fe34c69c,""
powersave off
bssid 00:1c:f0:9c:14:6b chan 6
address: 00:21:86:3e:83:aa
media: IEEE802.11 autoselect (OFDM54 mode 11g)
status: active
inet6 fe80::221:86ff:fe3e:83aa%bc0 prefixlen 64 scopeid 0x3
...
Here, we can clearly see the interface and link-local addresses of all 3 adapters available on the machine. In following
code segment, I gather the interface information using the getifaddrs() method, which populates a ifaddrs struct.
char test[INET6_ADDRSTRLEN];
memset(test, 0, INET6_ADDRSTRLEN);
struct ifaddrs *ifap;
struct ifaddrs *cur = NULL;
if (getifaddrs(&ifap) < 0)
{
perror("unable to retrieve interface information");
return -1;
}
for (cur = ifap; cur != NULL; cur = cur->ifa_next)
{
//go for the first ipv6 address you find?
//really we want the first "global" scope address...
if (cur->ifa_addr->sa_family == AF_INET6)
{
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)cur->ifa_addr;
inet_ntop(AF_INET6, &addr->sin6_addr, test, INET6_ADDRSTRLEN);
fprintf(stderr, "looking at the address: %s\n", test);
}
}
freeifaddrs(ifap);
...
This code outputs the following:
looking at the address: ::1
looking at the address: fe80:1::1
looking at the address: fe80:2::201:f0ff:fe80:30b
looking at the address: fe80:3::221:86ff:fe3e:83aa
We can see the IPv6 link-local addresses for the adapters, but each has, what appears to be, the scope id of the address
embedded in string. This results in an invalid link-local address. I am unaware of any error in my source, after
reviewing several examples, and need to know if I am overlooking something.
|
|
|
Sean Boudreau(deleted)
|
Re: IPv6 Link-Local addresses have (possible) scope id embedded inside of them.
|
Sean Boudreau(deleted)
08/01/2008 2:51 PM
post11357
|
Re: IPv6 Link-Local addresses have (possible) scope id embedded inside of them.
On Wed, Jul 30, 2008 at 11:38:21AM -0400, Owen James wrote:
> On QNX 6.3.2, with the io-pkt-v6-hc network driver installed, running the command ifconfig results in:
>
> lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192
> inet 127.0.0.1 netmask 0xff000000
> inet6 ::1 prefixlen 128
> inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
> en0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> address: 00:01:f0:80:03:0b
> inet 137.19.61.100 netmask 0xfffffe00 broadcast 137.19.61.255
> inet6 fe80::201:f0ff:fe80:30b%en0 prefixlen 64 scopeid 0x2
> bc0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> ssid TST-EMBD1 nwkey 65536:"",0x6912a386e68d04f539c9ce2894d67063,0xfe374224480605fc4803f370fe34c69c,""
> powersave off
> bssid 00:1c:f0:9c:14:6b chan 6
> address: 00:21:86:3e:83:aa
> media: IEEE802.11 autoselect (OFDM54 mode 11g)
> status: active
> inet6 fe80::221:86ff:fe3e:83aa%bc0 prefixlen 64 scopeid 0x3
>
> ...
>
> Here, we can clearly see the interface and link-local addresses of all 3 adapters available on the machine. In
following code segment, I gather the interface information using the getifaddrs() method, which populates a ifaddrs
struct.
>
> char test[INET6_ADDRSTRLEN];
>
> memset(test, 0, INET6_ADDRSTRLEN);
>
> struct ifaddrs *ifap;
> struct ifaddrs *cur = NULL;
>
> if (getifaddrs(&ifap) < 0)
> {
> perror("unable to retrieve interface information");
> return -1;
> }
>
> for (cur = ifap; cur != NULL; cur = cur->ifa_next)
> {
> //go for the first ipv6 address you find?
> //really we want the first "global" scope address...
> if (cur->ifa_addr->sa_family == AF_INET6)
> {
> struct sockaddr_in6 *addr = (struct sockaddr_in6 *)cur->ifa_addr;
>
> inet_ntop(AF_INET6, &addr->sin6_addr, test, INET6_ADDRSTRLEN);
> fprintf(stderr, "looking at the address: %s\n", test);
> }
> }
>
> freeifaddrs(ifap);
>
> ...
>
> This code outputs the following:
>
> looking at the address: ::1
> looking at the address: fe80:1::1
> looking at the address: fe80:2::201:f0ff:fe80:30b
> looking at the address: fe80:3::221:86ff:fe3e:83aa
>
> We can see the IPv6 link-local addresses for the adapters, but each has, what appears to be, the scope id of the
address embedded in string. This results in an invalid link-local address. I am unaware of any error in my source, after
reviewing several examples, and need to know if I am overlooking something.
Yes, getifaddrs() is returning out the 'kernel' representation
of scoped addresses which stores the scope in the 3rd and 4th
byte. The following modified example based on ifconfig converts
it to the draft-ietf-ipngwg-scopedaddr-format-00.txt format.
See also this page:
http://www.freebsd.org/doc/en/books/developers-handbook/ipv6.html
-seanb
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <stdio.h>
void in6_fillscopeid(struct sockaddr_in6 *);
int
main(void)
{
char test[INET6_ADDRSTRLEN];
struct ifaddrs *ifap;
struct ifaddrs *cur = NULL;
int ret;
char hbuf[NI_MAXHOST];
memset(test, 0, INET6_ADDRSTRLEN);
if (getifaddrs(&ifap) < 0)
{
perror("unable to retrieve interface information");
return -1;
}
for (cur = ifap; cur != NULL; cur = cur->ifa_next)
{
//go for the first ipv6 address you find?
//really we want the first "global" scope address...
if (cur->ifa_addr->sa_family == AF_INET6)
{
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)cur->ifa_addr;
in6_fillscopeid(addr);
if ((ret =...
View Full Message
|
|
|
Owen James
|
Re: IPv6 Link-Local addresses have (possible) scope id embedded inside of them.
|
Owen James
08/01/2008 5:56 PM
post11375
|
Re: IPv6 Link-Local addresses have (possible) scope id embedded inside of them.
Thanks sean, never came across that representation in my research of the sockaddr_in6 struct.
|
|
|
|