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

  1. /* PMSOCK.C--PM Sockets interface to IBM TCP/IP
  2.  *
  3.  * This 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.  * Fri Sept 2 1994 Don Loflin
  15.  *      Changing to be less direct
  16.  * Sun Aug 21 1994 Don Loflin
  17.  *    Redid to use IBM TCP routines directly
  18.  * Fri Aug 11 1994 Don Loflin (loflin@mail.utexas.edu)
  19.  *     Created PMSOCK.C from PMSOCK.H
  20.  * Mon Aug 8 1994  Don Loflin (loflin@mail.utexas.edu)
  21.  *    Created PMSOCK.H from WINSOCK.H
  22.  */
  23.  
  24. #include "pmsock.h"
  25.  
  26. /* IBM routines used here, from tcpip/include/sys/socket.h */
  27. extern int soclose( int );
  28. extern int sock_errno( void );
  29. extern int ioctl(int, int, char *, int);
  30.  
  31. #if 0
  32. int __WSAFDIsSet(SOCKET fd, fd_set *set)
  33. {
  34.   int i = set->fd_count;
  35.  
  36.    while (i--)
  37.        if (set->fd_array[i] == fd)
  38.            return 1;
  39.  
  40.    return 0;
  41.  
  42. }
  43.  
  44. #endif
  45. /* Socket functions - IBM compat. routines are commented out */
  46. #undef IBMSOCK
  47.  
  48. #ifdef IBMSOCK
  49. SOCKET accept (SOCKET s, struct sockaddr *addr, 
  50.                           int *addrlen);
  51.  
  52. int bind (SOCKET s, const struct sockaddr *addr, int namelen);
  53. #endif
  54.  
  55. int closesocket (SOCKET s)
  56. {
  57. /*   return (soclose(s)); */
  58. }
  59.  
  60. #ifdef IBMSOCK
  61. int connect (SOCKET s, const struct sockaddr *name, int namelen);
  62. #endif
  63. int ioctlsocket (SOCKET s, long cmd, u_long *argp)
  64. {
  65.    /* WinSock ioctlsocket only allows param to be u_long, so just pass that */
  66.    /*size to IBM ioctl */
  67.   /* return(ioctl(s, cmd, (char *) argp, sizeof(u_long)) );*/
  68. }
  69.  
  70. #ifdef IBMSOCK
  71. int getpeername (SOCKET s, struct sockaddr *name,
  72.                             int * namelen);
  73.  
  74. int getsockname (SOCKET s, struct sockaddr *name,
  75.                             int * namelen);
  76.  
  77. int getsockopt (SOCKET s, int level, int optname,
  78.                            char *optval, int *optlen);
  79.  
  80. u_long PASCAL FAR htonl (u_long hostlong);
  81.  
  82. u_short PASCAL FAR htons (u_short hostshort);
  83.  
  84. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  85.  
  86. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  87.  
  88. int PASCAL FAR listen (SOCKET s, int backlog);
  89.  
  90. u_long PASCAL FAR ntohl (u_long netlong);
  91.  
  92. u_short PASCAL FAR ntohs (u_short netshort);
  93.  
  94. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  95.  
  96. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  97.                          struct sockaddr FAR *from, int FAR * fromlen);
  98.  
  99. #endif
  100. #ifndef USEIBMSELECT
  101. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  102.                        fd_set FAR *exceptfds, const struct timeval FAR *timeout) 
  103. {
  104. // put pmsock fd_set's into ibm fd_set's, then  
  105. #endif
  106. #ifdef IBMSOCK
  107. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  108.  
  109. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  110.                        const struct sockaddr FAR *to, int tolen);
  111.  
  112. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  113.                            const char FAR * optval, int optlen);
  114.  
  115. int PASCAL FAR shutdown (SOCKET s, int how);
  116.  
  117. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  118.  
  119. /* Database function prototypes */
  120.  
  121. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  122.                                               int len, int type);
  123.  
  124. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  125.  
  126. int PASCAL FAR gethostname (char FAR * name, int namelen);
  127.  
  128. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  129.  
  130. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  131.                                               const char FAR * proto);
  132.  
  133. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  134.  
  135. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  136.  
  137. #endif /* IBMSOCK */
  138. /* Microsoft Windows Extension function prototypes */
  139.  
  140. int WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData)
  141. {
  142.    return(sock_init());
  143. }
  144.  
  145.  
  146. int WSACleanup(void)
  147. {
  148. /* null - IBM TCP doesn't require anything */
  149. }
  150.  
  151. void WSASetLastError(int iError)
  152. {
  153. /* not allowed */
  154. }
  155.  
  156. int WSAGetLastError(void)
  157. {
  158. /*   return (sock_errno()); */
  159. }
  160.  
  161. /*
  162.  * Aync calls optional
  163.  */
  164. #undef PMSAAsync
  165. #ifdef PMSAAsync 
  166.  
  167. BOOL PASCAL FAR WSAIsBlocking(void);
  168.  
  169. int PASCAL FAR WSAUnhookBlockingHook(void);
  170.  
  171. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  172.  
  173. int PASCAL FAR WSACancelBlockingCall(void);
  174.  
  175. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  176.                                         const char FAR * name, 
  177.                                         const char FAR * proto,
  178.                                         char FAR * buf, int buflen);
  179.  
  180. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  181.                                         const char FAR * proto, char FAR * buf,
  182.                                         int buflen);
  183.  
  184. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  185.                                          const char FAR * name, char FAR * buf,
  186.                                          int buflen);
  187.  
  188. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  189.                                            int number, char FAR * buf,
  190.                                            int buflen);
  191.  
  192. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  193.                                         const char FAR * name, char FAR * buf,
  194.                                         int buflen);
  195.  
  196. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  197.                                         const char FAR * addr, int len, int type,
  198.                                         char FAR * buf, int buflen);
  199.  
  200. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  201.  
  202. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  203.                                long lEvent);
  204.  
  205. #endif /* PMSAAsync */
  206.  
  207.  
  208.