Winsock Constants

This section details the various constants defined for the Windows Sockets API (Winsock).

General Constants

AF_INET

Address family for IPv4.

#define AF_INET 2

AF_INET6

Address family for IPv6.

#define AF_INET6 23

SOCK_STREAM

Socket type for connection-oriented communication (e.g., TCP).

#define SOCK_STREAM 1

SOCK_DGRAM

Socket type for connectionless communication (e.g., UDP).

#define SOCK_DGRAM 2

IPPROTO_TCP

Protocol for TCP.

#define IPPROTO_TCP 6

IPPROTO_UDP

Protocol for UDP.

#define IPPROTO_UDP 17

Socket Option Level Constants

SOL_SOCKET

Generic socket options.

#define SOL_SOCKET 0xFFFF

SOL_IP

IP level socket options (IPv4).

#define SOL_IP 0

SOL_IPV6

IP level socket options (IPv6).

#define SOL_IPV6 41

SOL_TCP

TCP level socket options.

#define SOL_TCP 6

Socket Option Name Constants (SOL_SOCKET)

SO_DEBUG

Enable debugging.

#define SO_DEBUG 1

SO_ACCEPTCONN

Indicate whether a socket is listening for connections.

#define SO_ACCEPTCONN 2

SO_REUSEADDR

Allow reuse of local addresses.

#define SO_REUSEADDR 4

SO_KEEPALIVE

Keep connections active.

#define SO_KEEPALIVE 8

SO_LINGER

Linger on close of a socket.

#define SO_LINGER 128

SO_BROADCAST

Enable broadcast sockets.

#define SO_BROADCAST 32

SO_RCVTIMEO

Receive timeout.

#define SO_RCVTIMEO 2002

SO_SNDTIMEO

Send timeout.

#define SO_SNDTIMEO 2003

Error Codes

Common Winsock error codes are typically returned by Winsock functions. They can be retrieved using WSAGetLastError().

WSAEINTR

A blocking Winsock call was interrupted by a call to WSACancelBlockingCall.

#define WSAEINTR 10004

WSAECONNRESET

An existing connection was forcibly closed by the remote host.

#define WSAECONNRESET 10054

WSAETIMEDOUT

A connection attempt timed out without establishing a connection.

#define WSAETIMEDOUT 10060