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