home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / winsock.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  34KB  |  960 lines

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