Recently I was working with the Berkeley socket API for IPv6, and noticed that IPv6 addresses (sockaddr_in6
) have a field called sin6_scope_id
, which was not part of IPv4 addresses.
After searching around a bit, I’ve learned that scope_id
is meant to identify the network interface, because multiple network interfaces can have the same link-local IPv6 address. This made sense, but then what I didn’t understand is how IPv4 handles this issue, if there’s no equivalent of scope ID there?
Is there a mechanism in the kernel that prevents multiple IPv4 interfaces from being assigned the same link-local address?
If that’s the case, then why was it necessary to invent scope ID for IPv6 instead of going with the same solution as IPv4?
Also, is the scope_id only used to distinguish between interfaces with identical link-local addresses, or are there other use cases too?