IPPROTO_IPV6 socket options

The following tables describe IPPROTO_IPV6 socket options that apply to sockets created for the IPv6 address family (AF_INET6). See the getsockopt and setsockopt function reference pages for more information on getting and setting socket options.

To enumerate protocols and discover supported properties for each installed protocol, use the WSAEnumProtocols, WSCEnumProtocols, or WSCEnumProtocols32 function.

Some socket options require more explanation than these tables can convey; such options contain links to additional information.

Options

Option get set Optval type Description
IP_ORIGINAL_ARRIVAL_IF yes yes DWORD (boolean) Indicates if the LPFN_WSARECVMSG (WSARecvMsg) function should return optional control data containing the original arrival interface where the packet was received for datagram sockets. This option is used with IPv6 transition technologies (6to4, ISATAP, and Teredo tunnels, for example) that provide address assignment and host-to-host automatic tunneling for unicast IPv6 traffic when IPv6 hosts must traverse IP4 networks to reach other IPv6 networks. IPv6 packets are sent tunneled as IPv4 packets. This option allows the original IPv4 interface where the packet was received to be returned in the WSAMSG structure.
IPV6_ADD_IFLIST yes DWORD (IF_INDEX) Adds an interface index to the IFLIST associated with the IP_IFLIST option.
IPV6_ADD_MEMBERSHIP yes ipv6_mreq Join the socket to the supplied multicast group on the specified interface. This option is only valid on datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).
IPV6_DEL_IFLIST yes DWORD (IF_INDEX) Removes an interface index from the IFLIST associated with the IP_IFLIST option. Entries can be removed only by the application, so be aware that entries might go stale once an interface is removed.
IPV6_DROP_MEMBERSHIP yes ipv6_mreq Leave the supplied multicast group from the given interface. This option is only valid on datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).
IPV6_GET_IFLIST yes DWORD[] (IF_INDEX[]) Gets the current IFLIST associated with the IP_IFLIST option. Returns error if IP_IFLIST is not enabled.
IPV6_HDRINCL yes yes DWORD(boolean) Indicates the application provides the IPv6 header on all outgoing data. If the optval parameter is set to 1 on the call to setsockopt, the option is enabled. If optval is set to 0, the option is disabled. The default value is disabled. This option is only valid for datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW). A TCP/IP service provider that supports SOCK_RAW should also support IPV6_HDRINCL.
IPV6_HOPLIMIT yes yes DWORD (boolean) Indicates that hop (TTL) information should be returned in the LPFN_WSARECVMSG (WSARecvMsg) function. If optval is set to 1 on the call to setsockopt, the option is enabled. If set to 0, the option is disabled. This option is only valid for datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).
IPV6_IFLIST yes yes DWORD (boolean) Gets or sets the IP_IFLIST state of the socket. When this option is set to true, Datagram reception is restricted to interfaces that are in the IFLIST. Datagrams received on any other interfaces are ignored. IFLIST starts empty. Use IP_ADD_IFLIST and IP_DEL_IFLIST to edit the IFLIST.
IPV6_JOIN_GROUP yes ipv6_mreq Same as IPV6_ADD_MEMBERSHIP
IPV6_LEAVE_GROUP yes ipv6_mreq Same as IPV6_DROP_MEMBERSHIP
IPV6_MTU yes DWORD Gets the system's estimate of the path MTU. Socket must be connected.
IPV6_MTU_DISCOVER yes yes DWORD (PMTUD_STATE) Gets or sets the path MTU discovery state for the socket. The default value is IP_PMTUDISC_NOT_SET. For stream sockets, IP_PMTUDISC_NOT_SET and IP_PMTUDISC_DO will perform path MTU discovery. IP_PMTUDISC_DONT and IP_PMTUDISC_PROBE will turn off path MTU discovery. For datagram sockets, if set to IP_PMTUDISC_DO , attempts to send packets larger than path MTU will result in an error. If set to IP_PMTUDISC_DONT, packets will be fragmented according to interface MTU. If set to IP_PMTUDISC_PROBE, attempts to send packets larger than interface MTU will result in an error.
IPV6_MULTICAST_HOPS yes yes DWORD Gets or sets the TTL value associated with IPv6 multicast traffic on the socket. It is illegal to set the TTL to a value greater than 255. This option is only valid for datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).
IPV6_MULTICAST_IF yes yes DWORD Gets or sets the outgoing interface for sending IPv6 multicast traffic. This option does not change the default interface for receiving IPv6 multicast traffic. This option is important for multihomed computers. The input value for setting this option is a 4-byte interface index of the desired outgoing interface in host byte order. The GetAdaptersAddresses function can be used to obtain the interface index information. If optval is set to NULL on call to setsockopt, the default IPv6 interface is used. If optval is zero , the default interface for receiving multicast is specified for sending multicast traffic. When getting this option, the optval returns the current default interface index for sending multicast IPv6 traffic in host byte order.
IPV6_MULTICAST_LOOP yes yes DWORD (boolean) Indicates multicast data sent on the socket will be echoed to the sockets receive buffer if it is also joined on the destination multicast group. If optval is set to 1 on the call to setsockopt, the option is enabled. If set to 0, the option is disabled. This option is only valid for datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).
IPV6_PKTINFO yes yes DWORD (boolean) Indicates that packet information should be returned by the LPFN_WSARECVMSG (WSARecvMsg) function.
IPV6_PROTECTION_LEVEL yes yes INT Enables restriction of a socket to a specified scope, such as addresses with the same link local or site local prefix. Provides various restriction levels and default settings. See IPV6_PROTECTION_LEVEL for more information.
IPV6_RECVIF yes yes DWORD (boolean) Indicates whether the IP stack should populate the control buffer with details about which interface received a packet with a datagram socket. When this value is true, the LPFN_WSARECVMSG (WSARecvMsg) function will return optional control data containing the interface where the packet was received for datagram sockets. This option allows the IPv6 interface where the packet was received to be returned in the WSAMSG structure. This option is only valid for datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).
IPV6_RECVTCLASS yes yes DWORD (boolean) Indicates whether the IP stack should populate the control buffer with a message containing the Traffic Class IPv6 header field on a received datagram. When this value is true, the LPFN_WSARECVMSG (WSARecvMsg) function will return optional control data containing the Traffic Class IPv6 header field value of the received datagram. This option allows the Traffic Class IPv6 header field of the received datagram to be returned in the WSAMSG structure. The returned message type will be IPV6_TCLASS. All DSCP and ECN bits of the Traffic Class field will be returned. This option is only valid on datagram sockets (the socket type must be SOCK_DGRAM).
IPV6_RECVECN yes yes DWORD (boolean) Indicates whether the IP stack should populate the control buffer with a message containing the ECN bits of the Traffic Class IPv6 header field on a received datagram. When this value is true, the LPFN_WSARECVMSG (WSARecvMsg) function will return optional control data containing the ECN bits of the Traffic Class IPv6 header field value of the received datagram. This option allows the ECN bits of the Traffic Class IPv6 header field of the received datagram to be returned in the WSAMSG structure. The returned message type will be IPV6_ECN. All 2 ECN bits of the Traffic Class field will be returned. This option is only valid on datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW). For type-safety, you should use the WSAGetRecvIPEcn and WSASetRecvIPEcn functions instead of using the socket option directly.
IPV6_UNICAST_HOPS yes yes DWORD Gets or sets the current TTL value associated with IPv6 socket for unicast traffic. It is illegal to set the TTL to a value greater than 255.
IPV6_UNICAST_IF yes yes DWORD (IF_INDEX) Gets or sets the outgoing interface for sending IPv6 traffic. This option does not change the default interface for receiving IPv6 traffic. This option is important for multihomed computers. The input value for setting this option is a 4-byte interface index of the desired outgoing interface in host byte order. The GetAdaptersAddresses function can be used to obtain the interface index information. If optval is zero, the default interface for sending IPv6 traffic is set to unspecified. When getting this option, the optval returns the current default interface index for sending IPv6 traffic in host byte order.
IPV6_USER_MTU yes yes DWORD Gets or sets an upper bound on the IP layer MTU (in bytes) for the given socket. If the value is higher than the system's estimate of the path MTU (which you can retrieve on a connected socket by querying the IPV6_MTU socket option), then the option has no effect. If the value is lower, then outbound packets larger than this will be fragmented, or will fail to send, depending on the value of IPV6_DONTFRAG. Default value is IP_UNSPECIFIED_USER_MTU (MAXULONG). For type-safety, you should use the WSAGetIPUserMtu and WSASetIPUserMtu functions instead of using the socket option directly.
IPV6_V6ONLY yes yes DWORD (boolean) Indicates if a socket created for the AF_INET6 address family is restricted to IPv6 communications only. Sockets created for the AF_INET6 address family may be used for both IPv6 and IPv4 communications. Some applications may want to restrict their use of a socket created for the AF_INET6 address family to IPv6 communications only. When this value is nonzero (the default on Windows), a socket created for the AF_INET6 address family can be used to send and receive IPv6 packets only. When this value is zero, a socket created for the AF_INET6 address family can be used to send and receive packets to and from an IPv6 address or an IPv4 address. Note that the ability to interact with an IPv4 address requires the use of IPv4 mapped addresses. This socket option is supported on Windows Vista or later.

Windows support for IPPROTO_IPV6 socket options

Option Windows 8 Windows Server 2012 Windows 7 Windows Server 2008 Windows Vista
IP_ORIGINAL_ARRIVAL_IF yes yes yes
IPV6_ADD_IFLIST Starting with Windows 10, version 1803
IPV6_ADD_MEMBERSHIP yes yes yes yes yes
IPV6_DEL_IFLIST Starting with Windows 10, version 1803
IPV6_DROP_MEMBERSHIP yes yes yes yes yes
IPV6_GET_IFLIST Starting with Windows 10, version 1803
IPV6_HDRINCL yes yes yes yes yes
IPV6_HOPLIMIT yes yes yes yes yes
IPV6_IFLIST Starting with Windows 10, version 1803
IPV6_JOIN_GROUP yes yes yes yes yes
IPV6_LEAVE_GROUP yes yes yes yes yes
IPV6_MULTICAST_HOPS yes yes yes yes yes
IPV6_MULTICAST_IF yes yes yes yes yes
IPV6_MULTICAST_LOOP yes yes yes yes yes
IPV6_PKTINFO yes yes yes yes yes
IPV6_PROTECTION_LEVEL yes yes yes yes yes
IPV6_RECVIF yes yes yes yes yes
IPV6_UNICAST_HOPS yes yes yes yes yes
IPV6_UNICAST_IF yes yes yes yes yes
IPV6_V6ONLY yes yes yes yes yes

Option Windows Server 2003 Windows XP
IP_ORIGINAL_ARRIVAL_IF
IPV6_ADD_IFLIST
IPV6_ADD_MEMBERSHIP yes yes
IPV6_DEL_IFLIST
IPV6_DROP_MEMBERSHIP yes yes
IPV6_GET_IFLIST
IPV6_HDRINCL yes yes
IPV6_HOPLIMIT yes yes
IPV6_IFLIST
IPV6_JOIN_GROUP yes yes
IPV6_LEAVE_GROUP yes yes
IPV6_MULTICAST_HOPS yes yes
IPV6_MULTICAST_IF yes yes
IPV6_MULTICAST_LOOP yes yes
IPV6_PKTINFO yes yes
IPV6_PROTECTION_LEVEL yes yes
IPV6_RECVIF
IPV6_UNICAST_HOPS yes yes
IPV6_UNICAST_IF
IPV6_V6ONLY

Remarks

On the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and IPPROTO_IPV6 level is defined in the Ws2def.h header file which is automatically included in the Winsock2.h header file. The IPPROTO_IPV6 socket options are defined in the Ws2ipdef.h header file which is automatically included in the Ws2tcpip.h header file. The Ws2def.h and Ws2ipdef.h header files should never be used directly.

The IP_ORIGINAL_ARRIVAL_IF socket option is supported on Windows Server 2008 R2 as well as on Windows 7.

Requirements

Requirement Value
Header
Ws2def.h (include Winsock2.h);
Winsock2.h on Windows Server 2003 and Windows XP