home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / wsftp2.zip / WINSOCK.H < prev    next >
C/C++ Source or Header  |  1993-06-22  |  31KB  |  874 lines

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