271 lines
8.9 KiB
C
271 lines
8.9 KiB
C
/* WINSOCK.H--definitions to be used with the WINSOCK.DLL
|
|
*
|
|
* This header file corresponds to version 1.1 of the Windows Sockets
|
|
* specification.
|
|
*/
|
|
|
|
#ifndef _WINSOCKAPI_
|
|
#define _WINSOCKAPI_
|
|
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/types.h>
|
|
#include <sys/time.h>
|
|
#include <fcntl.h>
|
|
#include <netdb.h>
|
|
#include <sys/socket.h>
|
|
#include "windows.h"
|
|
|
|
/*
|
|
* The new type to be used in all
|
|
* instances which refer to sockets.
|
|
*/
|
|
typedef u_int SOCKET;
|
|
|
|
extern int __WSAFDIsSet(SOCKET, fd_set *);
|
|
|
|
/*
|
|
* Internet address (old style... should be updated)
|
|
*/
|
|
#ifdef WS_USE_OLD_STYLE
|
|
#define s_addr S_un.S_addr /* can be used for most tcp & ip code */
|
|
#define s_host S_un.S_un_b.s_b2 /* host on imp */
|
|
#define s_net S_un.S_un_b.s_b1 /* network */
|
|
#define s_imp S_un.S_un_w.s_w2 /* imp */
|
|
#define s_impno S_un.S_un_b.s_b4 /* imp # */
|
|
#define s_lh S_un.S_un_b.s_b3 /* logical host */
|
|
#endif
|
|
|
|
#define WSADESCRIPTION_LEN 256
|
|
#define WSASYS_STATUS_LEN 128
|
|
|
|
typedef struct WSAData {
|
|
WORD wVersion;
|
|
WORD wHighVersion;
|
|
char szDescription[WSADESCRIPTION_LEN+1];
|
|
char szSystemStatus[WSASYS_STATUS_LEN+1];
|
|
unsigned short iMaxSockets;
|
|
unsigned short iMaxUdpDg;
|
|
char *lpVendorInfo;
|
|
} WSADATA, *LPWSADATA;
|
|
|
|
/*
|
|
* This is used instead of -1, since the
|
|
* SOCKET type is unsigned.
|
|
*/
|
|
#define INVALID_SOCKET (SOCKET)(~0)
|
|
#define SOCKET_ERROR (-1)
|
|
|
|
/*
|
|
* Option flags per-socket.
|
|
*/
|
|
#ifndef SO_DONTLINGER
|
|
#define SO_DONTLINGER (u_int)(~SO_LINGER)
|
|
#endif
|
|
|
|
/*
|
|
* Maximum queue length specifiable by listen.
|
|
*/
|
|
#ifdef SOMAXCONN
|
|
#undef SOMAXCONN
|
|
#endif
|
|
#define SOMAXCONN 5
|
|
|
|
#ifndef MSG_DONTROUTE
|
|
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
|
|
#endif
|
|
#define MSG_MAXIOVLEN 16
|
|
|
|
/*
|
|
* Define constant based on rfc883, used by gethostbyxxxx() calls.
|
|
*/
|
|
#define MAXGETHOSTSTRUCT 1024
|
|
|
|
/*
|
|
* Define flags to be used with the WSAAsyncSelect() call.
|
|
*/
|
|
#define FD_READ 0x01
|
|
#define FD_WRITE 0x02
|
|
#define FD_OOB 0x04
|
|
#define FD_ACCEPT 0x08
|
|
#define FD_CONNECT 0x10
|
|
#define FD_CLOSE 0x20
|
|
|
|
/*
|
|
* All Windows Sockets error constants are biased by WSABASEERR from
|
|
* the "normal"
|
|
*/
|
|
#define WSABASEERR 10000
|
|
/*
|
|
* Windows Sockets definitions of regular Microsoft C error constants
|
|
*/
|
|
#define WSAEINTR (WSABASEERR+4)
|
|
#define WSAEBADF (WSABASEERR+9)
|
|
#define WSAEACCES (WSABASEERR+13)
|
|
#define WSAEFAULT (WSABASEERR+14)
|
|
#define WSAEINVAL (WSABASEERR+22)
|
|
#define WSAEMFILE (WSABASEERR+24)
|
|
|
|
/*
|
|
* Windows Sockets definitions of regular Berkeley error constants
|
|
*/
|
|
#define WSAEWOULDBLOCK (WSABASEERR+35)
|
|
#define WSAEINPROGRESS (WSABASEERR+36)
|
|
#define WSAEALREADY (WSABASEERR+37)
|
|
#define WSAENOTSOCK (WSABASEERR+38)
|
|
#define WSAEDESTADDRREQ (WSABASEERR+39)
|
|
#define WSAEMSGSIZE (WSABASEERR+40)
|
|
#define WSAEPROTOTYPE (WSABASEERR+41)
|
|
#define WSAENOPROTOOPT (WSABASEERR+42)
|
|
#define WSAEPROTONOSUPPORT (WSABASEERR+43)
|
|
#define WSAESOCKTNOSUPPORT (WSABASEERR+44)
|
|
#define WSAEOPNOTSUPP (WSABASEERR+45)
|
|
#define WSAEPFNOSUPPORT (WSABASEERR+46)
|
|
#define WSAEAFNOSUPPORT (WSABASEERR+47)
|
|
#define WSAEADDRINUSE (WSABASEERR+48)
|
|
#define WSAEADDRNOTAVAIL (WSABASEERR+49)
|
|
#define WSAENETDOWN (WSABASEERR+50)
|
|
#define WSAENETUNREACH (WSABASEERR+51)
|
|
#define WSAENETRESET (WSABASEERR+52)
|
|
#define WSAECONNABORTED (WSABASEERR+53)
|
|
#define WSAECONNRESET (WSABASEERR+54)
|
|
#define WSAENOBUFS (WSABASEERR+55)
|
|
#define WSAEISCONN (WSABASEERR+56)
|
|
#define WSAENOTCONN (WSABASEERR+57)
|
|
#define WSAESHUTDOWN (WSABASEERR+58)
|
|
#define WSAETOOMANYREFS (WSABASEERR+59)
|
|
#define WSAETIMEDOUT (WSABASEERR+60)
|
|
#define WSAECONNREFUSED (WSABASEERR+61)
|
|
#define WSAELOOP (WSABASEERR+62)
|
|
#define WSAENAMETOOLONG (WSABASEERR+63)
|
|
#define WSAEHOSTDOWN (WSABASEERR+64)
|
|
#define WSAEHOSTUNREACH (WSABASEERR+65)
|
|
#define WSAENOTEMPTY (WSABASEERR+66)
|
|
#define WSAEPROCLIM (WSABASEERR+67)
|
|
#define WSAEUSERS (WSABASEERR+68)
|
|
#define WSAEDQUOT (WSABASEERR+69)
|
|
#define WSAESTALE (WSABASEERR+70)
|
|
#define WSAEREMOTE (WSABASEERR+71)
|
|
|
|
/*
|
|
* Extended Windows Sockets error constant definitions
|
|
*/
|
|
#define WSASYSNOTREADY (WSABASEERR+91)
|
|
#define WSAVERNOTSUPPORTED (WSABASEERR+92)
|
|
#define WSANOTINITIALISED (WSABASEERR+93)
|
|
|
|
/*
|
|
* Error return codes from gethostbyname() and gethostbyaddr()
|
|
* (when using the resolver). Note that these errors are
|
|
* retrieved via WSAGetLastError() and must therefore follow
|
|
* the rules for avoiding clashes with error numbers from
|
|
* specific implementations or language run-time systems.
|
|
* For this reason the codes are based at WSABASEERR+1001.
|
|
* Note also that [WSA]NO_ADDRESS is defined only for
|
|
* compatibility purposes.
|
|
*/
|
|
|
|
/* #define h_errno WSAGetLastError() */
|
|
|
|
/* Authoritative Answer: Host not found */
|
|
#define WSAHOST_NOT_FOUND (WSABASEERR+1001)
|
|
|
|
/* Non-Authoritative: Host not found, or SERVERFAIL */
|
|
#define WSATRY_AGAIN (WSABASEERR+1002)
|
|
|
|
/* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
|
#define WSANO_RECOVERY (WSABASEERR+1003)
|
|
|
|
/* Valid name, no data record of requested type */
|
|
#define WSANO_DATA (WSABASEERR+1004)
|
|
|
|
/* no address, look for MX record */
|
|
#define WSANO_ADDRESS WSANO_DATA
|
|
|
|
/* Socket function prototypes */
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Microsoft Windows Extension function prototypes */
|
|
|
|
INT WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
|
|
INT WSACleanup(void);
|
|
void WSASetLastError(INT iError);
|
|
INT WSAGetLastError(void);
|
|
BOOL WSAIsBlocking(void);
|
|
INT WSAUnhookBlockingHook(void);
|
|
FARPROC WSASetBlockingHook(FARPROC lpBlockFunc);
|
|
INT WSACancelBlockingCall(void);
|
|
HANDLE WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
|
|
LPCSTR name, LPCSTR proto,
|
|
LPSTR buf, INT buflen);
|
|
HANDLE WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, INT port,
|
|
LPCSTR proto, LPSTR buf, INT buflen);
|
|
HANDLE WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
|
|
LPCSTR name, LPSTR buf, INT buflen);
|
|
HANDLE WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
|
|
INT number, LPSTR buf, INT buflen);
|
|
HANDLE WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
|
|
LPCSTR name, LPSTR buf, INT buflen);
|
|
HANDLE WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg, LPCSTR addr, INT len,
|
|
INT type, LPSTR buf, INT buflen);
|
|
INT WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
|
|
INT WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg, long lEvent);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
/* Microsoft Windows Extended data types */
|
|
typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
|
|
typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
|
|
typedef struct linger LINGER, *PLINGER, *LPLINGER;
|
|
typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
|
|
typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
|
|
typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
|
|
typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
|
|
typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
|
|
typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
|
|
|
|
/*
|
|
* Windows message parameter composition and decomposition
|
|
* macros.
|
|
*
|
|
* WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
|
|
* when constructing the response to a WSAAsyncGetXByY() routine.
|
|
*/
|
|
#define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
|
|
/*
|
|
* WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
|
|
* when constructing the response to WSAAsyncSelect().
|
|
*/
|
|
#define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
|
|
/*
|
|
* WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
|
|
* to extract the buffer length from the lParam in the response
|
|
* to a WSAGetXByY().
|
|
*/
|
|
#define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
|
|
/*
|
|
* WSAGETASYNCERROR is intended for use by the Windows Sockets application
|
|
* to extract the error code from the lParam in the response
|
|
* to a WSAGetXByY().
|
|
*/
|
|
#define WSAGETASYNCERROR(lParam) HIWORD(lParam)
|
|
/*
|
|
* WSAGETSELECTEVENT is intended for use by the Windows Sockets application
|
|
* to extract the event code from the lParam in the response
|
|
* to a WSAAsyncSelect().
|
|
*/
|
|
#define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
|
|
/*
|
|
* WSAGETSELECTERROR is intended for use by the Windows Sockets application
|
|
* to extract the error code from the lParam in the response
|
|
* to a WSAAsyncSelect().
|
|
*/
|
|
#define WSAGETSELECTERROR(lParam) HIWORD(lParam)
|
|
|
|
#endif /* _WINSOCKAPI_ */
|