home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / INTERNET / UPC2S1.ZIP / PWINSOCK.C < prev    next >
C/C++ Source or Header  |  1993-09-26  |  8KB  |  204 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       p w i n s o c k . c                                          */
  3. /*                                                                    */
  4. /*       WinSock support for Windows 3.1                              */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Copyright (c) David M. Watt 1993, All Right Reserved            */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  13. /*    Wonderworks.                                                    */
  14. /*                                                                    */
  15. /*    All rights reserved except those explicitly granted by the      */
  16. /*    UUPC/extended license agreement.                                */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*--------------------------------------------------------------------*/
  20. /*                          RCS Information                           */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. /*
  24.  *    $Id: pwinsock.c 1.2 1993/09/27 00:45:20 ahd Exp $
  25.  *
  26.  *    $Log: pwinsock.c $
  27.  * Revision 1.2  1993/09/27  00:45:20  ahd
  28.  * Add missing def for shutdown()
  29.  *
  30.  * Revision 1.1  1993/09/20  04:39:51  ahd
  31.  * Initial revision
  32.  *
  33.  */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*                        System include files                        */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include <stdio.h>
  40. #include <windows.h>
  41. #include "winsock.h"
  42.  
  43. /*--------------------------------------------------------------------*/
  44. /*                    UUPC/extended include files                     */
  45. /*--------------------------------------------------------------------*/
  46.  
  47. #include "lib.h"
  48. #include "pwinsock.h"      // definitions for 16 bit Winsock functions
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*                  Define pointers to the functions                  */
  52. /*--------------------------------------------------------------------*/
  53.  
  54. int PASCAL FAR (*pWSAStartup)(WORD wVersionRequired, LPWSADATA lpWSAData);
  55.  
  56. int PASCAL FAR (*pWSACleanup)(void);
  57.  
  58. int PASCAL FAR (*pWSAGetLastError)(void);
  59.  
  60. BOOL PASCAL FAR (*pWSAIsBlocking)(void);
  61.  
  62. int PASCAL FAR (*pWSACancelBlockingCall)(void);
  63.  
  64. struct hostent FAR * PASCAL FAR (*pgethostbyname)(const char FAR * name);
  65.  
  66. struct servent FAR * PASCAL FAR (*pgetservbyname)(const char FAR * name,
  67.                                                   const char FAR * proto);
  68.  
  69. unsigned long PASCAL FAR (*pinet_addr)(const char FAR * cp);
  70.  
  71. SOCKET PASCAL FAR (*psocket)(int af,
  72.                              int type,
  73.                              int protocol);
  74.  
  75. int PASCAL FAR (*pconnect)(SOCKET s,
  76.                            const struct sockaddr FAR *name,
  77.                            int namelen);
  78.  
  79. SOCKET PASCAL FAR (*paccept)(SOCKET s,
  80.                              struct sockaddr FAR *addr,
  81.                              int FAR *addrlen);
  82.  
  83. int PASCAL FAR (*plisten) (SOCKET s, int backlog);
  84.  
  85. int PASCAL FAR (*bind)(SOCKET s,
  86.                        const struct sockaddr FAR *addr,
  87.                        int namelen);
  88.  
  89. int PASCAL FAR (*pselect)(int nfds,
  90.                           fd_set FAR *readfds,
  91.                           fd_set FAR *writefds,
  92.                           fd_set FAR *exceptfds,
  93.                           const struct timeval FAR *timeout);
  94.  
  95. int PASCAL FAR (*psend)(SOCKET s,
  96.                         const char FAR * buf,
  97.                         int len,
  98.                         int flags);
  99.  
  100. int PASCAL FAR (*precv) (SOCKET s,
  101.                          char FAR * buf,
  102.                          int len,
  103.                          int flags);
  104.  
  105. int PASCAL FAR (*pclosesocket)(SOCKET s);
  106.  
  107. u_short PASCAL FAR (*pntohs)(u_short netshort);
  108.  
  109. u_long PASCAL FAR (*phtonl) (u_long hostlong);
  110.  
  111. u_long PASCAL FAR (*pntohl) (u_long netlong);
  112.  
  113. int PASCAL FAR (*pshutdown) (SOCKET s, int how);
  114.  
  115. /*--------------------------------------------------------------------*/
  116. /*                          Local variables                           */
  117. /*--------------------------------------------------------------------*/
  118.  
  119. static HINSTANCE hWinsock = NULL;
  120.  
  121. currentfile();
  122.  
  123. /*--------------------------------------------------------------------*/
  124. /*       p W i n S o c k I n i t                                      */
  125. /*                                                                    */
  126. /*       Initialize winsock.dll for Windows 3.1                       */
  127. /*--------------------------------------------------------------------*/
  128.  
  129. boolean pWinSockInit( void )
  130. {
  131.  
  132. /*--------------------------------------------------------------------*/
  133. /*                          Load the library                          */
  134. /*--------------------------------------------------------------------*/
  135.  
  136.    if (!hWinsock)
  137.       hWinsock = LoadLibrary("WINSOCK.DLL");
  138.    else {
  139.       printmsg(0,"pWinSockInit: called twice with no termination");
  140.       panic();
  141.    }
  142.  
  143.  
  144.    if (!hWinsock)
  145.    {
  146.       printmsg(0, "pWinSockInit: could not find Winsock.DLL");
  147.       return FALSE;
  148.    }
  149.  
  150. /*--------------------------------------------------------------------*/
  151. /*       Initialize pointers to functions with in the libraries       */
  152. /*--------------------------------------------------------------------*/
  153.  
  154. #ifdef __TURBOC__
  155. #pragma warn -sus
  156. #endif
  157.  
  158.    paccept                = GetProcAddress(hWinsock, (LPSTR)MAKELONG(  1,0));
  159.    pbind                  = GetProcAddress(hWinsock, (LPSTR)MAKELONG(  2,0));
  160.    pclosesocket           = GetProcAddress(hWinsock, (LPSTR)MAKELONG(  3,0));
  161.    pconnect               = GetProcAddress(hWinsock, (LPSTR)MAKELONG(  4,0));
  162.    phtonl                 = GetProcAddress(hWinsock, (LPSTR)MAKELONG(  8,0));
  163.    pinet_addr             = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 10,0));
  164.    plisten                = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 13,0));
  165.    pntohl                 = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 14,0));
  166.    pntohs                 = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 15,0));
  167.    precv                  = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 16,0));
  168.    pselect                = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 18,0));
  169.    psend                  = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 19,0));
  170.    pshutdown              = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 22,0));
  171.    psocket                = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 23,0));
  172.    pgethostbyname         = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 52,0));
  173.    pgetservbyname         = GetProcAddress(hWinsock, (LPSTR)MAKELONG( 55,0));
  174.    pWSAGetLastError       = GetProcAddress(hWinsock, (LPSTR)MAKELONG(111,0));
  175.    pWSACancelBlockingCall = GetProcAddress(hWinsock, (LPSTR)MAKELONG(113,0));
  176.    pWSAIsBlocking         = GetProcAddress(hWinsock, (LPSTR)MAKELONG(114,0));
  177.    pWSAStartup            = GetProcAddress(hWinsock, (LPSTR)MAKELONG(115,0));
  178.    pWSACleanup            = GetProcAddress(hWinsock, (LPSTR)MAKELONG(116,0));
  179.  
  180. #ifdef __TURBOC__
  181. #pragma warn .sus
  182. #endif
  183.  
  184.    return TRUE;
  185.  
  186. } /* pWinSockInit */
  187.  
  188. /*--------------------------------------------------------------------*/
  189. /*       p W i n S o c k E x i t                                      */
  190. /*                                                                    */
  191. /*       Clean up Windows 3.x winsock.dll                             */
  192. /*--------------------------------------------------------------------*/
  193.  
  194. void pWinSockExit( void )
  195. {
  196.  
  197.    if (hWinsock)
  198.    {
  199.       FreeLibrary(hWinsock);
  200.       hWinsock = (HINSTANCE) NULL;
  201.    }
  202.  
  203. } /* pWinSockExit */
  204.