home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / include / xsocket.h < prev    next >
Text File  |  1998-03-21  |  23KB  |  629 lines

  1.  
  2. #if !defined( __XSOCKET_H__ )
  3. #define __XSOCKET_H__
  4.  
  5. #if defined( __WATCOMC__ )
  6. #include <types.h>
  7. #endif
  8.  
  9. #include <stdlib.h>
  10.  
  11. #ifndef __IBMCPP__
  12. #include <sys\types.h>
  13. extern "C" {
  14.    #include <sys\socket.h>
  15.    #include <netinet\in.h>
  16.    #include <netdb.h>
  17. }
  18. #endif
  19.  
  20.  
  21. #include "xio.h"
  22. #include "xstring.h"
  23. #include "xexcept.h"
  24.  
  25.  
  26.  
  27. // TBO
  28. #if defined( __IBMCPP__ )
  29. #define INET
  30.  
  31. typedef int*  PINT;
  32. typedef int   DTYP1;
  33.  
  34. #ifndef __off_t
  35.   #define __off_t
  36.   typedef long off_t;
  37. #endif
  38.  
  39. typedef char *caddr_t;
  40. typedef long daddr_t;
  41.  
  42. #define NIL   ((char*) 0)
  43. #define PZERO 0
  44.  
  45. #define MAXHOSTNAMELEN 120
  46. #ifndef MAXPATHLEN
  47.    #define MAXPATHLEN CCHMAXPATH
  48. #endif
  49. #define MAXSOCKETS 2048
  50.  
  51.  
  52. #define SOCBASEERR              10000
  53.  
  54. // OS/2 SOCKET API definitions of regular Microsoft C 6.0 error constants
  55.  
  56. #define SOCEPERM                (SOCBASEERR+1)             // Not owner
  57. #define SOCESRCH                (SOCBASEERR+3)             // No such process
  58. #define SOCEINTR                (SOCBASEERR+4)             // Interrupted system call
  59. #define SOCENXIO                (SOCBASEERR+6)             // No such device or address
  60. #define SOCEBADF                (SOCBASEERR+9)             // Bad file number
  61. #define SOCEACCES               (SOCBASEERR+13)            // Permission denied
  62. #define SOCEFAULT               (SOCBASEERR+14)            // Bad address
  63. #define SOCEINVAL               (SOCBASEERR+22)            // Invalid argument
  64. #define SOCEMFILE               (SOCBASEERR+24)            // Too many open files
  65. #define SOCEPIPE                (SOCBASEERR+32)            // Broken pipe
  66.  
  67. #define SOCEOS2ERR              (SOCBASEERR+100)           // OS/2 Error
  68.  
  69. // OS/2 SOCKET API definitions of regular BSD error constants
  70.  
  71. #define SOCEWOULDBLOCK          (SOCBASEERR+35)            // Operation would block
  72. #define SOCEINPROGRESS          (SOCBASEERR+36)            // Operation now in progress
  73. #define SOCEALREADY             (SOCBASEERR+37)            // Operation already in progress
  74. #define SOCENOTSOCK             (SOCBASEERR+38)            // Socket operation on non-socket
  75. #define SOCEDESTADDRREQ         (SOCBASEERR+39)            // Destination address required
  76. #define SOCEMSGSIZE             (SOCBASEERR+40)            // Message too long
  77. #define SOCEPROTOTYPE           (SOCBASEERR+41)            // Protocol wrong type for socket
  78. #define SOCENOPROTOOPT          (SOCBASEERR+42)            // Protocol not available
  79. #define SOCEPROTONOSUPPORT      (SOCBASEERR+43)            // Protocol not supported
  80. #define SOCESOCKTNOSUPPORT      (SOCBASEERR+44)            // Socket type not supported
  81. #define SOCEOPNOTSUPP           (SOCBASEERR+45)            // Operation not supported on socket
  82. #define SOCEPFNOSUPPORT         (SOCBASEERR+46)            // Protocol family not supported
  83. #define SOCEAFNOSUPPORT         (SOCBASEERR+47)            // Address family not supported by protocol family
  84. #define SOCEADDRINUSE           (SOCBASEERR+48)            // Address already in use
  85. #define SOCEADDRNOTAVAIL        (SOCBASEERR+49)            // Can't assign requested address
  86. #define SOCENETDOWN             (SOCBASEERR+50)            // Network is down
  87. #define SOCENETUNREACH          (SOCBASEERR+51)            // Network is unreachable
  88. #define SOCENETRESET            (SOCBASEERR+52)            // Network dropped connection on reset
  89. #define SOCECONNABORTED         (SOCBASEERR+53)            // Software caused connection abort
  90. #define SOCECONNRESET           (SOCBASEERR+54)            // Connection reset by peer
  91. #define SOCENOBUFS              (SOCBASEERR+55)            // No buffer space available
  92. #define SOCEISCONN              (SOCBASEERR+56)            // Socket is already connected
  93. #define SOCENOTCONN             (SOCBASEERR+57)            // Socket is not connected
  94. #define SOCESHUTDOWN            (SOCBASEERR+58)            // Can't send after socket shutdown
  95. #define SOCETOOMANYREFS         (SOCBASEERR+59)            // Too many references: can't splice
  96. #define SOCETIMEDOUT            (SOCBASEERR+60)            // Connection timed out
  97. #define SOCECONNREFUSED         (SOCBASEERR+61)            // Connection refused
  98. #define SOCELOOP                (SOCBASEERR+62)            // Too many levels of symbolic links
  99. #define SOCENAMETOOLONG         (SOCBASEERR+63)            // File name too long
  100. #define SOCEHOSTDOWN            (SOCBASEERR+64)            // Host is down
  101. #define SOCEHOSTUNREACH         (SOCBASEERR+65)            // No route to host
  102. #define SOCENOTEMPTY            (SOCBASEERR+66)            // Directory not empty
  103.  
  104. // OS/2 SOCKET API errors redefined as regular BSD error constants
  105.  
  106. #define EWOULDBLOCK             SOCEWOULDBLOCK
  107. #define EINPROGRESS             SOCEINPROGRESS
  108. #define EALREADY                SOCEALREADY
  109. #define ENOTSOCK                SOCENOTSOCK
  110. #define EDESTADDRREQ            SOCEDESTADDRREQ
  111. #define EMSGSIZE                SOCEMSGSIZE
  112. #define EPROTOTYPE              SOCEPROTOTYPE
  113. #define ENOPROTOOPT             SOCENOPROTOOPT
  114. #define EPROTONOSUPPORT         SOCEPROTONOSUPPORT
  115. #define ESOCKTNOSUPPORT         SOCESOCKTNOSUPPORT
  116. #define EOPNOTSUPP              SOCEOPNOTSUPP
  117. #define EPFNOSUPPORT            SOCEPFNOSUPPORT
  118. #define EAFNOSUPPORT            SOCEAFNOSUPPORT
  119. #define EADDRINUSE              SOCEADDRINUSE
  120. #define EADDRNOTAVAIL           SOCEADDRNOTAVAIL
  121. #define ENETDOWN                SOCENETDOWN
  122. #define ENETUNREACH             SOCENETUNREACH
  123. #define ENETRESET               SOCENETRESET
  124. #define ECONNABORTED            SOCECONNABORTED
  125. #define ECONNRESET              SOCECONNRESET
  126. #define ENOBUFS                 SOCENOBUFS
  127. #define EISCONN                 SOCEISCONN
  128. #define ENOTCONN                SOCENOTCONN
  129. #define ESHUTDOWN               SOCESHUTDOWN
  130. #define ETOOMANYREFS            SOCETOOMANYREFS
  131. #define ETIMEDOUT               SOCETIMEDOUT
  132. #define ECONNREFUSED            SOCECONNREFUSED
  133. #define ELOOP                   SOCELOOP
  134. #define ENAMETOOLONG            SOCENAMETOOLONG
  135. #define EHOSTDOWN               SOCEHOSTDOWN
  136. #define EHOSTUNREACH            SOCEHOSTUNREACH
  137. #define ENOTEMPTY               SOCENOTEMPTY
  138.  
  139. // Address families.
  140.  
  141. #define AF_UNSPEC       0     // unspecified
  142. #define AF_UNIX         1     // local to host (pipes, portals)
  143. #define AF_INET         2     // internetwork: UDP, TCP, etc.
  144. #define AF_IMPLINK      3     // arpanet imp addresses
  145. #define AF_PUP          4     // pup protocols: e.g. BSP
  146. #define AF_CHAOS        5     // mit CHAOS protocols
  147. #define AF_NS           6     // XEROX NS protocols
  148. #define AF_NBS          7     // nbs protocols
  149. #define AF_ECMA         8     // european computer manufacturers
  150. #define AF_DATAKIT      9     // datakit protocols
  151. #define AF_CCITT        10    // CCITT protocols, X.25 etc
  152. #define AF_SNA          11    // IBM SNA
  153. #define AF_DECnet       12    // DECnet
  154. #define AF_DLI          13    // Direct data link interface
  155. #define AF_LAT          14    // LAT
  156. #define AF_HYLINK       15    // NSC Hyperchannel
  157. #define AF_APPLETALK    16    // Apple Talk
  158. #define AF_NETBIO       17    // NetBIOS-style addresses
  159. #define AF_VOICEVIEW    18    // VoiceView
  160. #define AF_MAX          19
  161.  
  162. #define INVALID_SOCKET   (int)(~0)
  163. #define SOCKET_ERROR      (-1)
  164.  
  165. // Definitions related to sockets: types, address families, options.
  166.  
  167. // Types
  168.  
  169. #define SOCK_STREAM     1       // stream socket
  170. #define SOCK_DGRAM      2       // datagram socket
  171. #define SOCK_RAW        3       // raw-protocol interface
  172. #define SOCK_RDM        4       // reliably-delivered message
  173. #define SOCK_SEQPACKET  5       // sequenced packet stream
  174.  
  175. // Option flags per-socket.
  176.  
  177. #define SO_DEBUG        0x0001          // turn on debugging info recording
  178. #define SO_ACCEPTCONN   0x0002          // socket has had listen()
  179. #define SO_REUSEADDR    0x0004          // allow local address reuse
  180. #define SO_KEEPALIVE    0x0008          // keep connections alive
  181. #define SO_DONTROUTE    0x0010          // just use interface addresses
  182. #define SO_BROADCAST    0x0020          // permit sending of broadcast msgs
  183. #define SO_USELOOPBACK  0x0040          // bypass hardware when possible
  184. #define SO_LINGER       0x0080          // linger on close if data present
  185. #define SO_OOBINLINE    0x0100          // leave received OOB data in line
  186.  
  187. // Additional options, not kept in so_options.
  188.  
  189. #define SO_SNDBUF       0x1001          // send buffer size
  190. #define SO_RCVBUF       0x1002          // receive buffer size
  191. #define SO_SNDLOWAT     0x1003          // send low-water mark
  192. #define SO_RCVLOWAT     0x1004          // receive low-water mark
  193. #define SO_SNDTIMEO     0x1005          // send timeout
  194. #define SO_RCVTIMEO     0x1006          // receive timeout
  195. #define SO_ERROR        0x1007          // get error status and clear
  196. #define SO_TYPE         0x1008          // get socket type
  197.  
  198. // Structure used for manipulating linger option.
  199.  
  200. struct linger
  201. {
  202.  DTYP1  l_onoff;    // option on/off
  203.  DTYP1  l_linger;   // linger time
  204. };
  205.  
  206. // Level number for (get/set)sockopt() to apply to socket itself.
  207.  
  208. #define SOL_SOCKET  0xffff       // options for socket level
  209.  
  210. // Structure used by kernel to store most
  211. // addresses.
  212.  
  213. struct sockaddr
  214. {
  215.  USHORT  sa_family;              // address family
  216.  CHAR    sa_data[14];            // up to 14 bytes of direct address
  217. };
  218. typedef sockaddr* psockaddr;
  219.  
  220. // Structure used by kernel to pass protocol
  221. // information in raw sockets.
  222.  
  223. struct sockproto
  224. {
  225.  USHORT  sp_family;              // address family
  226.  USHORT  sp_protocol;            // protocol
  227. };
  228.  
  229. // Protocol families, same as address families for now.
  230.  
  231. #define PF_UNSPEC       AF_UNSPEC
  232. #define PF_UNIX         AF_UNIX
  233. #define PF_INET         AF_INET
  234. #define PF_IMPLINK      AF_IMPLINK
  235. #define PF_PUP          AF_PUP
  236. #define PF_CHAOS        AF_CHAOS
  237. #define PF_NS           AF_NS
  238. #define PF_NBS          AF_NBS
  239. #define PF_ECMA         AF_ECMA
  240. #define PF_DATAKIT      AF_DATAKIT
  241. #define PF_CCITT        AF_CCITT
  242. #define PF_SNA          AF_SNA
  243. #define PF_DECnet       AF_DECnet
  244. #define PF_DLI          AF_DLI
  245. #define PF_LAT          AF_LAT
  246. #define PF_HYLINK       AF_HYLINK
  247. #define PF_APPLETALK    AF_APPLETALK
  248. #define PF_MAX          AF_MAX
  249.  
  250. // Maximum queue length specifiable by listen.
  251.  
  252. #define SOMAXCONN       5
  253.  
  254. struct iovec
  255. {
  256.  PSZ   iov_base;
  257.  int     iov_len;
  258. };
  259. typedef iovec* piovec;
  260.  
  261. struct uio
  262. {
  263.  piovec   uio_iov;
  264.  int      uio_iovcnt;
  265.  off_t    uio_offset;
  266.  int      uio_segflg;
  267.  int      uio_resid;
  268. };
  269. typedef uio*   pio;
  270.  
  271. // Message header for recvmsg and sendmsg calls.
  272.  
  273. struct msghdr
  274. {
  275.  PSZ      msg_name;               // optional address
  276.  int      msg_namelen;            // size of address
  277.  piovec   msg_iov;                // scatter/gather array
  278.  int      msg_iovlen;             // # elements in msg_iov
  279.  PSZ      msg_accrights;          // access rights sent/received
  280.  int      msg_accrightslen;
  281. };
  282. typedef msghdr*   pmsghdr;
  283.  
  284. enum uio_rw
  285. {
  286.  UIO_READ,
  287.  UIO_WRITE
  288. };
  289.  
  290. #define FREAD  1
  291. #define FWRITE 2
  292.  
  293. #define MSG_OOB         0x1        // process out-of-band data
  294. #define MSG_PEEK        0x2        // peek at incoming message
  295. #define MSG_DONTROUTE   0x4        // send without using routing tables
  296. #define MSG_MAXIOVLEN   16
  297.  
  298. // Definition for bswap
  299.  
  300. #define htonl(x)     (lswap(x))
  301. #define ntohl(x)     (lswap(x))
  302. #define htons(x)     (bswap(x))
  303. #define ntohs(x)     (bswap(x))
  304. #define bzero(x,y)   memset((x),'\0',(y))
  305. #define bcopy(x,y,z) memcpy((y),(x),(z))
  306. #define bcmp(x,y,z)  memcmp((y),(x),(z))
  307.  
  308. //
  309.  
  310. #define IPPROTO_IP              0               // dummy for IP
  311. #define IPPROTO_ICMP            1               // control message protocol
  312. #define IPPROTO_GGP             3               // gateway^2 (deprecated)
  313. #define IPPROTO_TCP             6               // tcp
  314. #define IPPROTO_EGP             8               // exterior gateway protocol
  315. #define IPPROTO_PUP             12              // pup
  316. #define IPPROTO_UDP             17              // user datagram protocol
  317. #define IPPROTO_IDP             22              // xns idp
  318. #define IPPROTO_RAW             255             // raw IP packet
  319. #define IPPROTO_MAX             256
  320.  
  321.  
  322. // Ports < IPPORT_RESERVED are reserved for
  323. // privileged processes (e.g. root).
  324. // Ports > IPPORT_USERRESERVED are reserved
  325. // for servers, not necessarily privileged.
  326.  
  327. #define IPPORT_RESERVED         1024
  328. #define IPPORT_USERRESERVED     5000
  329.  
  330. // Link numbers
  331.  
  332. #define IMPLINK_IP              155
  333. #define IMPLINK_LOWEXPER        156
  334. #define IMPLINK_HIGHEXPER       158
  335.  
  336.  
  337. // TBO
  338. struct in_addr {
  339.         unsigned long s_addr;
  340. };
  341.  
  342.  
  343. // Definitions of bits in internet address integers.
  344. // On subnets, the decomposition of addresses to host and net parts
  345. // is done according to subnet mask, not the masks here.
  346.  
  347. #define IN_CLASSA(i)            (((long)(i) & 0x80000000L) == 0)
  348. #define IN_CLASSA_NET           0xff000000L
  349. #define IN_CLASSA_NSHIFT        24
  350. #define IN_CLASSA_HOST          0x00ffffffL
  351. #define IN_CLASSA_MAX           128
  352.  
  353. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000L) == 0x80000000L)
  354. #define IN_CLASSB_NET           0xffff0000L
  355. #define IN_CLASSB_NSHIFT        16
  356. #define IN_CLASSB_HOST          0x0000ffffL
  357. #define IN_CLASSB_MAX           65536L
  358.  
  359. #define IN_CLASSC(i)            (((long)(i) & 0xe0000000L) == 0xc0000000L)
  360. #define IN_CLASSC_NET           0xffffff00L
  361. #define IN_CLASSC_NSHIFT        8
  362. #define IN_CLASSC_HOST          0x000000ffL
  363.  
  364. #define IN_CLASSD(i)            (((long)(i) & 0xf0000000L) == 0xe0000000L)
  365. #define IN_MULTICAST(i)         IN_CLASSD(i)
  366.  
  367. #define IN_EXPERIMENTAL(i)      (((long)(i) & 0xe0000000L) == 0xe0000000L)
  368. #define IN_BADCLASS(i)          (((long)(i) & 0xf0000000L) == 0xf0000000L)
  369.  
  370. #define INADDR_ANY              (ULONG)0x00000000L
  371. #define INADDR_BROADCAST        (ULONG)0xffffffffL     // must be masked
  372. #ifndef KERNEL
  373. #define INADDR_NONE             0xffffffffL             // -1 return
  374. #endif
  375.  
  376. #define IN_LOOPBACKNET          127                     // official!
  377.  
  378.  
  379. struct sockaddr_in
  380. {
  381.  short    sin_family;
  382.  USHORT   sin_port;
  383.  in_addr  sin_addr;
  384.  char     sin_zero[8];
  385. };
  386. typedef sockaddr_in* psockaddr_in;
  387.  
  388. #define SOCADDR_BINDSIZE 16
  389.  
  390. // Options for use with [gs]etsockopt at the IP level.
  391.  
  392. #define IP_OPTIONS      1  // set/get IP per-packet options
  393.  
  394.  
  395. struct servent;
  396. typedef servent*  pservent;
  397.  
  398. #define _MAXALIASES     35
  399. #define _MAXADDRS       35
  400. #define _MAXLINELEN     1024
  401. #define _HOSTBUFSIZE    (BUFSIZ + 1)
  402.  
  403. // Structures returned by network
  404. // data base library.  All addresses
  405. // are supplied in host order, and
  406. // returned in network order (suitable
  407. // for use in system calls).
  408.  
  409. //typedef struct
  410. struct hostent
  411. {
  412.  PSZ                h_name;       // official name of host
  413.  PSZ*               h_aliases;    // alias list
  414.  DTYP1              h_addrtype;   // host address type
  415.  DTYP1              h_length;     // length of address
  416.  PSZ*               h_addr_list;  // list of addresses from name server
  417.  // TBO
  418. #define h_addr  h_addr_list[0]  /* address, for backward compatiblity */
  419. };// hostent, *phostend;
  420. typedef hostent * phostent;
  421.  
  422.  
  423. // Assumption here is that a network number
  424. // fits in 32 bits -- probably a poor one.
  425.  
  426. struct netent
  427. {
  428.  PSZ    n_name;       // official name of net
  429.  PSZ*   n_aliases;    // alias list
  430.  DTYP1  n_addrtype;   // net address type
  431.  ULONG  n_net;        // network #
  432. };
  433. typedef netent*  pnetent;
  434.  
  435. struct servent
  436. {
  437.  PSZ    s_name;       // official service name
  438.  PSZ*   s_aliases;    // alias list
  439.  DTYP1  s_port;       // port #
  440.  PSZ    s_proto;      // protocol to use
  441. };
  442. typedef servent*  pservent;
  443.  
  444. struct protoent
  445. {
  446.  PSZ    p_name;       // official protocol name
  447.  PSZ*   p_aliases;    // alias list
  448.  DTYP1  p_proto;      // protocol #
  449. };
  450. typedef protoent*  pprotoent;
  451.  
  452. // After a successful call to gethostbyname_r()/gethostbyaddr_r(), the
  453. // structure hostent_data will contain the data to which pointers in
  454. // the hostent structure will point to.
  455.  
  456. struct hostent_data
  457. {
  458.  in_addr     host_addr;                     // host address pointer
  459.  PSZ         h_addr_ptrs[_MAXADDRS + 1];    // host address
  460.  char        hostaddr[_MAXADDRS];
  461.  char        hostbuf[_HOSTBUFSIZE + 1];     // host data
  462.  PSZ         host_aliases[_MAXALIASES];
  463.  PSZ         host_addrs[2];
  464.  FILE*       hostf;
  465.  int         stayopen;                      // AIX addon
  466.  ULONG       host_addresses[_MAXADDRS];     // As per defect 48367.
  467. };                                          // Actual Addresses.
  468. typedef hostent_data*   phostent_data;
  469.  
  470. struct servent_data     // should be considered opaque
  471. {
  472.  FILE*       serv_fp;
  473.  char        line[_MAXLINELEN];
  474.  PSZ         serv_aliases[_MAXALIASES];
  475.  int         _serv_stayopen;
  476. };
  477. typedef servent_data*   pservent_data;
  478.  
  479.  
  480. // Error return codes from gethostbyname() and gethostbyaddr()
  481. // (left in extern int h_errno).
  482.  
  483. extern int h_errno;
  484.  
  485. #define HOST_NOT_FOUND  1          // Authoritative Answer Host not found
  486. #define TRY_AGAIN       2          // Non-Authoritive Host not found, or SERVERFAIL
  487. #define NO_RECOVERY     3          // Non recoverable errors, FORMERR, REFUSED, NOTIMP
  488. #define NO_DATA         4          // Valid name, no data record of requested type
  489. #define NO_ADDRESS      NO_DATA    // no address, look for MX record
  490.  
  491. #ifdef __cplusplus
  492.   extern "C" {
  493. #endif
  494.  
  495. ULONG     APIENTRY   inet_addr(const PSZ);
  496. int       APIENTRY   accept(int, psockaddr, PINT);
  497. int       APIENTRY   bind(int, psockaddr, int);
  498. int       APIENTRY   connect(int, psockaddr, int);
  499. int       APIENTRY   getpeername(int, psockaddr, PINT);
  500. int       APIENTRY   getsockname(int, psockaddr, PINT);
  501. int       APIENTRY   getsockopt(int, int, int, PSZ, PINT);
  502. int       APIENTRY   listen(int, int);
  503. int       APIENTRY   recv(int, PSZ, int, int);
  504. int       APIENTRY   recvfrom(int, PSZ, int, int, psockaddr, PINT);
  505. int       APIENTRY   send(int, PSZ, int, int);
  506. int       APIENTRY   sendto(int, PSZ, int, int, psockaddr, int);
  507. int       APIENTRY   shutdown(int, int);
  508. int       APIENTRY   socket(int, int, int);
  509. #ifndef BSD_SELECT
  510.   int     APIENTRY   select(PINT, int, int, int, long);
  511. #endif
  512. int       APIENTRY   gethostid();
  513. int       APIENTRY   recvmsg(int, pmsghdr, int);
  514. int       APIENTRY   sendmsg(int, pmsghdr, int);
  515. int       APIENTRY   setsockopt(int, int, int, PSZ, int);
  516. int       APIENTRY   sock_init();
  517. int       APIENTRY   sock_errno();
  518. int       APIENTRY   psock_errno(PSZ);
  519. int       APIENTRY   soclose(int);
  520. int       APIENTRY   soabort(int);
  521. int       APIENTRY   so_cancel(int);
  522. int       APIENTRY   readv(int, piovec, int);
  523. int       APIENTRY   writev(int, piovec, int);
  524. int       APIENTRY   getinetversion(PSZ);
  525. ULONG     APIENTRY   lswap(ULONG);
  526. USHORT    APIENTRY   bswap(USHORT);
  527. in_addr   APIENTRY   inet_makeaddr(ULONG, ULONG);
  528. ULONG     APIENTRY   inet_network(PSZ);
  529. PSZ       APIENTRY   inet_ntoa(in_addr);
  530. ULONG     APIENTRY   inet_lnaof(in_addr);
  531. ULONG     APIENTRY   inet_netof(in_addr);
  532. int       APIENTRY   gethostbyname_r(PSZ, phostent, phostent_data);
  533. int       APIENTRY   gethostbyaddr_r(PSZ, int, int, phostent, phostent_data);
  534. int       APIENTRY   getservbyname_r(PSZ, PSZ, pservent, pservent_data);
  535. int       APIENTRY   gethostname(PSZ, int );
  536. phostent  APIENTRY   gethostbyname(PSZ);
  537. phostent  APIENTRY   _gethtbyname(PSZ);
  538. phostent  APIENTRY   gethostbyaddr(PSZ, int, int);
  539. phostent  APIENTRY   _gethtbyaddr(PSZ, int, int);
  540. pnetent   APIENTRY   getnetbyname(PSZ);
  541. pnetent   APIENTRY   getnetbyaddr(ULONG, int);
  542. pservent  APIENTRY   getservbyname( PSZ, PSZ);
  543. pservent  APIENTRY   getservbyport( int, PSZ);
  544. pservent  APIENTRY   getservent();
  545. pprotoent APIENTRY   getprotobyname(PSZ);
  546. pprotoent APIENTRY   getprotobynumber(int);
  547. void      APIENTRY   sethostent(int);
  548. phostent  APIENTRY   gethostent();
  549. void      APIENTRY   endhostent();
  550. void      APIENTRY   setnetent(int);
  551. pnetent   APIENTRY   getnetent();
  552. void      APIENTRY   endnetent();
  553. void      APIENTRY   setprotoent(int);
  554. pprotoent APIENTRY   getprotoent();
  555. void      APIENTRY   endprotoent();
  556. void      APIENTRY   setservent(int);
  557. pservent  APIENTRY   getservent();
  558. void      APIENTRY   endservent();
  559.  
  560.  
  561. #ifdef __cplusplus
  562.   }
  563. #endif
  564.  
  565. // tbo
  566. #endif // #if defined( __IBMCPP__ )
  567.  
  568.  
  569. class _export_ XSocket : public XIO
  570. {
  571.         friend class XServerSocket;
  572.  
  573.         protected:
  574.                 struct sockaddr_in      name;
  575.                 struct sockaddr         client;
  576.                 struct hostent*         phost;
  577.  
  578.         public:
  579.                 // ctor/dtor
  580.                          XSocket( void );
  581.                 virtual ~XSocket();
  582.  
  583.                 void Open( int net = AF_INET, int typ = SOCK_STREAM, int y = 0 );
  584.                 void Close( void );
  585.  
  586.                 int  GetSocket( void )          { return handle; }
  587.                 void SetSocket( int sock )      { handle = sock; }
  588.  
  589.                        void     SetHostent( struct hostent* ph )        { phost = ph; }
  590.                 struct hostent* GetHostent( void )                      { return phost; }
  591.  
  592.                 XString GetHostname( void );
  593.                 void    GetHostByName( const char* hostname );
  594.                 void    GetHostByAddr( const char* hostname, int addrfam = AF_INET );
  595.  
  596.                 void SetInAddress( int addrfam = AF_INET );
  597.                 void SetInAddress( ULONG in_addr /*= INADDR_ANY*/, int addrfam = AF_INET );
  598.                 void SetInPort( int port );
  599.  
  600.                 ULONG _Read( void * buffer, const ULONG sizeofbuffer);
  601.                 ULONG _Write( const void * buffer, const ULONG sizeofbuffer) const;
  602. };
  603.  
  604.  
  605. class _export_ XClientSocket : public XSocket
  606. {
  607.         public:
  608.                 // ctor/dtor
  609.                          XClientSocket( void ) : XSocket() {}
  610.                 virtual ~XClientSocket() {}
  611.  
  612.                 void Connect( void );
  613. };
  614.  
  615.  
  616. class _export_ XServerSocket : public XSocket
  617. {
  618.         public:
  619.                 // ctor/dtor
  620.                          XServerSocket( void ) : XSocket() {}
  621.                 virtual ~XServerSocket() {}
  622.  
  623.                 void     Bind( void );
  624.                 void     Listen( int backlog = SOMAXCONN );
  625.                 XSocket* Accept( void );
  626. };
  627.  
  628. #endif
  629.