setsockopt , getsoctopt 函数的Level 参数和 name 参数对应表!!!

来源:互联网 发布:大数据建设有哪些 编辑:程序博客网 时间:2024/04/29 22:31

int setsockopt(
  SOCKET s,
  int level,
  int optname,
  const char* optval,
  int optlen
);

对于这个函数的level级别的参数到底有哪些, optname ,对应的又有哪些,一直很纳闷,终于今天抽空看了下msdn,leve ---- opt name  -- optval 三者之间的对应关系参数弄明白了,贴在这里,供大家一起分享!

IPPROTO_IP

IPPROTO_IPV6

IPPROTO_RM

IPPROTO_TCP

IPPROTO_UDP

NSPROTO_IPX

SOL_APPLETALK

SOL_IRLMP

SOL_SOCKET

 

 

/* Option to use with [gs]etsockopt at the IPPROTO_IP level */

#define IP_OPTIONS      1 /* set/get IP options */

#define IP_HDRINCL      2 /* header is included with data */

#define IP_TOS          3 /* IP type of service and preced*/

#define IP_TTL          4 /* IP time to live */

#define IP_MULTICAST_IF     9 /* set/get IP multicast i/f  */

#define IP_MULTICAST_TTL       10 /* set/get IP multicast ttl */

#define IP_MULTICAST_LOOP      11 /*set/get IP multicast loopback */

#define IP_ADD_MEMBERSHIP      12 /* add an IP group membership */

#define IP_DROP_MEMBERSHIP     13/* drop an IP group membership */

#define IP_DONTFRAGMENT     14 /* don't fragment IP datagrams */

#define IP_ADD_SOURCE_MEMBERSHIP  15 /* join IP group/source */

#define IP_DROP_SOURCE_MEMBERSHIP 16 /* leave IP group/source */

#define IP_BLOCK_SOURCE           17 /* block IP group/source */

#define IP_UNBLOCK_SOURCE         18 /* unblock IP group/source */

#define IP_PKTINFO                19 /* receive packet information for ipv4*/

#define IP_RECEIVE_BROADCAST      22 /* allow/block broadcast reception */

 

/* Option to use with [gs]etsockopt at the IPPROTO_IPV6 level */

#define IPV6_HDRINCL            2  /* Header is included with data */

#define IPV6_UNICAST_HOPS       4  /* Set/get IP unicast hop limit */

#define IPV6_MULTICAST_IF       9  /* Set/get IP multicast interface */

#define IPV6_MULTICAST_HOPS     10 /* Set/get IP multicast ttl */

#define IPV6_MULTICAST_LOOP     11 /* Set/get IP multicast loopback */

#define IPV6_ADD_MEMBERSHIP     12 /* Add an IP group membership */

#define IPV6_DROP_MEMBERSHIP    13 /* Drop an IP group membership */

#define IPV6_JOIN_GROUP         IPV6_ADD_MEMBERSHIP

#define IPV6_LEAVE_GROUP        IPV6_DROP_MEMBERSHIP

#define IPV6_PKTINFO            19 /* Receive packet information for ipv6 */

#define IPV6_HOPLIMIT           21 /* Receive packet hop limit */

#define IPV6_PROTECTION_LEVEL   23 /* Set/get IPv6 protection level */

 

/* Values of IPV6_PROTECTION_LEVEL */

#define PROTECTION_LEVEL_UNRESTRICTED  10  /* For peer-to-peer apps

#define PROTECTION_LEVEL_DEFAULT       20  /* Default level         */

#define PROTECTION_LEVEL_RESTRICTED    30  /* For Intranet apps     */

 

/* Option to use with [gs]etsockopt at the IPPROTO_UDP level */

#define UDP_NOCHECKSUM  1

#define UDP_CHECKSUM_COVERAGE   20  /* Set/get UDP-Lite checksum coverage */

 

/* Option to use with [gs]etsockopt at the IPPROTO_TCP level */

#define  TCP_EXPEDITED_1122 0x0002

 

level = SOL_SOCKET

Value

Type

Meaning

SO_BROADCAST

BOOL

Enables transmission and receipt of broadcast messages on the socket.

SO_CONDITIONAL_ACCEPT

BOOL

Enables sockets to delay the acknowledgment of a connection until after the WSAAccept condition function is called.

SO_DEBUG

BOOL

Records debugging information.

SO_DONTLINGER

BOOL

Does not block close waiting for unsent data to be sent. Setting this option is equivalent to setting SO_LINGER with l_onoff set to zero.

SO_DONTROUTE

BOOL

Does not route: sends directly to interface. Succeeds but is ignored on AF_INET sockets; fails on AF_INET6 sockets with WSAENOPROTOOPT. Not supported on ATM sockets (results in an error).

SO_GROUP_PRIORITY

int

Reserved.

SO_KEEPALIVE

BOOL

Sends keep-alives. Not supported on ATM sockets (results in an error).

SO_LINGER

LINGER

Lingers on close if unsent data is present.

SO_OOBINLINE

BOOL

Receives OOB data in the normal data stream. (See section Protocol Independent Out-Of-band Data for a discussion of this topic.)

SO_RCVBUF

int

Specifies the total per-socket buffer space reserved for receives. This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window.

SO_REUSEADDR

BOOL

Allows the socket to be bound to an address that is already in use. (See bind.) Not applicable on ATM sockets.

SO_EXCLUSIVEADDRUSE

BOOL

Enables a socket to be bound for exclusive access. Does not require administrative privilege.

SO_SNDBUF

int

Specifies the total per-socket buffer space reserved for sends. This is unrelated to SO_MAX_MSG_SIZE or the size of a TCP window.

PVD_CONFIG

Service Provider Dependent

This object stores the configuration information for the service provider associated with socket s. The exact format of this data structure is service provider specific.

level = IPPROTO_TCP1

Value

Type

Meaning

TCP_NODELAY

BOOL

Disables the Nagle algorithm for send coalescing.

1     included for backward compatibility with Windows Sockets 1.1

 

level = NSPROTO_IPX

Note  Windows NT supports all IPX options. Windows Me/98/95 support only the following options:

Note  IPX_PTYPE
IPX_FILTERPTYPE
IPX_DSTYPE
IPX_RECVHDR
IPX_MAXSIZE (used with the getsockopt function)
IPX_ADDRESS (used with the getsockopt function)

Value

Type

Meaning

IPX_PTYPE

int

Sets the IPX packet type.

IPX_FILTERPTYPE

int

Sets the receive filter packet type

IPX_STOPFILTERPTYPE

int

Stops filtering the filter type set with IPX_FILTERTYPE

IPX_DSTYPE

int

Sets the value of the data stream field in the SPX header on every packet sent.

IPX_EXTENDED_ADDRESS

BOOL

Sets whether extended addressing is enabled.

IPX_RECVHDR

BOOL

Sets whether the protocol header is sent up on all receive headers.

IPX_RECEIVE_BROADCAST

BOOL

Indicates broadcast packets are likely on the socket. Set to TRUE by default. Applications that do not use broadcasts should set this to FALSE for better system performance.

IPX_IMMEDIATESPXACK

BOOL

Directs SPX connections not to delay before sending an ACK. Applications without back-and-forth traffic should set this to TRUE to increase performance.

 

BSD options not supported for setsockopt are shown in the following table.

Value

Type

Meaning

SO_ACCEPTCONN

BOOL

Socket is listening.

SO_RCVLOWAT

int

Receives low watermark.

SO_RCVTIMEO

int

Receives time-out in milliseconds (available in the Microsoft implementation of Windows Sockets 2).

SO_SNDLOWAT

int

Sends low watermark.

SO_SNDTIMEO

int

Sends time-out in milliseconds (available in the Microsoft implementation of Windows Sockets 2).

SO_TYPE

int

Type of the socket.

 

SO_CONDITIONAL_ACCEPT

Setting this socket option to TRUE delays the acknowledgment of a connection until after the WSAAccept condition function is called. If FALSE, the connection may be accepted before the condition function is called, but the connection will be disconnected if the condition function rejects the call. This option must be set before calling the listen function, otherwise WSAEINVAL is returned. SO_CONDITIONAL_ACCEPT is only supported for TCP and ATM.

TCP sets SO_CONDITIONAL_ACCEPT to FALSE by default, and therefore by default the connection will be accepted before the WSAAccept condition function is called. When set to TRUE, the conditional decision must be made within the TCP connection time-out. CF_DEFER connections are still subject to the time-out.

ATM sets SO_CONDITIONAL_ACCEPT to TRUE by default.

SO_DEBUG

Windows Sockets service providers are encouraged (but not required) to supply output debug information if the SO_DEBUG option is set by an application. The mechanism for generating the debug information and the form it takes are beyond the scope of this document.

SO_GROUP_PRIORITY

Reserved for future use with socket groups. Group priority indicates the relative priority of the specified socket relative to other sockets within the socket group. Values are nonnegative integers, with zero corresponding to the highest priority. Priority values represent a hint to the underlying service provider about how potentially scarce resources should be allocated. For example, whenever two or more sockets are both ready to transmit data, the highest priority socket (lowest value for SO_GROUP_PRIORITY) should be serviced first with the remainder serviced in turn according to their relative priorities.

SO_KEEPALIVE

An application can request that a TCP/IP provider enable the use of keep-alive packets on TCP connections by turning on the SO_KEEPALIVE socket option. A Windows Sockets provider need not support the use of keep-alives. If it does, the precise semantics are implementation-specific but should conform to section 4.2.3.6 of RFC 1122: Requirements for Internet Hosts—Communication Layers. If a connection is dropped as the result of keep-alives the error code WSAENETRESET is returned to any calls in progress on the socket, and any subsequent calls will fail with WSAENOTCONN.

SO_LINGER

The SO_LINGER option controls the action taken when unsent data is queued on a socket and a closesocket is performed. See closesocket for a description of the way in which the SO_LINGER settings affect the semantics of closesocket. The application sets the desired behavior by creating a LINGER structure (pointed to by the optval parameter) with these members l_onoff and l_linger set appropriately.

SO_REUSEADDR

By default, a socket cannot be bound (see bind) to a local address that is already in use. On occasion, however, it can be necessary to reuse an address in this way. Since every connection is uniquely identified by the combination of local and remote addresses, there is no problem with having two sockets bound to the same local address as long as the remote addresses are different. To inform the Windows Sockets provider that a bind on a socket should not be disallowed because the desired address is already in use by another socket, the application should set the SO_REUSEADDR socket option for the socket before issuing the bind. The option is interpreted only at the time of the bind. It is therefore unnecessary and harmless to set the option on a socket that is not to be bound to an existing address. Setting or resetting the option after the bind has no effect on this or any other socket.

SO_RCVBUF and SO_SNDBUF

When a Windows Sockets implementation supports the SO_RCVBUF and SO_SNDBUF options, an application can request different buffer sizes (larger or smaller). The call to setsockopt can succeed even when the implementation did not provide the whole amount requested. An application must call getsockopt with the same option to check the buffer size actually provided.

SO_RCVTIMEO and SO_SNDTIMEO

When using the recv function, if no data arrives during the period specified in SO_RCVTIMEO, the recv function completes. In Windows versions prior to Windows 2000, any data received subsequently fails with WSAETIMEDOUT. In Windows 2000 and later, if no data arrives within the period specified in SO_RCVTIMEO the recv function returns WSAETIMEDOUT, and if data is received, recv returns SUCCESS.

If a send or receive operation times out on a socket, the socket state is indeterminate, and should not be used; TCP sockets in this state have a potential for data loss, since the operation could be canceled at the same moment the operation was to be completed.

PVD_CONFIG

This object stores the configuration information for the service provider associated with the socket specified in the s parameter. The exact format of this data structure is specific to each service provider.

TCP_NODELAY

The TCP_NODELAY option is specific to TCP/IP service providers. The Nagle algorithm is disabled if the TCP_NODELAY option is enabled (and vice versa). The process involves buffering send data when there is unacknowledged data already in flight or buffering send data until a full-size packet can be sent. It is highly recommended that TCP/IP service providers enable the Nagle Algorithm by default, and for the vast majority of application protocols the Nagle Algorithm can deliver significant performance enhancements. However, for some applications this algorithm can impede performance, and TCP_NODELAY can be used to turn it off. These are applications where many small messages are sent, and the time delays between the messages are maintained. Application writers should not set TCP_NODELAY unless the impact of doing so is well-understood and desired because setting TCP_NODELAY can have a significant negative impact on network and application performance.

 

格式太烂,请见谅!!!

原创粉丝点击