This page lists and describes the various constants used within the Windows Sockets API (Winsock). These constants define flags, options, and values that control socket behavior and provide information.
General Socket Constants
Constant
Value
Description
AF_INET
2
Address Family: Internet Protocol version 4 (IPv4).
AF_INET6
23
Address Family: Internet Protocol version 6 (IPv6).
AF_UNSPEC
0
Address Family: Unspecified.
SOCK_STREAM
1
Socket Type: Stream socket, providing reliable, ordered, and error-checked delivery.
SOCK_DGRAM
2
Socket Type: Datagram socket, providing unreliable, unordered, and connectionless delivery.
IPPROTO_TCP
6
Protocol: Transmission Control Protocol (TCP).
IPPROTO_UDP
17
Protocol: User Datagram Protocol (UDP).
SOL_SOCKET
0xFFFF
Socket Level: General socket options.
INVALID_SOCKET
-1
Represents an invalid socket handle. Typically used for error conditions.
SOCKET_ERROR
-1
General error return value for socket functions.
Socket Option Constants (SOL_SOCKET Level)
Constant
Value
Description
SO_BROADCAST
0x0020
Enables or disables permission to send broadcast data to a network interface.
SO_DEBUG
0x0001
Enables or disables socket debugging.
SO_DONTLINGER
0x8000
Disables the normal socket closing behavior.
SO_ERROR
0x1007
Retrieves error information for the socket.
SO_KEEPALIVE
0x0008
Enables or disables keep-alive probes on the connection.
SO_LINGER
0x0080
Controls the behavior of socket closure when data is pending.
SO_RCVBUF
0x1002
Sets or gets the size of the receive buffer.
SO_RCVTIMEO
0x1006
Sets or gets the receive timeout.
SO_REUSEADDR
0x0002
Enables or disables the reuse of local addresses.
SO_SNDBUF
0x1001
Sets or gets the size of the send buffer.
SO_SNDTIMEO
0x1005
Sets or gets the send timeout.
IP Socket Option Constants (IPPROTO_IP Level)
Constant
Value
Description
IP_ADD_MEMBERSHIP
12
Adds a socket to a multicast group.
IP_DROP_MEMBERSHIP
13
Removes a socket from a multicast group.
IP_HDRINCL
2
Indicates whether the IP header is included in the data buffer for sending datagrams.
IP_OPTIONS
1
Sets or retrieves IP options for a socket.
IP_TTL
4
Sets or retrieves the Time To Live (TTL) value for outgoing IP datagrams.
IPv6 Socket Option Constants (IPPROTO_IPV6 Level)
Constant
Value
Description
IPV6_ADD_MEMBERSHIP
12
Adds a socket to an IPv6 multicast group.
IPV6_DROP_MEMBERSHIP
13
Removes a socket from an IPv6 multicast group.
IPV6_UNICAST_HOPS
4
Sets or retrieves the hop limit for outgoing IPv6 unicast packets.
IPV6_V6ONLY
27
Controls whether a socket can be used for both IPv4 and IPv6 addresses.
Note: The specific values for some constants might vary slightly across different Windows SDK versions. Always refer to your active SDK documentation for the most precise information.
Common Flags for Send/Receive Operations
Constant
Description
MSG_PEEK
Examines incoming data without removing it from the receive queue.
MSG_DONTROUTE
Sends data without observing routing rules. Usually used for diagnostic or routing purposes.
MSG_OOB
Sends or receives out-of-band data.
MSG_WAITALL
Waits until all data is received or an error occurs. (Supported by Winsock 2 and later).
Important: Using MSG_WAITALL can lead to blocking indefinitely if the peer does not send enough data or closes the connection unexpectedly. Ensure proper error handling and timeouts.
Service Type Flags (for WSASocket)
Constant
Description
WSA_FLAG_OVERLAPPED
Specifies that the socket will be used for overlapped I/O operations.
WSA_FLAG_MULTIPOINT_C selectedCard
Specifies that the socket is a multipoint socket.
WSA_FLAG_NO_ERROR_SHIFT
Specifies that error codes should not be shifted.
For detailed explanations and usage examples of these constants, please refer to the specific Winsock API function documentation.