EN
このコンテンツは設定された言語で表示できません。英語版のページが表示されます。

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..

To query the status of this socket option, call the getsockopt function. To set this option, call the setsockopt function with the following parameters.

Socket option value

The constant that represents this socket option is 19.

Syntax


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
);

Parameters

s [in]

A descriptor identifying the socket.

level [in]

The level at which the option is defined. Use IPPROTO_IPV6 for this operation.

optname [in]

The socket option for which to get or set the value. Use IPV6_PKTINFO for this operation.

optval [out]

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.

Return value

If the operation completes successfully, the getsockopt or setsockopt function returns zero.

If the operation fails, a value of SOCKET_ERROR is returned and a specific error code can be retrieved by calling WSAGetLastError.

Error codeMeaning
WSANOTINITIALISED

A successful WSAStartup call must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAEFAULT

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.

WSAEINPROGRESS

A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.

WSAEINVAL

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.

WSAENOPROTOOPT

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.

WSAENOTSOCK

The descriptor is not a socket.

 

Remarks

The getsockopt function called with the IPV6_PKTINFO socket option allows an application to determine if packet information is to be returned by the WSARecvMsgfunction for an IPv6 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.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Ws2ipdef.h (include Ws2tcpip.h)

See also

Dual-Stack Sockets
getsockopt
in6_pktinfo
IP_PKTINFO
IPPROTO_IPV6 Socket Options
setsockopt
socket
WSAMSG
WSARecvMsg

 

 

コミュニティの追加

追加
表示:
© 2014 Microsoft