bind() 适用于 ipv6 无线适配器接口但不适用于 ipv6 以太网(错误 10049)

bind() works for ipv6 wireless adapter interface but not for ipv6 ethernet (error 10049)

背景

在我的程序开始时,我使用 GetAdaptersAddresses. Later, after creating an ipv6 slaac address, calling Socket(), Bind() and Listen() all succeed where the IfType is Wireless, that is, IfType 71 (IF_TYPE_IEEE80211). My filter parameters are family and ifType. I test by connecting and disconnecting the ethernet cable. For each case my software finds the active interface with said parameters: connected it finds ethernet first, disconnected it doesn't find ethernet, then looks further for a wireless interface. See SO 为相关代码片段构建适配器接口地址的链接列表。

问题

但是,如果接口的IfType为6(IF_TYPE_ETHERNET_CSMACD),Socket()成功,但Bind()当然Listen()则失败。

问题

还有我遗漏的任何其他因素或界面参数可以决定结果吗?

尝试 1

循环遍历所有 ipv6 接口只是为了根据经验确定是否有任何接口会成功。 None 在两台机器上完成。

尝试 2

寻找scope id并将其附加到地址,但是,我在接口链表中没有看到scope id参数。

尝试 3

Bind()如果调用InitializeUnicastIpAddressEntry and before the call to CreateUnicastIpAddressEntryipRow.DadState没有设置为IpDadStatePreferred,则

Bind()无法将ip地址输入内部table:

ipRow.DadState = IpDadStatePreferred; // RT:191204: beginning with windows 10, this results in 'preferred' instead of 'tentative'

这导致绑定到 preferred 套接字,可以在其上成功调用 Listen()

以下是 CreateUnicastIpAddressEntry 中不正确的文档片段:

If the value of the DadState member returns with some value other than IpDadStatePreferred or IpDadStateTentative, duplicate address detection has failed and the IP address is not usable.

如果返回的DadStateIpDadStateTentative,该地址也不可用

另外,还有这个:

The DadState, ScopeId, and CreationTimeStamp members of the MIB_UNICASTIPADDRESS_ROW structure that the Row parameter points to are ignored when the CreateUnicastIpAddressEntry function is called.

DadState 不会被忽略,如前所述,如果未设置为首选,将导致非首选、不可用的地址。