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 and also specify the local IPv4 source address to use for sending by the WSASendMsg function..

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

Wert für Socketoption

Die Konstante, die diese Socketoption darstellt, ist 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
);

Parameter

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.

Rückgabewert

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.

 

Hinweise

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 and whether a specific local IPv6 address is to be used for sending by the WSASendMsg function.

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 and also allows an application to enable or disable the ability to specify a specific local address to be used for sending with the WSASendMsg 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.

When this socket option is enabled on an IPv6 socket of type SOCK_DGRAM or SOCK_RAW, an application can also specific the local IP address to use for sending with the WSASendMsg function. One of the control data objects passed in the WSAMSG structure to the WSASendMsg function may contain an in6_pktinfo structure used to specify the local IPv6 source address to use for sending.

For a dual-stack socket for both IPv4 and IPv6, both the IP_PKTINFO socket option and the IPV6_PKTINFO socket option must be enabled for the return of packet information by the WSARecvMsg function.

For a dual-stack socket for both IPv4 and IPv6, both the IP_PKTINFO socket option and the IPV6_PKTINFO socket option must be enabled to be able to specify the specific IP address to use for sending with the WSASendMsg function.

Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h, and should never be used directly.

Anforderungen

Mindestens unterstützter Client

Windows XP

Mindestens unterstützter Server

Windows Server 2003

Header

Ws2ipdef.h (include Ws2tcpip.h)

Siehe auch

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

 

 

Anzeigen:
© 2014 Microsoft