home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-03 | 3.9 KB | 171 lines | [TEXT/CWIE] |
- // Interface routines for MacPPP
- // © 1994-95 Richard Buckle <richardb@cocytus.demon.co.uk>
-
- // Release 1.2 for CodeWarrior 7
-
- // headers
- #include <ppp.interface.h> // our public interface
-
- // Open Transport -- I don't have the header file from the MacOS SDK
- #define gestaltOpenTpt 'otan'
- enum
- {
- gestaltOpenTptPresent = 0x00000001,
- gestaltOpenTptLoaded = 0x00000002,
- gestaltOpenTptAppleTalkPresent = 0x00000004,
- gestaltOpenTptAppleTalkLoaded = 0x00000008,
- gestaltOpenTptTCPPresent = 0x00000010,
- gestaltOpenTptTCPLoaded = 0x00000020,
- gestaltOpenTptNetwarePresent = 0x00000040,
- gestaltOpenTptNetwareLoaded = 0x00000080
- };
-
-
- // private constants
- #define ipctlGetAddr 15 // csCode to get our IP address
- #define gestaltPPPGlobals 'PPP ' // gestalt selector code for MacPPP
- #define kIPPDriverName (unsigned char *)"\p.IPP" // MacPPP driver name
- #define kSDprohibitOpenBit 0x02 // PROVISIONAL for FreePPP:
- // Clear this bit in lap->prefdata.quiet
- // to override the autoconnect bar.
- // It doesn't interfere with other MacPPPs (yet)
-
-
- // functions
-
- // Return TRUE if PPP is installed
- Boolean PPPisInstalled( void )
- {
- LapInfo *lap;
-
- return ( Gestalt(gestaltPPPGlobals, (long *)&lap) == noErr );
- }
-
-
- // Return TRUE if PPP is installed and open
- Boolean PPPisOpen( void )
- {
- LapInfo *lap;
- Boolean result = FALSE;
-
- if( Gestalt( gestaltPPPGlobals, (long *)&lap) == noErr )
- {
- if( lap != NULL )
- {
- if( lap->ppp_fsm[IPcp].state == fsmOPENED )
- {
- result = TRUE; // PPP is open
- }
- }
- }
-
- return result;
- }
-
-
- // Open PPP if it's installed
- void OpenPPP( void )
- {
- LapInfo *lap;
- short type;
-
- if( Gestalt( gestaltPPPGlobals, (long *)&lap) == noErr)
- {
- if (lap && (lap->ppp_fsm[IPcp].state != fsmOPENED) )
- {
- unsigned char oldQuietField;
-
- // remember quiet field and clear bit 1
- // (for compatibility with FreePPP)
- oldQuietField = lap->prefdata.quiet;
- lap->prefdata.quiet &= ~kSDprohibitOpenBit;
-
- if( UsingOpenTransport() )
- {
- (*lap->lapOpen)(lap);
-
- if ( lap->transProc != nil )
- (*(lap->transProc))(TransitionOpen);
- }
- else
- {
- if( lap->transProc == nil )
- {
- if (noErr == OpenDriver( kIPPDriverName, &type))
- {
- // open TCP
- CntrlParam tiopb;
- bzero((b_8 *)&tiopb, sizeof(tiopb));
- tiopb.ioCRefNum = type;
- tiopb.csCode = ipctlGetAddr;
- tiopb.ioCompletion = NULL;
- PBControlSync( (ParamBlockRec *)&tiopb );
- }
- }
- else
- (*(lap->transProc))(TransitionOpen);
- }
-
- }
- }
- }
-
-
- // Hard close PPP if it's installed
- // (hard close is usually preferable)
- void ClosePPPHard( void )
- {
- volatile LapInfo *lap;
-
- if( Gestalt(gestaltPPPGlobals, (long *)&lap) == noErr )
- {
- if( lap && lap->lapClose && (lap->ppp_fsm[IPcp].state == fsmOPENED) )
- {
- // no need to test lap->transProc here (I guess)
-
- (*(lap->lapClose))(lap); /* close PPP */
- }
- }
- }
-
- // Soft close PPP if it's installed
- // This allows PPP to redial without the user's permission
- // If you use it, explain this in your documentation or
- // you'll get lots of bug reports :-)
- void ClosePPPSoft( void )
- {
- LapInfo *lap;
-
- if( Gestalt(gestaltPPPGlobals, (long *)&lap) == noErr )
- {
- if( lap && lap->lapClose && (lap->ppp_fsm[IPcp].state == fsmOPENED) )
- {
- (*(lap->lapClose))(lap); /* close PPP */
- lap->ppp_flags |= CLOSE_PPP;
- if( UsingOpenTransport() )
- {
- ( *(lap->lapInit) )( lap, lap->transProc );
- }
- else
- {
- if( lap->transProc )
- (*(lap->transProc))(TransitionOpen);
- }
- }
- }
- }
-
- // Return TRUE if the machine is using Open Transport rather than MacTCP.
- Boolean UsingOpenTransport( void )
- {
- Boolean result = FALSE;
- long gestaltResult;
-
- if( Gestalt(gestaltOpenTpt, &gestaltResult) == noErr )
- // OT is around, see whether OT TCP is around too
- result = (gestaltResult & gestaltOpenTptTCPPresent);
-
- return result;
- }
-
-