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