home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / winh / winsock.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  31.4 KB  |  917 lines

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