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

拈花ヽ惹草 提交于 2019-12-13 03:05:21

问题


Background

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.

Problem

However, if the interface's IfType is 6 (IF_TYPE_ETHERNET_CSMACD), Socket() succeeds, but Bind() and of course Listen() then fails.

Question

Are there any other factors or interface parameters I have left out that can determine the outcome?

Attempt1

Cycle through all ipv6 interfaces just to empirically determine if any would succeed. None did on two machines.

Attempt2

Looked for scope id and append that to address, however, I didn't see the scope id parameter in the interface linked list.


回答1:


Attempt3

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'

This results in a binding to a preferred socket upon which Listen() can be successfully called.

Here are the incorrect doc snippets in 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.

If the returned DadState is IpDadStateTentative, the address is not useable either.

Also, there is this:

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 is not ignored, and as stated before will result in a non-preferred, non-useable address if not set to preferred.



来源:https://stackoverflow.com/questions/59147682/bind-works-for-ipv6-wireless-adapter-interface-but-not-for-ipv6-ethernet-erro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!