问题描述
这个问题可以被视为一姐的问题,$p$pvious 之一张贴自己。这是非常繁琐的,当你想要一个链路本地地址绑定到IPv6套接字,你需要设置体sockaddr_in6 sin6_scope_id
字段code>结构。我想知道,如果有人能提供以下建议的解决方案。
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.
推荐答案
的IPv6链路本地地址不在节点上独一无二的,这只是为NIC独特这就是为什么你必须指定范围-ID。换句话说,它是完全有效的多个适配器使用完全相同的IPv6地址。
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.
这意味着你应该在输入范围-ID或合适的文本形式(%为eth0,%1),您可以传递给的getaddrinfo()
。
This means you should take in as input the scope-id or suitable text form (%eth0, %1) that you can pass to getaddrinfo()
.
一个方法是采取一个IPv6链路本地地址,枚举接口,如果只有一个匹配使用,如果超过一个匹配,那么救助与接口列表,并获得用户指定哪一个在全形式。
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.
这篇关于如何将链路本地地址绑定到IPv6套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!