使用 SIO _ 地址 _ 列表 _ 排序Using SIO_ADDRESS_LIST_SORT

SIO _ ADDRESS _ LIST _ sort IOCTL 允许应用程序开发人员对 IPv6 和 IPv4 目标地址列表进行排序,以确定用于建立连接的最佳可用地址。The SIO_ADDRESS_LIST_SORT IOCTL allows application developers to sort a list of IPv6 and IPv4 destination addresses to determine the best available address for making a connection. Windows XP 和更高版本支持 SIO _ 地址 _ 列表 _ 排序 IOCTL。The SIO_ADDRESS_LIST_SORT IOCTL is supported on Windows XP and later.

在 Windows Vista 和更高版本中, CreateSortedAddressPairs 函数使用提供的潜在 IP 目标地址列表,将目标地址与主机的本地 IP 地址配对,并根据最适合于两个对等方之间的通信的地址对进行排序。On Windows Vista and later, the CreateSortedAddressPairs function takes a supplied list of potential IP destination addresses, pairs the destination addresses with the host machine's local IP addresses, and sorts the pairs according to which address pair is best suited for communication between the two peers. 应在 Windows Vista 和更高版本上使用 CreateSortedAddressPairs 函数,而不是 SIO _ 地址 _ 列表 _ 排序 IOCTL。The CreateSortedAddressPairs function should be used instead of the SIO_ADDRESS_LIST_SORT IOCTL on Windows Vista and later.

以下各节描述了 SIO _ 地址 _ 列表 _ 排序 的使用注意事项。The following sections describe usage considerations for SIO_ADDRESS_LIST_SORT.

参数Parameters

传递到 SIO _ 地址 _ 列表 _ 排序 的缓冲区是 套接字 _ 地址 _ 列表 结构。The buffer passed to SIO_ADDRESS_LIST_SORT is a SOCKET_ADDRESS_LIST structure. 列表中的每个 套接字 _ 地址 必须采用 SOCKADDR _ IN6 格式。Each SOCKET_ADDRESS in the list must be in SOCKADDR_IN6 format.

SIO _ 地址 _ 列表 _ 排序 IOCTL 对 Windows Vista 和更高版本上的 IPv6 和 IPv4 地址进行排序。The SIO_ADDRESS_LIST_SORT IOCTL sorts both IPv6 and IPv4 addresses on Windows Vista and later. 要排序的列表中的任何 IPv4 地址必须采用 IPv4 映射的 IPv6 地址格式。Any IPv4 addresses in the list to be sorted must be in the IPv4-mapped IPv6 address format. 有关 IPv4 映射的 IPv6 地址格式的详细信息,请参阅 双堆栈套接字For more information on the IPv4-mapped IPv6 address format, see Dual-Stack Sockets.

在 Windows Server 2003 和 Windows XP 上, SIO _ 地址 _ 列表 _ 排序 只对 IPv6 地址进行排序。On Windows Server 2003, and Windows XP, SIO_ADDRESS_LIST_SORT sorts only IPv6 addresses. 不支持 IPv4 映射的 IPv6 地址格式的 IPv4 地址。IPv4 addresses in the IPv4-mapped IPv6 address format are not supported.

输出时,如果 IOCTL 代码确定某些目标地址无效,套接字 _ 地址 _ 列表结构的 iAddressCount 成员可能小于输入。On output, the iAddressCount member of the SOCKET_ADDRESS_LIST structure may be smaller than on input if the IOCTL code determines that some destination addresses are invalid.

排序确定Sorting Determination

SIO 地址列表排序 IOCTL 的 IPv6 地址的排序顺序 _ _ _ 基于前缀策略表。The sorting order for IPv6 addresses for the SIO_ADDRESS_LIST_SORT IOCTL is based on the prefix policy table. 前缀策略表使用 Netsh.exe 命令行实用程序进行配置。The prefix policy table is configured using the Netsh.exe command line utility. 以下命令行段说明了基本 Netsh.exe 前缀策略表配置命令:The following command line snippets illustrate basic Netsh.exe prefix policy table configuration commands:

netsh interface ipv6 show prefixpolicies
netsh interface ipv6 add prefixpolicy ::/96 3 4
netsh interface ipv6 delete prefixpolicy ::/96
netsh interface ipv6 set prefixpolicy ::/96 3 4

备注

在 Windows Server 2003 和 Windows XP 上,上面列出的第一个 netsh 命令如下所示。On Windows Server 2003 and Windows XP, the first netsh command listed above was as follows. 所有其他相关命令都是相同的。All other related commands are the same.

netsh interface ipv6 show prefixpolicy

地址排序还由 IETF 发布的 Internet 协议版本 6 (IPv6) 上的 RFC 3484 中所述的算法决定。Address ordering is also determined by an algorithm outlined in the RFC 3484 on Default Address Selection for Internet Protocol version 6 (IPv6) published by the IETF. 有关详细信息,请参阅 https://www.ietf.org/rfc/rfc3484.txtFor more information, see https://www.ietf.org/rfc/rfc3484.txt. (此资源只能用英语提供。 ) (This resource may only be available in English.)

SIO _ 地址 _ 列表 _ 排序 IOCTL 将地址从最佳到最差排序,并根据需要填写 sin6 _ 范围 _ id 成员。The SIO_ADDRESS_LIST_SORT IOCTL sorts addresses from best to worst, and fills in sin6_scope_id members, if needed. 对于站点本地地址,SIO _ 地址 _ 列表 _ 排序将填充作用域 id,或删除该地址。For site-local addresses, SIO_ADDRESS_LIST_SORT either fills in the scope-id, or removes the address.

SIO _ 地址 _ 列表 _ 排序 IOCTL 将忽略绑定到套接字的源地址,并只按作为参数传递的目标地址列表进行排序。The SIO_ADDRESS_LIST_SORT IOCTL ignores the source address bound to the socket and only sorts by the destination address list passed as a parameter.

应在 Windows Vista 和更高版本上使用 CreateSortedAddressPairs 函数,而不是 SIO _ 地址 _ 列表 _ 排序 IOCTL。The CreateSortedAddressPairs function should be used instead of the SIO_ADDRESS_LIST_SORT IOCTL on Windows Vista and later. CreateSortedAddressPairs 函数返回包含本地源地址和目标地址的地址对的列表。The CreateSortedAddressPairs function returns a list of address pairs that contains a local source address and a destination address. 这为应用程序提供了要用于每个目标地址的正确源地址。This provides an application the correct source address to use for each destination address. 应用程序还可以通过查找特定源地址来筛选结果。An application can also filter the results by looking for a specific source address. in the results.

要求Requirements

SIO _ 地址 _ 列表 _ 排序 IOCTL 在 Winsock2 标头文件中定义。The SIO_ADDRESS_LIST_SORT IOCTL is defined in the Winsock2.h header file. 在 Windows Vista 和更高版本的 Microsoft Windows 软件开发工具包 (SDK) 上,标头文件的组织已更改,并且 SIO _ 地址 _ 列表 _ 排序 IOCTL 在 Ws2def 头文件中定义。On the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and SIO_ADDRESS_LIST_SORT IOCTL is defined in the Ws2def.h header file. 请注意, Ws2def 标头文件自动包含在 Winsock2 中,不应直接使用。Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.

Windows XP 和更高版本支持 SIO _ 地址 _ 列表 _ 排序 IOCTL。The SIO_ADDRESS_LIST_SORT IOCTL is supported on Windows XP and later.

CreateSortedAddressPairsCreateSortedAddressPairs