home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / WINSOCK.H < prev    next >
C/C++ Source or Header  |  1997-02-14  |  34KB  |  966 lines

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