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