home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pmsock01.zip / pmsock.h < prev    next >
Text File  |  1994-09-23  |  32KB  |  916 lines

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