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