home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / PPP Interfaces 1.2 / PPP Libraries / source / ppp.interface.c < prev    next >
Encoding:
Text File  |  1996-01-03  |  3.9 KB  |  171 lines  |  [TEXT/CWIE]

  1. // Interface routines for MacPPP
  2. // © 1994-95 Richard Buckle <richardb@cocytus.demon.co.uk>
  3.  
  4. // Release 1.2 for CodeWarrior 7
  5.  
  6. // headers
  7. #include <ppp.interface.h> // our public interface
  8.  
  9. // Open Transport -- I don't have the header file from the MacOS SDK
  10. #define gestaltOpenTpt 'otan'
  11. enum
  12.     {
  13.     gestaltOpenTptPresent          = 0x00000001,
  14.     gestaltOpenTptLoaded           = 0x00000002,
  15.     gestaltOpenTptAppleTalkPresent = 0x00000004,
  16.     gestaltOpenTptAppleTalkLoaded  = 0x00000008,
  17.     gestaltOpenTptTCPPresent       = 0x00000010,
  18.     gestaltOpenTptTCPLoaded        = 0x00000020,
  19.     gestaltOpenTptNetwarePresent   = 0x00000040,
  20.     gestaltOpenTptNetwareLoaded    = 0x00000080
  21.     };
  22.  
  23.  
  24. // private constants
  25. #define ipctlGetAddr        15                            // csCode to get our IP address
  26. #define gestaltPPPGlobals    'PPP '                        // gestalt selector code for MacPPP
  27. #define kIPPDriverName        (unsigned char *)"\p.IPP"    // MacPPP driver name
  28. #define    kSDprohibitOpenBit    0x02                        // PROVISIONAL for FreePPP: 
  29.                                                         // Clear this bit in lap->prefdata.quiet
  30.                                                         // to override the autoconnect bar.
  31.                                                         // It doesn't interfere with other MacPPPs (yet)
  32.  
  33.  
  34. // functions
  35.  
  36. // Return TRUE if PPP is installed
  37. Boolean PPPisInstalled( void )
  38.     {
  39.     LapInfo        *lap;
  40.     
  41.     return ( Gestalt(gestaltPPPGlobals, (long *)&lap) == noErr );
  42.     }
  43.  
  44.  
  45. // Return TRUE if PPP is installed and open
  46. Boolean PPPisOpen( void )
  47.     {
  48.     LapInfo        *lap;
  49.     Boolean     result = FALSE;
  50.     
  51.     if( Gestalt( gestaltPPPGlobals, (long *)&lap) == noErr ) 
  52.         {
  53.         if( lap != NULL ) 
  54.             {
  55.               if( lap->ppp_fsm[IPcp].state == fsmOPENED ) 
  56.                 {
  57.                 result = TRUE; // PPP is open
  58.                 } 
  59.             }
  60.         }
  61.     
  62.     return result;
  63.     }
  64.  
  65.  
  66. // Open PPP if it's installed
  67. void OpenPPP( void )
  68.     {
  69.     LapInfo        *lap;
  70.     short        type;
  71.  
  72.     if( Gestalt( gestaltPPPGlobals, (long *)&lap) == noErr) 
  73.         {
  74.         if (lap && (lap->ppp_fsm[IPcp].state != fsmOPENED) ) 
  75.             {
  76.             unsigned char    oldQuietField;
  77.             
  78.             // remember quiet field and clear bit 1
  79.             // (for compatibility with FreePPP)
  80.             oldQuietField = lap->prefdata.quiet;
  81.             lap->prefdata.quiet &= ~kSDprohibitOpenBit;
  82.             
  83.             if( UsingOpenTransport() )
  84.                 {
  85.                 (*lap->lapOpen)(lap);
  86.                 
  87.                 if ( lap->transProc != nil )
  88.                     (*(lap->transProc))(TransitionOpen);
  89.                 }
  90.             else
  91.                 {
  92.                 if( lap->transProc == nil )
  93.                     {
  94.                     if (noErr == OpenDriver( kIPPDriverName, &type)) 
  95.                         {
  96.                         // open TCP
  97.                         CntrlParam tiopb;
  98.                         bzero((b_8 *)&tiopb, sizeof(tiopb));
  99.                         tiopb.ioCRefNum = type;
  100.                         tiopb.csCode = ipctlGetAddr;
  101.                         tiopb.ioCompletion = NULL;
  102.                         PBControlSync( (ParamBlockRec *)&tiopb );
  103.                         }
  104.                     } 
  105.                 else
  106.                     (*(lap->transProc))(TransitionOpen);
  107.                 }
  108.             
  109.             }
  110.         }
  111.     }
  112.  
  113.  
  114. // Hard close PPP if it's installed
  115. // (hard close is usually preferable)
  116. void ClosePPPHard( void )
  117.     {
  118.     volatile LapInfo        *lap;
  119.     
  120.     if( Gestalt(gestaltPPPGlobals, (long *)&lap) == noErr ) 
  121.         {
  122.         if( lap && lap->lapClose && (lap->ppp_fsm[IPcp].state == fsmOPENED) ) 
  123.             {
  124.             // no need to test lap->transProc here (I guess)
  125.             
  126.             (*(lap->lapClose))(lap);    /* close PPP */
  127.             }
  128.         }
  129.     }
  130.  
  131. // Soft close PPP if it's installed
  132. // This allows PPP to redial without the user's permission
  133. // If you use it, explain this in your documentation or
  134. // you'll get lots of bug reports :-)
  135. void ClosePPPSoft( void )
  136.     {
  137.     LapInfo        *lap;
  138.     
  139.     if( Gestalt(gestaltPPPGlobals, (long *)&lap) == noErr ) 
  140.         {
  141.         if( lap && lap->lapClose && (lap->ppp_fsm[IPcp].state == fsmOPENED) ) 
  142.             {
  143.             (*(lap->lapClose))(lap);    /* close PPP */
  144.             lap->ppp_flags |= CLOSE_PPP;
  145.             if( UsingOpenTransport() )
  146.                 {
  147.                 ( *(lap->lapInit) )( lap, lap->transProc );
  148.                 }
  149.             else
  150.                 {
  151.                 if( lap->transProc )
  152.                     (*(lap->transProc))(TransitionOpen);
  153.                 }
  154.             }
  155.         }
  156.     }
  157.  
  158. // Return TRUE if the machine is using Open Transport rather than MacTCP.
  159. Boolean UsingOpenTransport( void )
  160.     {
  161.     Boolean    result = FALSE;
  162.     long    gestaltResult;
  163.     
  164.     if( Gestalt(gestaltOpenTpt, &gestaltResult) == noErr )
  165.         // OT is around, see whether OT TCP is around too
  166.         result = (gestaltResult & gestaltOpenTptTCPPresent);
  167.     
  168.     return result;
  169.     }
  170.  
  171.