I have written some simple code that uses ioctl SIOCGIFCONF to query all network interfaces on a system and, using inet_ntop, return the textual representation of the address found. The odd thing is that when a link-local IPv6 address is discovered, the OSX version of the code appears to embed the scope within the address.
Here's a line from /sbin/ifconfig on OSX after autoconfiguring the interfaces (:
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
ether 00:17:f2:0b:52:73
inet6 fe80::217:f2ff:fe0b:5273%en1 prefixlen 64 scopeid 0x5
and the IP address as returned by ioctl SIOCGIFCONF:
IPv6 addr: fe80:5::217:f2ff:fe0b:5273
It looks like the value for scope (5) was inserted immediately after fe80.
The same code on Linux returns the ipv6 address without any extra data.
Two questions occur to me: 1) Is it legitimate to write an ipv6 address like this? 2) Is the OSX behavior documented anywhere?
References please!