home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dax1.exe / CP / CPC / CPINIT.C < prev    next >
Text File  |  1992-07-15  |  5KB  |  113 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      cpinit.c                                              ║
  4. //   ║ abstract:    This module initializes the CP Layer.                 ║
  5. //   ║                                                                    ║
  6. //   ║ environment: NetWare 3.x v3.11                                     ║
  7. //   ║              Network C for NLMs SDK v2.0d                          ║
  8. //   ║              CLib v3.11                                            ║
  9. //   ║              Network C for DOS v2.0                                ║
  10. //   ║              NetWare C Interface DOS v1.2                          ║
  11. //   ║                                                                    ║
  12. //   ║  This software is provided as is and carries no warranty           ║
  13. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  14. //   ║  warranties of merchantability, title and fitness for a particular ║
  15. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  16. //   ║  your requirements or that the software is without defect or error ║
  17. //   ║  or that operation of the software will be uninterrupted.  You are ║
  18. //   ║  using the software at your risk.  The software is not a product   ║
  19. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  20. //   ║                                                                    ║
  21. //   ╟────────────────────────────────────────────────────────────────────╢
  22. //   ║ maintenance history:                                               ║
  23. //   ║ level    date      pi   description                                ║
  24. //   ╟────────────────────────────────────────────────────────────────────╢
  25. //   ║  001   01/24/92    kl   initial release.                           ║
  26. //   ║  002   07/14/92    kl   windows port.                              ║
  27. //   ╚════════════════════════════════════════════════════════════════════╝
  28.  
  29. #include <string.h>
  30. #include <errno.h>
  31. #include <malloc.h>
  32. #include "cp/cpsys.h"
  33.  
  34. #if defined(WINCLIENT)
  35.     DWORD   _TASKID;            // used by all IPX calls
  36. #endif
  37.  
  38. CPDATA  *CPInitialize(char *name, UINT16 type)
  39. {
  40.     #if !defined(DYNAMICMEM)
  41.         static  CPDATA  __cpd;
  42.         CPDATA  *CPid = &__cpd;
  43.     #else
  44.         CPDATA  *CPid;
  45.     #endif
  46.         char    value[128],dummy;
  47.         //
  48.         //  Get the C Interface ready to make IPX calls
  49.         //
  50.         if( IPXInitialize() )                               goto error0;
  51.     #if defined(DYNAMICMEM)
  52.         //
  53.         //  Allocate memory for __cpd
  54.         //
  55.         if((CPid = (CPDATA *)calloc(1,sizeof *CPid))==NULL) goto error0;
  56.     #endif
  57.         //
  58.         //  Open a socket for our local application to listen on
  59.         //
  60.         if( IPXOpenSocket((BYTE *)&CPid->skt,SHORT_LIVED) ) goto error0;
  61.         //
  62.         //  Get the address of the application server by reading the
  63.         //  NET_ADDRESS property of that server from the bindery.
  64.         //
  65.         if( ReadPropertyValue(name,type,"NET_ADDRESS",1,value,&dummy,&dummy) )
  66.             return NULL;
  67.         //
  68.         //  Save the server's address.
  69.         //  Put the signature on the CP Layer packet header.  This signature
  70.         //  is used to authenticate the packets on both sides.
  71.         //
  72.         CPid->ipxaddr = *(IPXAddress *)value;
  73.         CPid->cphdr.signature = CPPKTSIG;
  74.         //
  75.         //  Get the Send Logic ready to xfer messages to the server
  76.         //
  77.         if( CPInitializeSendLogic(CPid) )                   goto error1;
  78.         //
  79.         //  Get ready to receive messages from the server.
  80.         //
  81.         if( CPInitializeRecvLogic(CPid) )                   goto error1;
  82.         //
  83.         //  Do whatever prep is needed to establish connections.
  84.         //
  85.         if( CPInitializeConnLogic(CPid) )                   goto error1;
  86.         //
  87.         //  Okay, we're ready.  Return structure pointer for use on
  88.         //  subsequent API requests to the CP layer.
  89.         //
  90.         return CPid;
  91. error0:
  92.         return NULL;
  93. error1:
  94.         CPDeInitialize(CPid);
  95.         goto error0;
  96. }
  97.  
  98. void    CPDeInitialize(CPDATA *CPid)
  99. {
  100.         if( CPid ){
  101.             if( CPid->skt ) IPXCloseSocket(CPid->skt);
  102.             CPDeInitializeRecvLogic(CPid);
  103.             CPDeInitializeSendLogic(CPid);
  104.             CPDeInitializeConnLogic(CPid);
  105.             memset(CPid,NULL,sizeof *CPid);
  106.             IPXDeInitialize();
  107.     #if defined(DYNAMICMEM)
  108.             free(CPid);
  109.     #endif
  110.         }
  111. }
  112. 
  113.