home *** CD-ROM | disk | FTP | other *** search
/ Internet Standards / CD1.mdf / winsock / winsock.h < prev    next >
C/C++ Source or Header  |  1993-10-18  |  30KB  |  854 lines

  1. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  2.  *
  3.  * This header file corresponds to version 1.1 of the Windows Sockets
  4.  * specification.
  5.  *
  6.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  7.  * of the University of California.  All rights reserved.  The
  8.  * Berkeley Software License Agreement specifies the terms and
  9.  * conditions for redistribution.
  10.  *
  11.  * Change log:
  12.  *
  13.  * Fri Apr 23 16:31:01 1993  Mark Towfiq  (towfiq@Microdyne.COM)
  14.  *    New version from David Treadwell which adds extern "C" around
  15.  *    __WSAFDIsSet() and removes "const" from buf param of
  16.  *    WSAAsyncGetHostByAddr().  Added change log.
  17.  *
  18.  * Sat May 15 10:55:00 1993 David Treadwell (davidtr@microsoft.com)
  19.  *    Fix the IN_CLASSC macro to account for class-D multicasts.
  20.  *    Add AF_IPX == AF_NS.
  21.  *
  22.  * Tue Oct 19 13:05:02 1993  Mark Towfiq (Mark.Towfiq@Sun.COM)
  23.  *    New version from David Treadwell which changes type of counter in
  24.  *    fd_set to u_int instead of u_short, so that it is correctly
  25.  *    promoted in Winsdows NT and other 32-bit environments.
  26.  */
  27.  
  28. #ifndef _WINSOCKAPI_
  29. #define _WINSOCKAPI_
  30.  
  31. /*
  32.  * Pull in WINDOWS.H if necessary
  33.  */
  34. #ifndef _INC_WINDOWS
  35. #include <windows.h>
  36. #endif /* _INC_WINDOWS */
  37.  
  38. /*
  39.  * Basic system type definitions, taken from the BSD file sys/types.h.
  40.  */
  41. typedef unsigned char   u_char;
  42. typedef unsigned short  u_short;
  43. typedef unsigned int    u_int;
  44. typedef unsigned long   u_long;
  45.  
  46. /*
  47.  * The new type to be used in all
  48.  * instances which refer to sockets.
  49.  */
  50. typedef u_int           SOCKET;
  51.  
  52. /*
  53.  * Select uses arrays of SOCKETs.  These macros manipulate such
  54.  * arrays.  FD_SETSIZE may be defined by the user before including
  55.  * this file, but the default here should be >= 64.
  56.  *
  57.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  58.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  59.  */
  60. #ifndef FD_SETSIZE
  61. #define FD_SETSIZE      64
  62. #endif /* FD_SETSIZE */
  63.  
  64. typedef struct fd_set {
  65.         u_int   fd_count;               /* how many are SET? */
  66.         SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */
  67. } fd_set;
  68.  
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72.  
  73. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  74.  
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78.  
  79. #define FD_CLR(fd, set) do { \
  80.     u_int __i; \
  81.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  82.         if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  83.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  84.                 ((fd_set FAR *)(set))->fd_array[__i] = \
  85.                     ((fd_set FAR *)(set))->fd_array[__i+1]; \
  86.                 __i++; \
  87.             } \
  88.             ((fd_set FAR *)(set))->fd_count--; \
  89.             break; \
  90.         } \
  91.     } \
  92. } while(0)
  93.  
  94. #define FD_SET(fd, set) do { \
  95.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  96.         ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=fd;\
  97. } while(0)
  98.  
  99. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  100.  
  101. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
  102.  
  103. /*
  104.  * Structure used in select() call, taken from the BSD file sys/time.h.
  105.  */
  106. struct timeval {
  107.         long    tv_sec;         /* seconds */
  108.         long    tv_usec;        /* and microseconds */
  109. };
  110.  
  111. /*
  112.  * Operations on timevals.
  113.  *
  114.  * NB: timercmp does not work for >= or <=.
  115.  */
  116. #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
  117. #define timercmp(tvp, uvp, cmp) \
  118.         ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  119.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  120. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  121.  
  122. /*
  123.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  124.  *
  125.  *
  126.  * Ioctl's have the command encoded in the lower word,
  127.  * and the size of any in or out parameters in the upper
  128.  * word.  The high 2 bits of the upper word are used
  129.  * to encode the in/out status of the parameter; for now
  130.  * we restrict parameters to at most 128 bytes.
  131.  */
  132. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  133. #define IOC_VOID        0x20000000      /* no parameters */
  134. #define IOC_OUT         0x40000000      /* copy out parameters */
  135. #define IOC_IN          0x80000000      /* copy in parameters */
  136. #define IOC_INOUT       (IOC_IN|IOC_OUT)
  137.                                         /* 0x20000000 distinguishes new &
  138.                                            old ioctl's */
  139. #define _IO(x,y)        (IOC_VOID|(x<<8)|y)
  140.  
  141. #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  142.  
  143. #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
  144.  
  145. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  146. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  147. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  148.  
  149. /* Socket I/O Controls */
  150. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  151. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  152. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  153. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  154. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  155.  
  156. /*
  157.  * Structures returned by network data base library, taken from the
  158.  * BSD file netdb.h.  All addresses are supplied in host order, and
  159.  * returned in network order (suitable for use in system calls).
  160.  */
  161.  
  162. struct  hostent {
  163.         char    FAR * h_name;           /* official name of host */
  164.         char    FAR * FAR * h_aliases;  /* alias list */
  165.         short   h_addrtype;             /* host address type */
  166.         short   h_length;               /* length of address */
  167.         char    FAR * FAR * h_addr_list; /* list of addresses */
  168. #define h_addr  h_addr_list[0]          /* address, for backward compat */
  169. };
  170.  
  171. /*
  172.  * It is assumed here that a network number
  173.  * fits in 32 bits.
  174.  */
  175. struct  netent {
  176.         char    FAR * n_name;           /* official name of net */
  177.         char    FAR * FAR * n_aliases;  /* alias list */
  178.         short   n_addrtype;             /* net address type */
  179.         u_long  n_net;                  /* network # */
  180. };
  181.  
  182. struct  servent {
  183.         char    FAR * s_name;           /* official service name */
  184.         char    FAR * FAR * s_aliases;  /* alias list */
  185.         short   s_port;                 /* port # */
  186.         char    FAR * s_proto;          /* protocol to use */
  187. };
  188.  
  189. struct  protoent {
  190.         char    FAR * p_name;           /* official protocol name */
  191.         char    FAR * FAR * p_aliases;  /* alias list */
  192.         short   p_proto;                /* protocol # */
  193. };
  194.  
  195. /*
  196.  * Constants and structures defined by the internet system,
  197.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  198.  */
  199.  
  200. /*
  201.  * Protocols
  202.  */
  203. #define IPPROTO_IP              0               /* dummy for IP */
  204. #define IPPROTO_ICMP            1               /* control message protocol */
  205. #define IPPROTO_GGP             2               /* gateway^2 (deprecated) */
  206. #define IPPROTO_TCP             6               /* tcp */
  207. #define IPPROTO_PUP             12              /* pup */
  208. #define IPPROTO_UDP             17              /* user datagram protocol */
  209. #define IPPROTO_IDP             22              /* xns idp */
  210. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  211.  
  212. #define IPPROTO_RAW             255             /* raw IP packet */
  213. #define IPPROTO_MAX             256
  214.  
  215. /*
  216.  * Port/socket numbers: network standard functions
  217.  */
  218. #define IPPORT_ECHO             7
  219. #define IPPORT_DISCARD          9
  220. #define IPPORT_SYSTAT           11
  221. #define IPPORT_DAYTIME          13
  222. #define IPPORT_NETSTAT          15
  223. #define IPPORT_FTP              21
  224. #define IPPORT_TELNET           23
  225. #define IPPORT_SMTP             25
  226. #define IPPORT_TIMESERVER       37
  227. #define IPPORT_NAMESERVER       42
  228. #define IPPORT_WHOIS            43
  229. #define IPPORT_MTP              57
  230.  
  231. /*
  232.  * Port/socket numbers: host specific functions
  233.  */
  234. #define IPPORT_TFTP             69
  235. #define IPPORT_RJE              77
  236. #define IPPORT_FINGER           79
  237. #define IPPORT_TTYLINK          87
  238. #define IPPORT_SUPDUP           95
  239.  
  240. /*
  241.  * UNIX TCP sockets
  242.  */
  243. #define IPPORT_EXECSERVER       512
  244. #define IPPORT_LOGINSERVER      513
  245. #define IPPORT_CMDSERVER        514
  246. #define IPPORT_EFSSERVER        520
  247.  
  248. /*
  249.  * UNIX UDP sockets
  250.  */
  251. #define IPPORT_BIFFUDP          512
  252. #define IPPORT_WHOSERVER        513
  253. #define IPPORT_ROUTESERVER      520
  254.                                         /* 520+1 also used */
  255.  
  256. /*
  257.  * Ports < IPPORT_RESERVED are reserved for
  258.  * privileged processes (e.g. root).
  259.  */
  260. #define IPPORT_RESERVED         1024
  261.  
  262. /*
  263.  * Link numbers
  264.  */
  265. #define IMPLINK_IP              155
  266. #define IMPLINK_LOWEXPER        156
  267. #define IMPLINK_HIGHEXPER       158
  268.  
  269. /*
  270.  * Internet address (old style... should be updated)
  271.  */
  272. struct in_addr {
  273.         union {
  274.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  275.                 struct { u_short s_w1,s_w2; } S_un_w;
  276.                 u_long S_addr;
  277.         } S_un;
  278. #define s_addr  S_un.S_addr
  279.                                 /* can be used for most tcp & ip code */
  280. #define s_host  S_un.S_un_b.s_b2
  281.                                 /* host on imp */
  282. #define s_net   S_un.S_un_b.s_b1
  283.                                 /* network */
  284. #define s_imp   S_un.S_un_w.s_w2
  285.                                 /* imp */
  286. #define s_impno S_un.S_un_b.s_b4
  287.                                 /* imp # */
  288. #define s_lh    S_un.S_un_b.s_b3
  289.                                 /* logical host */
  290. };
  291.  
  292. /*
  293.  * Definitions of bits in internet address integers.
  294.  * On subnets, the decomposition of addresses to host and net parts
  295.  * is done according to subnet mask, not the masks here.
  296.  */
  297. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  298. #define IN_CLASSA_NET           0xff000000
  299. #define IN_CLASSA_NSHIFT        24
  300. #define IN_CLASSA_HOST          0x00ffffff
  301. #define IN_CLASSA_MAX           128
  302.  
  303. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  304. #define IN_CLASSB_NET           0xffff0000
  305. #define IN_CLASSB_NSHIFT        16
  306. #define IN_CLASSB_HOST          0x0000ffff
  307. #define IN_CLASSB_MAX           65536
  308.  
  309. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000) == 0xc0000000)
  310. #define IN_CLASSC_NET           0xffffff00
  311. #define IN_CLASSC_NSHIFT        8
  312. #define IN_CLASSC_HOST          0x000000ff
  313.  
  314. #define INADDR_ANY              (u_long)0x00000000
  315. #define INADDR_LOOPBACK         0x7f000001
  316. #define INADDR_BROADCAST        (u_long)0xffffffff
  317. #define INADDR_NONE             0xffffffff
  318.  
  319. /*
  320.  * Socket address, internet style.
  321.  */
  322. struct sockaddr_in {
  323.         short   sin_family;
  324.         u_short sin_port;
  325.         struct  in_addr sin_addr;
  326.         char    sin_zero[8];
  327. };
  328.  
  329. #define WSADESCRIPTION_LEN      256
  330. #define WSASYS_STATUS_LEN       128
  331.  
  332. typedef struct WSAData {
  333.         WORD                    wVersion;
  334.         WORD                    wHighVersion;
  335.         char                    szDescription[WSADESCRIPTION_LEN+1];
  336.         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
  337.         unsigned short          iMaxSockets;
  338.         unsigned short          iMaxUdpDg;
  339.         char FAR *              lpVendorInfo;
  340. } WSADATA;
  341.  
  342. typedef WSADATA FAR *LPWSADATA;
  343.  
  344. /*
  345.  * Options for use with [gs]etsockopt at the IP level.
  346.  */
  347. #define IP_OPTIONS      1               /* set/get IP per-packet options */
  348.  
  349. /*
  350.  * Definitions related to sockets: types, address families, options,
  351.  * taken from the BSD file sys/socket.h.
  352.  */
  353.  
  354. /*
  355.  * This is used instead of -1, since the
  356.  * SOCKET type is unsigned.
  357.  */
  358. #define INVALID_SOCKET  (SOCKET)(~0)
  359. #define SOCKET_ERROR            (-1)
  360.  
  361. /*
  362.  * Types
  363.  */
  364. #define SOCK_STREAM     1               /* stream socket */
  365. #define SOCK_DGRAM      2               /* datagram socket */
  366. #define SOCK_RAW        3               /* raw-protocol interface */
  367. #define SOCK_RDM        4               /* reliably-delivered message */
  368. #define SOCK_SEQPACKET  5               /* sequenced packet stream */
  369.  
  370. /*
  371.  * Option flags per-socket.
  372.  */
  373. #define SO_DEBUG        0x0001          /* turn on debugging info recording */
  374. #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
  375. #define SO_REUSEADDR    0x0004          /* allow local address reuse */
  376. #define SO_KEEPALIVE    0x0008          /* keep connections alive */
  377. #define SO_DONTROUTE    0x0010          /* just use interface addresses */
  378. #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
  379. #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
  380. #define SO_LINGER       0x0080          /* linger on close if data present */
  381. #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
  382.  
  383. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  384.  
  385. /*
  386.  * Additional options.
  387.  */
  388. #define SO_SNDBUF       0x1001          /* send buffer size */
  389. #define SO_RCVBUF       0x1002          /* receive buffer size */
  390. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  391. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  392. #define SO_SNDTIMEO     0x1005          /* send timeout */
  393. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  394. #define SO_ERROR        0x1007          /* get error status and clear */
  395. #define SO_TYPE         0x1008          /* get socket type */
  396.  
  397. /*
  398.  * TCP options.
  399.  */
  400. #define TCP_NODELAY     0x0001
  401.  
  402. /*
  403.  * Address families.
  404.  */
  405. #define AF_UNSPEC       0               /* unspecified */
  406. #define AF_UNIX         1               /* local to host (pipes, portals) */
  407. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  408. #define AF_IMPLINK      3               /* arpanet imp addresses */
  409. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  410. #define AF_CHAOS        5               /* mit CHAOS protocols */
  411. #define AF_NS           6               /* XEROX NS protocols */
  412. #define AF_IPX          6               /* IPX and SPX */
  413. #define AF_ISO          7               /* ISO protocols */
  414. #define AF_OSI          AF_ISO          /* OSI is ISO */
  415. #define AF_ECMA         8               /* european computer manufacturers */
  416. #define AF_DATAKIT      9               /* datakit protocols */
  417. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  418. #define AF_SNA          11              /* IBM SNA */
  419. #define AF_DECnet       12              /* DECnet */
  420. #define AF_DLI          13              /* Direct data link interface */
  421. #define AF_LAT          14              /* LAT */
  422. #define AF_HYLINK       15              /* NSC Hyperchannel */
  423. #define AF_APPLETALK    16              /* AppleTalk */
  424. #define AF_NETBIOS      17              /* NetBios-style addresses */
  425.  
  426. #define AF_MAX          18
  427.  
  428. /*
  429.  * Structure used by kernel to store most
  430.  * addresses.
  431.  */
  432. struct sockaddr {
  433.         u_short sa_family;              /* address family */
  434.         char    sa_data[14];            /* up to 14 bytes of direct address */
  435. };
  436.  
  437. /*
  438.  * Structure used by kernel to pass protocol
  439.  * information in raw sockets.
  440.  */
  441. struct sockproto {
  442.         u_short sp_family;              /* address family */
  443.         u_short sp_protocol;            /* protocol */
  444. };
  445.  
  446. /*
  447.  * Protocol families, same as address families for now.
  448.  */
  449. #define PF_UNSPEC       AF_UNSPEC
  450. #define PF_UNIX         AF_UNIX
  451. #define PF_INET         AF_INET
  452. #define PF_IMPLINK      AF_IMPLINK
  453. #define PF_PUP          AF_PUP
  454. #define PF_CHAOS        AF_CHAOS
  455. #define PF_NS           AF_NS
  456. #define PF_IPX          AF_IPX
  457. #define PF_ISO          AF_ISO
  458. #define PF_OSI          AF_OSI
  459. #define PF_ECMA         AF_ECMA
  460. #define PF_DATAKIT      AF_DATAKIT
  461. #define PF_CCITT        AF_CCITT
  462. #define PF_SNA          AF_SNA
  463. #define PF_DECnet       AF_DECnet
  464. #define PF_DLI          AF_DLI
  465. #define PF_LAT          AF_LAT
  466. #define PF_HYLINK       AF_HYLINK
  467. #define PF_APPLETALK    AF_APPLETALK
  468.  
  469. #define PF_MAX          AF_MAX
  470.  
  471. /*
  472.  * Structure used for manipulating linger option.
  473.  */
  474. struct  linger {
  475.         u_short l_onoff;                /* option on/off */
  476.         u_short l_linger;               /* linger time */
  477. };
  478.  
  479. /*
  480.  * Level number for (get/set)sockopt() to apply to socket itself.
  481.  */
  482. #define SOL_SOCKET      0xffff          /* options for socket level */
  483.  
  484. /*
  485.  * Maximum queue length specifiable by listen.
  486.  */
  487. #define SOMAXCONN       5
  488.  
  489. #define MSG_OOB         0x1             /* process out-of-band data */
  490. #define MSG_PEEK        0x2             /* peek at incoming message */
  491. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  492.  
  493. #define MSG_MAXIOVLEN   16
  494.  
  495. /*
  496.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  497.  */
  498. #define MAXGETHOSTSTRUCT        1024
  499.  
  500. /*
  501.  * Define flags to be used with the WSAAsyncSelect() call.
  502.  */
  503. #define FD_READ         0x01
  504. #define FD_WRITE        0x02
  505. #define FD_OOB          0x04
  506. #define FD_ACCEPT       0x08
  507. #define FD_CONNECT      0x10
  508. #define FD_CLOSE        0x20
  509.  
  510. /*
  511.  * All Windows Sockets error constants are biased by WSABASEERR from
  512.  * the "normal"
  513.  */
  514. #define WSABASEERR              10000
  515. /*
  516.  * Windows Sockets definitions of regular Microsoft C error constants
  517.  */
  518. #define WSAEINTR                (WSABASEERR+4)
  519. #define WSAEBADF                (WSABASEERR+9)
  520. #define WSAEACCES               (WSABASEERR+13)
  521. #define WSAEFAULT               (WSABASEERR+14)
  522. #define WSAEINVAL               (WSABASEERR+22)
  523. #define WSAEMFILE               (WSABASEERR+24)
  524.  
  525. /*
  526.  * Windows Sockets definitions of regular Berkeley error constants
  527.  */
  528. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  529. #define WSAEINPROGRESS          (WSABASEERR+36)
  530. #define WSAEALREADY             (WSABASEERR+37)
  531. #define WSAENOTSOCK             (WSABASEERR+38)
  532. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  533. #define WSAEMSGSIZE             (WSABASEERR+40)
  534. #define WSAEPROTOTYPE           (WSABASEERR+41)
  535. #define WSAENOPROTOOPT          (WSABASEERR+42)
  536. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  537. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  538. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  539. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  540. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  541. #define WSAEADDRINUSE           (WSABASEERR+48)
  542. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  543. #define WSAENETDOWN             (WSABASEERR+50)
  544. #define WSAENETUNREACH          (WSABASEERR+51)
  545. #define WSAENETRESET            (WSABASEERR+52)
  546. #define WSAECONNABORTED         (WSABASEERR+53)
  547. #define WSAECONNRESET           (WSABASEERR+54)
  548. #define WSAENOBUFS              (WSABASEERR+55)
  549. #define WSAEISCONN              (WSABASEERR+56)
  550. #define WSAENOTCONN             (WSABASEERR+57)
  551. #define WSAESHUTDOWN            (WSABASEERR+58)
  552. #define WSAETOOMANYREFS         (WSABASEERR+59)
  553. #define WSAETIMEDOUT            (WSABASEERR+60)
  554. #define WSAECONNREFUSED         (WSABASEERR+61)
  555. #define WSAELOOP                (WSABASEERR+62)
  556. #define WSAENAMETOOLONG         (WSABASEERR+63)
  557. #define WSAEHOSTDOWN            (WSABASEERR+64)
  558. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  559. #define WSAENOTEMPTY            (WSABASEERR+66)
  560. #define WSAEPROCLIM             (WSABASEERR+67)
  561. #define WSAEUSERS               (WSABASEERR+68)
  562. #define WSAEDQUOT               (WSABASEERR+69)
  563. #define WSAESTALE               (WSABASEERR+70)
  564. #define WSAEREMOTE              (WSABASEERR+71)
  565.  
  566. /*
  567.  * Extended Windows Sockets error constant definitions
  568.  */
  569. #define WSASYSNOTREADY          (WSABASEERR+91)
  570. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  571. #define WSANOTINITIALISED       (WSABASEERR+93)
  572.  
  573. /*
  574.  * Error return codes from gethostbyname() and gethostbyaddr()
  575.  * (when using the resolver). Note that these errors are
  576.  * retrieved via WSAGetLastError() and must therefore follow
  577.  * the rules for avoiding clashes with error numbers from
  578.  * specific implementations or language run-time systems.
  579.  * For this reason the codes are based at WSABASEERR+1001.
  580.  * Note also that [WSA]NO_ADDRESS is defined only for
  581.  * compatibility purposes.
  582.  */
  583.  
  584. #define h_errno         WSAGetLastError()
  585.  
  586. /* Authoritative Answer: Host not found */
  587. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  588. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  589.  
  590. /* Non-Authoritative: Host not found, or SERVERFAIL */
  591. #define WSATRY_AGAIN            (WSABASEERR+1002)
  592. #define TRY_AGAIN               WSATRY_AGAIN
  593.  
  594. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  595. #define WSANO_RECOVERY          (WSABASEERR+1003)
  596. #define NO_RECOVERY             WSANO_RECOVERY
  597.  
  598. /* Valid name, no data record of requested type */
  599. #define WSANO_DATA              (WSABASEERR+1004)
  600. #define NO_DATA                 WSANO_DATA
  601.  
  602. /* no address, look for MX record */
  603. #define WSANO_ADDRESS           WSANO_DATA
  604. #define NO_ADDRESS              WSANO_ADDRESS
  605.  
  606. /*
  607.  * Windows Sockets errors redefined as regular Berkeley error constants
  608.  */
  609. #define EWOULDBLOCK             WSAEWOULDBLOCK
  610. #define EINPROGRESS             WSAEINPROGRESS
  611. #define EALREADY                WSAEALREADY
  612. #define ENOTSOCK                WSAENOTSOCK
  613. #define EDESTADDRREQ            WSAEDESTADDRREQ
  614. #define EMSGSIZE                WSAEMSGSIZE
  615. #define EPROTOTYPE              WSAEPROTOTYPE
  616. #define ENOPROTOOPT             WSAENOPROTOOPT
  617. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  618. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  619. #define EOPNOTSUPP              WSAEOPNOTSUPP
  620. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  621. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  622. #define EADDRINUSE              WSAEADDRINUSE
  623. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  624. #define ENETDOWN                WSAENETDOWN
  625. #define ENETUNREACH             WSAENETUNREACH
  626. #define ENETRESET               WSAENETRESET
  627. #define ECONNABORTED            WSAECONNABORTED
  628. #define ECONNRESET              WSAECONNRESET
  629. #define ENOBUFS                 WSAENOBUFS
  630. #define EISCONN                 WSAEISCONN
  631. #define ENOTCONN                WSAENOTCONN
  632. #define ESHUTDOWN               WSAESHUTDOWN
  633. #define ETOOMANYREFS            WSAETOOMANYREFS
  634. #define ETIMEDOUT               WSAETIMEDOUT
  635. #define ECONNREFUSED            WSAECONNREFUSED
  636. #define ELOOP                   WSAELOOP
  637. #define ENAMETOOLONG            WSAENAMETOOLONG
  638. #define EHOSTDOWN               WSAEHOSTDOWN
  639. #define EHOSTUNREACH            WSAEHOSTUNREACH
  640. #define ENOTEMPTY               WSAENOTEMPTY
  641. #define EPROCLIM                WSAEPROCLIM
  642. #define EUSERS                  WSAEUSERS
  643. #define EDQUOT                  WSAEDQUOT
  644. #define ESTALE                  WSAESTALE
  645. #define EREMOTE                 WSAEREMOTE
  646.  
  647. /* Socket function prototypes */
  648.  
  649. #ifdef __cplusplus
  650. extern "C" {
  651. #endif
  652.  
  653. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  654.                           int FAR *addrlen);
  655.  
  656. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  657.  
  658. int PASCAL FAR closesocket (SOCKET s);
  659.  
  660. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  661.  
  662. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  663.  
  664. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  665.                             int FAR * namelen);
  666.  
  667. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  668.                             int FAR * namelen);
  669.  
  670. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  671.                            char FAR * optval, int FAR *optlen);
  672.  
  673. u_long PASCAL FAR htonl (u_long hostlong);
  674.  
  675. u_short PASCAL FAR htons (u_short hostshort);
  676.  
  677. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  678.  
  679. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  680.  
  681. int PASCAL FAR listen (SOCKET s, int backlog);
  682.  
  683. u_long PASCAL FAR ntohl (u_long netlong);
  684.  
  685. u_short PASCAL FAR ntohs (u_short netshort);
  686.  
  687. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  688.  
  689. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  690.                          struct sockaddr FAR *from, int FAR * fromlen);
  691.  
  692. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  693.                        fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  694.  
  695. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  696.  
  697. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  698.                        const struct sockaddr FAR *to, int tolen);
  699.  
  700. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  701.                            const char FAR * optval, int optlen);
  702.  
  703. int PASCAL FAR shutdown (SOCKET s, int how);
  704.  
  705. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  706.  
  707. /* Database function prototypes */
  708.  
  709. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  710.                                               int len, int type);
  711.  
  712. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  713.  
  714. int PASCAL FAR gethostname (char FAR * name, int namelen);
  715.  
  716. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  717.  
  718. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  719.                                               const char FAR * proto);
  720.  
  721. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  722.  
  723. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  724.  
  725. /* Microsoft Windows Extension function prototypes */
  726.  
  727. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  728.  
  729. int PASCAL FAR WSACleanup(void);
  730.  
  731. void PASCAL FAR WSASetLastError(int iError);
  732.  
  733. int PASCAL FAR WSAGetLastError(void);
  734.  
  735. BOOL PASCAL FAR WSAIsBlocking(void);
  736.  
  737. int PASCAL FAR WSAUnhookBlockingHook(void);
  738.  
  739. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  740.  
  741. int PASCAL FAR WSACancelBlockingCall(void);
  742.  
  743. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  744.                                         const char FAR * name,
  745.                                         const char FAR * proto,
  746.                                         char FAR * buf, int buflen);
  747.  
  748. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  749.                                         const char FAR * proto, char FAR * buf,
  750.                                         int buflen);
  751.  
  752. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  753.                                          const char FAR * name, char FAR * buf,
  754.                                          int buflen);
  755.  
  756. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  757.                                            int number, char FAR * buf,
  758.                                            int buflen);
  759.  
  760. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  761.                                         const char FAR * name, char FAR * buf,
  762.                                         int buflen);
  763.  
  764. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  765.                                         const char FAR * addr, int len, int type,
  766.                                         char FAR * buf, int buflen);
  767.  
  768. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  769.  
  770. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  771.                                long lEvent);
  772.  
  773. #ifdef __cplusplus
  774. }
  775. #endif
  776.  
  777. /* Microsoft Windows Extended data types */
  778. typedef struct sockaddr SOCKADDR;
  779. typedef struct sockaddr *PSOCKADDR;
  780. typedef struct sockaddr FAR *LPSOCKADDR;
  781.  
  782. typedef struct sockaddr_in SOCKADDR_IN;
  783. typedef struct sockaddr_in *PSOCKADDR_IN;
  784. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  785.  
  786. typedef struct linger LINGER;
  787. typedef struct linger *PLINGER;
  788. typedef struct linger FAR *LPLINGER;
  789.  
  790. typedef struct in_addr IN_ADDR;
  791. typedef struct in_addr *PIN_ADDR;
  792. typedef struct in_addr FAR *LPIN_ADDR;
  793.  
  794. typedef struct fd_set FD_SET;
  795. typedef struct fd_set *PFD_SET;
  796. typedef struct fd_set FAR *LPFD_SET;
  797.  
  798. typedef struct hostent HOSTENT;
  799. typedef struct hostent *PHOSTENT;
  800. typedef struct hostent FAR *LPHOSTENT;
  801.  
  802. typedef struct servent SERVENT;
  803. typedef struct servent *PSERVENT;
  804. typedef struct servent FAR *LPSERVENT;
  805.  
  806. typedef struct protoent PROTOENT;
  807. typedef struct protoent *PPROTOENT;
  808. typedef struct protoent FAR *LPPROTOENT;
  809.  
  810. typedef struct timeval TIMEVAL;
  811. typedef struct timeval *PTIMEVAL;
  812. typedef struct timeval FAR *LPTIMEVAL;
  813.  
  814. /*
  815.  * Windows message parameter composition and decomposition
  816.  * macros.
  817.  *
  818.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  819.  * when constructing the response to a WSAAsyncGetXByY() routine.
  820.  */
  821. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  822. /*
  823.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  824.  * when constructing the response to WSAAsyncSelect().
  825.  */
  826. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  827. /*
  828.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  829.  * to extract the buffer length from the lParam in the response
  830.  * to a WSAGetXByY().
  831.  */
  832. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  833. /*
  834.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  835.  * to extract the error code from the lParam in the response
  836.  * to a WSAGetXByY().
  837.  */
  838. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  839. /*
  840.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  841.  * to extract the event code from the lParam in the response
  842.  * to a WSAAsyncSelect().
  843.  */
  844. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  845. /*
  846.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  847.  * to extract the error code from the lParam in the response
  848.  * to a WSAAsyncSelect().
  849.  */
  850. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  851.  
  852. #endif  /* _WINSOCKAPI_ */
  853.  
  854.