IPPROTO_IP Socket Options

The following tables describe IPPROTO_IP socket options that apply to sockets created for the IPv4 address family (AF_INET). 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 pages.

IPPROTO_IP Socket Options
OptionGetSetOptval typeDescription
IP_ADD_MEMBERSHIPyes ip_mreq

Join the socket to the supplied multicast group on the specified interface.

IP_ADD_SOURCE_MEMBERSHIP yes ip_mreq_source

Join the supplied multicast group on the given interface and accept data sourced from the supplied source address.

IP_BLOCK_SOURCEyes ip_mreq_source

Removes the given source as a sender to the supplied multicast group and interface.

IP_DONTFRAGMENTyesyesDWORD (boolean)

Indicates that data should not be fragmented regardless of the local MTU. Valid only for message oriented protocols. Microsoft TCP/IP providers respect this option for UDP and ICMP.

IP_DROP_MEMBERSHIPyes ip_mreq

Leaves the specified multicast group from the specified interface. Service providers must support this option when multicast is supported. Support is indicated in the WSAPROTOCOL_INFO structure returned by a WSAEnumProtocols function call with the following: XPI_SUPPORT_MULTIPOINT=1, XP1_MULTIPOINT_CONTROL_PLANE=0, XP1_MULTIPOINT_DATA_PLANE=0.

IP_DROP_SOURCE_MEMBERSHIPyes ip_mreq_source

Drops membership to the given multicast group, interface, and source address.

IP_HDRINCLyesyesDWORD (boolean)

When set to TRUE, indicates the application provides the IP header. Applies only to SOCK_RAW sockets. The TCP/IP service provider may set the ID field, if the value supplied by the application is zero.

The IP_HDRINCL option is applied only to the SOCK_RAW type of protocol. A TCP/IP service provider that supports SOCK_RAW should also support IP_HDRINCL.

IP_MULTICAST_IFyesyesDWORD

Gets or sets the outgoing interface for sending IPv4 multicast traffic. This option does not change the default interface for receiving IPv4 multicast traffic.

The input value for setting this option is a 4-byte IPv4 address in network byte order. This DWORD parameter can also be an interface index in network byte order. Any IP address in the 0.x.x.x block (first octet of 0) except IPv4 address 0.0.0.0 is treated as an interface index. An interface index is a 24-bit number, and the 0.0.0.0/8 IPv4 address block is not used (this range is reserved). The interface index can be used to specify the default interface for multicast traffic for IPv4. 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 IPv4 traffic in host byte order.

IP_MULTICAST_LOOPyesyesDWORD (boolean)

Controls whether data sent by an application on the local computer (not necessarily by the same socket) in a multicast session will be received by a socket joined to the multicast destination group on the loopback interface. A value of TRUE causes multicast data sent by an application on the local computer to be delivered to a listening socket on the loopback interface. A value of FALSE prevents multicast data sent by an application on the local computer from being delivered to a listening socket on the loopback interface. By default, IP_MULTICAST_LOOPBACK is enabled.

IP_MULTICAST_TTLyesyesDWORDSets/gets the TTL value associated with IP multicast traffic on the socket.
IP_OPTIONS yesyeschar []Specifies IP options to be inserted into outgoing packets. Setting new options overwrites all previously specified options. Setting optval to zero removes all previously specified options. IP_OPTIONS support is not required; to check whether IP_OPTIONS is supported, use getsockopt to get current options. If getsockopt fails, IP_OPTIONS is not supported.
IP_ORIGINAL_ARRIVAL_IFyesyesDWORD (boolean)

Indicates if the WSARecvMsg function should return optional control data containing the arrival interface where the packet was received for datagram sockets.

This option allows the IPv4 interface where the packet was received to be returned in the WSAMSG structure.

This option is only valid on datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).

IP_PKTINFO yesyesDWORDIndicates that packet information should be returned by the WSARecvMsg function.
IP_RECEIVE_BROADCASTyesyesDWORD (boolean)Allows or blocks broadcast reception.
IP_RECVIFyesyesDWORD (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 WSARecvMsg function will return optional control data containing the interface where the packet was received for datagram sockets.

This option allows the IPv4 interface where the packet was received to be returned in the WSAMSG structure.

This option is only valid on datagram and raw sockets (the socket type must be SOCK_DGRAM or SOCK_RAW).

IP_TOSyesyesDWORD (boolean)Do not use. Type of Service (TOS) settings should only be set using the Quality of Service API. See Differentiated Services in the Quality of Service section of the Platform SDK for more information.
IP_TTLyesyesDWORD (boolean)Changes the default value set by the TCP/IP service provider in the TTL field of the IP header in outgoing datagrams. IP_TTL support is not required; to check whether IP_TTL is supported, use getsockopt to get current options. If getsockopt fails, IP_TTL is not supported.
IP_UNBLOCK_SOURCEyes ip_mreq_source

Adds the given source as a sender to the supplied multicast group and interface.

IP_UNICAST_IFyesyesDWORD (IF_INDEX)

Gets or sets the outgoing interface for sending IPv4 traffic. This option does not change the default interface for receiving IPv4 traffic. This option is important for multihomed computers.

The input value for setting this option is a 4-byte IPv4 address in network byte order. This DWORD parameter must be an interface index in network byte order. Any IP address in the 0.x.x.x block (first octet of 0) except IPv4 address 0.0.0.0 is treated as an interface index. An interface index is a 24-bit number, and the 0.0.0.0/8 IPv4 address block is not used (this range is reserved). The interface index can be used to specify the default interface for sending traffic for IPv4. The GetAdaptersAddresses function can be used to obtain the interface index information. If optval is zero , the default interface for sending traffic is set to unspecified.

When getting this option, the optval returns the current default interface index for sending IPv4 traffic in host byte order.

IP_WFP_REDIRECT_CONTEXTyesyesWSACMSGHDR with control data

A datagram socket ancillary data type (cmsg_type) to indicate the redirect context for a UDP socket used by a user mode Windows Filtering Platform (WFP) redirect service.

IP_WFP_REDIRECT_RECORDSyesyesWSACMSGHDR with control data

A datagram socket ancillary data type (cmsg_type) to indicate the redirect record for a UDP socket used by a user mode Windows Filtering Platform (WFP) redirect service.

 

Windows Support for IP_PROTO options
OptionWindows 8Windows Server 2012Windows 7Windows Server 2008Windows VistaWindows Server 2003Windows XP
IP_ADD_MEMBERSHIPxxx xxxx
IP_ADD_SOURCE_MEMBERSHIPxxxxxxx
IP_BLOCK_SOURCExxxxxxx
IP_DONTFRAGMENTxxxxxxx
IP_DROP_MEMBERSHIPxxxxxxx
IP_DROP_SOURCE_MEMBERSHIPxxxxxxx
IP_HDRINCLxxxxxxx
IP_MULTICAST_IFxxxxxxx
IP_MULTICAST_LOOPxxxxxxx
IP_MULTICAST_TTLxxxxxxx
IP_OPTIONS xxxxxxx
IP_ORIGINAL_ARRIVAL_IFxxx
IP_PKTINFOxxxxxxx
IP_RECEIVE_BROADCASTxxxxxxx
IP_RECVIFxxxxx
IP_TOSxx
IP_TTLxxxxxxx
IP_UNBLOCK_SOURCExxxxxxx
IP_UNICAST_IFxxxxx
IP_WFP_REDIRECT_CONTEXTxx
IP_WFP_REDIRECT_RECORDSxx

 

Remarks

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

On the Platform SDK released for Windows Server 2003 and Windows XP, the IPPROTO_IP level is defined in the Winsock2.h header file. Some of the IPPROTO_IP socket options are defined in the Ws2tcpip.h header file. The remaining IPPROTO_IP socket options are defined in the Wsipv6ok.h header file which is automatically included by the Winsock2.h header file. The Wsipv6ok.h header file should never be used directly.

Requirements

Header

Ws2def.h (include Winsock2.h);
Ws2ipdef.h (include Ws2tcpip.h);
Wsipv6ok.h (include Winsock2.h)

 

 

Community Additions

ADD
Show:
© 2014 Microsoft