Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to bind a link local address to an ipv6 socket

Tags:

c

ipv6

This question can be treated as a sister question of previous one posted by myself. It is very tedious that when you want to bind a link local address to an IPv6 socket, you need to set the sin6_scope_id field of the sockaddr_in6 struct. I'm wondering if someone can provide a solution following good practice.

like image 717
Haiyuan Zhang Avatar asked Mar 17 '10 08:03

Haiyuan Zhang


People also ask

What is the link-local prefix for IPv6?

IPv6 link-local addresses are defined by RFC 4291 (IPv6 Addressing Architecture) and are covered by the prefix fe80::/10. In practice, only fe80::/64 is used.

Why do we need link-local address in IPv6?

Consequently, IPv6 hosts usually have more than one IPv6 address assigned to each of their IPv6-enabled network interfaces. The link-local address is required for IPv6 sublayer operations of the Neighbor Discovery Protocol, as well as for some other IPv6-based protocols, such as DHCPv6.


1 Answers

The IPv6 link-local address is not unique on the node it's only unique for the NIC which is why you have to specify the scope-id. In other words it is perfectly valid to have multiple adapters with exactly the same IPv6 address.

This means you should take in as input the scope-id or suitable text form (%eth0, %1) that you can pass to getaddrinfo().

One method is to take in a IPv6 link-local address, enumerate the interfaces and if only one matches use that, if more than one match then bail out with a list of interfaces and get the user to specify which one in full form.

like image 80
Steve-o Avatar answered Oct 19 '22 23:10

Steve-o