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