bind()适用于ipv6无线适配器接口,但不适用于ipv6以太网(错误10049) [英] bind() works for ipv6 wireless adapter interface but not for ipv6 ethernet (error 10049)
问题描述
背景
在程序开始时,我使用无法在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 并调用
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成员的值返回的值不是 IpDadStatePreferred或IpDadStateTentative,重复的地址 检测失败,并且IP地址不可用.
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.
如果返回的DadState
是IpDadStateTentative
,则该地址也不可用.
If the returned DadState
is IpDadStateTentative
, the address is not useable either.
还有这个:
该对象的
DadState
,ScopeId
和CreationTimeStamp
成员 Row参数指向的MIB_UNICASTIPADDRESS_ROW
结构 调用CreateUnicastIpAddressEntry
函数时将被忽略.
The
DadState
,ScopeId
, andCreationTimeStamp
members of theMIB_UNICASTIPADDRESS_ROW
structure that the Row parameter points to are ignored when theCreateUnicastIpAddressEntry
function is called.
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!