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. The SIO_ADDRESS_LIST_SORT IOCTL is supported on Windows XP and later.

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. The CreateSortedAddressPairs function should be used instead of the SIO_ADDRESS_LIST_SORT IOCTL on Windows Vista and later.

The following sections describe usage considerations for SIO_ADDRESS_LIST_SORT.


The buffer passed to SIO_ADDRESS_LIST_SORT is a SOCKET_ADDRESS_LIST structure. Each SOCKET_ADDRESS in the list must be in SOCKADDR_IN6 format.

The SIO_ADDRESS_LIST_SORT IOCTL sorts both IPv6 and IPv4 addresses on Windows Vista and later. Any IPv4 addresses in the list to be sorted must be in the IPv4-mapped IPv6 address format. For more information on the IPv4-mapped IPv6 address format, see Dual-Stack Sockets.

On Windows Server 2003, and Windows XP, SIO_ADDRESS_LIST_SORT sorts only IPv6 addresses. IPv4 addresses in the IPv4-mapped IPv6 address format are not supported.

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

The sorting order for IPv6 addresses for the SIO_ADDRESS_LIST_SORT IOCTL is based on the prefix policy table. The prefix policy table is configured using the Netsh.exe command line utility. 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


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

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. For more information, see (This resource may only be available in English.)

The SIO_ADDRESS_LIST_SORT IOCTL sorts addresses from best to worst, and fills in sin6_scope_id members, if needed. For site-local addresses, SIO_ADDRESS_LIST_SORT either fills in the scope-id, or removes the address.

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.

The CreateSortedAddressPairs function should be used instead of the SIO_ADDRESS_LIST_SORT IOCTL on Windows Vista and later. 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.


The SIO_ADDRESS_LIST_SORT IOCTL is defined in the Winsock2.h header file. 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. Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.

The SIO_ADDRESS_LIST_SORT IOCTL is supported on Windows XP and later.