在 Windows 7 中绑定 () 到 IPv6 地址失败并显示错误代码:: WSAEADDRNOTAVAIL (10049)
我正在尝试使用两台 Windows-7 机器设置一个私有 ipv6 网络来测试我的应用程序。我编写了一个示例代码来测试套接字 api。我已经创建了一个 IPv6 套接字。当我尝试使用链接本地地址(从ipconfig命令获取)绑定时,错误代码为10049。
请告知为什么绑定< /em> Ipv6 地址在 windows-7 机器上失败?
I am trying to set-up a private ipv6 network with two windows-7 machines for tesing my application. I have written a sample code to test the socket apis. I have created an IPv6 socket. When I try to bind with the link-local address (which I get from ipconfig command), the error code is 10049.
Please inform, why the bind with Ipv6 address is failing in windows-7 machine ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是链路本地 IPv6 地址,则可能需要在
sockaddr_in6
结构中设置sin6_scope_id
字段来指示您要侦听的接口。链接本地地址不明确,因为 每个接口都必须有一个链接本地地址分配,并且它们都使用相同的前缀。 (fe80::/64
)您可能应该
bind()
您的监听套接字到未指定的地址(全零或::
),这样这不是问题,但对于发送方来说仍然是一个问题。如果您不指定sin6_scope_id
,系统将不知道将数据包发送到哪个接口。为了避免这个问题,最好设置一个执行路由器通告,这样你就可以获得 全球单播(或者至少唯一本地 ) 地址。
If you're using a link-local IPv6 address, you probably need to set the
sin6_scope_id
field in yoursockaddr_in6
structure to indicate which interface you want to listen on. A link-local address is ambiguous, since every interface must have a link-local address assigned, and they all use the same prefix. (fe80::/64
)You should probably
bind()
your listen socket to the unspecified address (all-zeroes or::
) so this isn't an issue, but it will still be a problem for the sending side. If you don't specify thesin6_scope_id
, the system won't know which interface to send the packet on.To avoid the issue, it would be best to set up an IPv6 router that does router advertisements, so you can get global unicast (or, at a minimum, unique local) addresses.