Local IPv6 LAN address with integrated OSX scope

I wrote simple code that uses ioctl SIOCGIFCONF to query all network interfaces in the system and, using inet_ntop, returns a textual representation of the address found. It is strange that when it detects a local IPv6 communication address, the OSX version of the code seems to embed the scope in the address.

Here is the line from / sbin / ifconfig on OSX after the autoconfiguration of 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 returned by ioctl SIOCGIFCONF:

IPv6 addr: fe80: 5 :: 217: f2ff: fe0b: 5273

It looks like the value for region (5) was inserted right after fe80.

The same Linux code returns the ipv6 address without any additional data.

Two questions come to me: 1) Is it legal to write an ipv6 address like this? 2) Is OSX behavior described somewhere?

, !

+3
1

, , , , IPv6, (, - ), , . , .

.


. . BSD IPv6 16- IPv6-. . RFC, 0 . (, , ) , , - . , , .


2. , :

  466 static int
  467 in6_ifattach_linklocal(
  468         struct ifnet *ifp,
  469         struct ifnet *altifp,   /* secondary EUI64 source */
  470         struct in6_aliasreq *ifra_passed)
  471 {
      ...
  494                 ifra.ifra_addr.sin6_family = AF_INET6;
  495                 ifra.ifra_addr.sin6_len = sizeof(struct sockaddr_in6);
  496                 ifra.ifra_addr.sin6_addr.s6_addr16[0] = htons(0xfe80);
  497 #if SCOPEDROUTING
  498                 ifra.ifra_addr.sin6_addr.s6_addr16[1] = 0
  499 #else
  500                 ifra.ifra_addr.sin6_addr.s6_addr16[1] = htons(ifp->if_index); /* XXX */
  501 #endif

/* XXX */ 500.;-) , /, , . . if_index , , , 128- , - .

+4

All Articles