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

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