IPV6_PKTINFO socket option
The IPV6_PKTINFO socket option allows an application to enable or disable the return of packet information by the WSARecvMsg function on an IPv6 socket..
Socket option value
The constant that represents this socket option is 19.
int getsockopt( (SOCKET) s, // descriptor identifying a socket (int) IPPROTO_IPV6, // level (int) IPV6_PKTINFO, // optname (char *) optval, // output buffer, (int) optlen, // size of output buffer );
int setsockopt( (SOCKET) s, // descriptor identifying a socket (int) IPPROTO_IPV6, // level (int) IPV6_PKTINFO, // optname (char *) optval, // input buffer, (int) optlen, // size of input buffer );
A descriptor identifying the socket.
The level at which the option is defined. Use IPPROTO_IPV6 for this operation.
The socket option for which to get or set the value. Use IPV6_PKTINFO for this operation.
A pointer to the buffer containing the value for the option to set. This parameter should point to buffer equal to or larger than the size of a DWORD value.
This value is treated as a boolean value with 0 used to indicate FALSE (disabled) and a nonzero value to indicate TRUE (enabled).
optlen [in, out]
A pointer to the size, in bytes, of the optval buffer. This size must be equal to or larger than the size of a DWORD value.
If the operation fails, a value of SOCKET_ERROR is returned and a specific error code can be retrieved by calling WSAGetLastError.
|A successful WSAStartup call must occur before using this function.
|The network subsystem has failed.
|One of the optval or the optlen parameters point to memory that is not in a valid part of the user address space. This error is also returned if the value pointed to by the optlen parameter is less than the size of a DWORD value.
|A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
|An invalid argument was supplied. This error is returned if the level parameter is unknown or invalid. On Windows Vista and later, this error is also returned if the socket was in a transitional state.
|The option is unknown or unsupported by the indicated protocol family. This error is returned if the type parameter for the socket descriptor passed in the s parameter was not SOCK_DGRAM or SOCK_RAW.
|The descriptor is not a socket.
The setsockopt function called with the IPV6_PKTINFO socket option allows an application to enable or disable the return of packet information by the WSARecvMsg function. The IPV6_PKTINFO option for a socket is disabled (set to FALSE) by default.
When this socket option is enabled on an IPv6 socket of type SOCK_DGRAM or SOCK_RAW, the WSARecvMsg function returns packet information in the WSAMSG structure pointed to by the lpMsg parameter. One of the control data objects in the returned WSAMSG structure will contain an in6_pktinfo structure used to store received packet address information.
For datagrams received by the WSARecvMsg function over IPv6, the Control member of the WSAMSG structure received will contain a WSABUF structure that contains a WSACMSGHDR structure. The cmsg_level member of this WSACMSGHDR structure would contain IPPROTO_IPV6, the cmsg_type member of this structure would contain IPV6_PKTINFO, and the cmsg_data member would contain an in6_pktinfo structure used to store received IPv6 packet address information. The IPv6 address in the in6_pktinfo structure is the IPv6 address from which the packet was received.
For a dual-stack datagram socket, if an application requires the WSARecvMsg function to return packet information in a WSAMSG structure for datagrams received over IPv4, then IP_PKTINFO socket option must be set to true on the socket. If only the IPV6_PKTINFO option is set to true on the socket, packet information will be provided for datagrams received over IPv6 but may not be provided for datagrams received over IPv4.
Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h, and should never be used directly.
|Minimum supported client
||Windows XP [desktop apps only]
|Minimum supported server
||Windows Server 2003 [desktop apps only]