home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / header45.zip / stack16 / winsock.h < prev   
Text File  |  1999-05-11  |  29KB  |  840 lines

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