MSDN Documentation

WS2_32 Functions

This section provides detailed reference information for the Windows Sockets API (Winsock) functions. These functions are part of the ws2_32.dll library and are essential for network programming on Windows.

accept

Accepts a connection on a socket.

int accept(SOCKET s, struct sockaddr FAR * addr, int FAR * len);

bind

Associates a local address with a socket.

int bind(SOCKET s, const struct sockaddr FAR * name, int namelen);

closesocket

Closes an existing socket.

int closesocket(SOCKET s);

connect

Establishes a connection to a specified remote socket.

int connect(SOCKET s, const struct sockaddr FAR * name, int namelen);

getpeername

Retrieves the address of the peer connected to a socket.

int getpeername(SOCKET s, struct sockaddr FAR * name, int FAR * namelen);

getsockname

Retrieves the local name for a socket.

int getsockname(SOCKET s, struct sockaddr FAR * name, int FAR * namelen);

getsockopt

Retrieves the current value for a socket option.

int getsockopt(SOCKET s, int level, int optname, char FAR * optval, int FAR * optlen);

htonl

Converts a ULONG from host byte order to network byte order.

unsigned long htonl(unsigned long hostlong);

htons

Converts a ULONG from host byte order to network byte order.

unsigned short htons(unsigned short hostshort);

inet_addr

Converts an IPv4 address string to its binary representation.

unsigned long inet_addr(const char FAR * cp);

inet_ntoa

Converts an IPv4 address from its binary representation to a string.

char FAR* inet_ntoa(struct in_addr in);

listen

Sets up a socket to listen for incoming connection requests.

int listen(SOCKET s, int backlog);

ntohl

Converts a ULONG from network byte order to host byte order.

unsigned long ntohl(unsigned long netlong);

ntohs

Converts a ULONG from network byte order to host byte order.

unsigned short ntohs(unsigned short netshort);

recv

Receives data from a connected socket.

int recv(SOCKET s, char FAR* buf, int len, int flags);

recvfrom

Receives data from a socket and stores the originating address.

int recvfrom(SOCKET s, char FAR* buf, int len, int flags, struct sockaddr FAR* from, int FAR* fromlen);

select

Monitors multiple socket handles for readiness.

int select(int nfds, fd_set FAR* readfds, fd_set FAR* writefds, fd_set FAR* exceptfds, const struct timeval FAR* timeout);

send

Sends data on a connected socket.

int send(SOCKET s, const char FAR* buf, int len, int flags);

sendto

Sends data to a specific destination, from an unconnected socket.

int sendto(SOCKET s, const char FAR* buf, int len, int flags, const struct sockaddr FAR* to, int tolen);

setsockopt

Sets a socket option for a socket.

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

shutdown

Disables sends, receives, or both on a socket.

int shutdown(SOCKET s, int how);

socket

Creates a socket.

SOCKET socket(int af, int type, int protocol);

WSAStartup

Initializes the Windows Sockets DLL.

int WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);

WSACleanup

Shuts down the Winsock DLL.

int WSACleanup(void);