问题描述
背景
在程序开始时,我使用 GetAdaptersAddresses .稍后,在创建ipv6 slaac
地址之后,在IfType
为无线的情况下,即IfType
71(IF_TYPE_IEEE80211
),调用Socket()
,Bind()
和Listen()
都将成功.我的过滤器参数是family
和ifType
.我通过连接和断开以太网电缆进行测试.对于每种情况,我的软件都会找到具有上述参数的活动接口:已连接它会先找到以太网,断开连接则不会找到以太网,然后再寻找无线接口.有关相关代码段,请参见SO 无法在CreateUnicastIpAddressEntry 之后获取GetUnicastIpAddressEntry.
At the beginning of my program I build a linked list of adapter interface addresses using 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 Unable to GetUnicastIpAddressEntry after CreateUnicastIpAddressEntry for relevant code snippets.
问题
但是,如果接口的IfType
是6(IF_TYPE_ETHERNET_CSMACD
),则Socket()
成功,但是Bind()
当然是Listen()
然后失败.
However, if the interface's IfType
is 6 (IF_TYPE_ETHERNET_CSMACD
), Socket()
succeeds, but Bind()
and of course Listen()
then fails.
问题
我是否还有其他因素或接口参数可以确定结果?
Are there any other factors or interface parameters I have left out that can determine the outcome?
Attempt1
循环遍历所有ipv6接口只是为了凭经验确定是否会成功.在两台机器上都没有.
Cycle through all ipv6 interfaces just to empirically determine if any would succeed. None did on two machines.
Attempt2
寻找了scope id
并将其附加到地址,但是,我在接口链接列表中没有看到scope id
参数.
Looked for scope id
and append that to address, however, I didn't see the scope id
parameter in the interface linked list.
推荐答案
Attempt3
Bind()
将无法在内部表中输入IP地址./windows/win32/api/netioapi/nf-netioapi-initializeunicastipaddressentry"rel =" nofollow noreferrer> InitializeUnicastIpAddressEntry 并调用 CreateUnicastIpAddressEntry :
Bind()
will fail to enter the ip address into the internal table if ipRow.DadState
is not set to IpDadStatePreferred
after the call to InitializeUnicastIpAddressEntry and before the call to CreateUnicastIpAddressEntry:
ipRow.DadState = IpDadStatePreferred; // RT:191204: beginning with windows 10, this results in 'preferred' instead of 'tentative'
这导致绑定到preferred
套接字,可以在其上成功调用Listen()
.
This results in a binding to a preferred
socket upon which Listen()
can be successfully called.
这是CreateUnicastIpAddressEntry
中不正确的文档片段:
Here are the incorrect doc snippets in CreateUnicastIpAddressEntry
:
如果返回的DadState
是IpDadStateTentative
,则该地址也不可用.
If the returned DadState
is IpDadStateTentative
, the address is not useable either.
还有这个:
DadState
不会被忽略,并且如前所述,如果未设置为preferred,则会导致一个非首选的,无法使用的地址.
DadState
is not ignored, and as stated before will result in a non-preferred, non-useable address if not set to preferred.
这篇关于bind()适用于ipv6无线适配器接口,但不适用于ipv6以太网(错误10049)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!