Re: PPP
Re: PPP
- Subject: Re: PPP
- From: Jens Bauer <email@hidden>
- Date: Mon, 19 Aug 2002 21:36:24 +0200
Hi Todd,
On Mon, 19 Aug, 2002, Todd Casey <email@hidden> wrote:
>
I need to dial-up a PPP connection inside my C/C++ application on Mac OS. Is
>
this possible? I am a newbie to Mac programming and need to be pointed in
>
the right direction. Do I use the Open Transport SDK?
Indeed, this is possible.
I understand that you want to do this under Mac OS 9 and below, not Mac
OS X, am I correct ?
If so, you should use Open Transport, yes.
You have another option, which I didn't choose myself, so I cannot help
you if you want to take that path; it's about using AppleEvents.
But if you want to use Open Transport, you should create an asynchronous
endpoint, install a notifier.
Inside this notifier, you should catch some PPP events, here's a small
piece of code, that you can use for reference:
(Note: some of these constants are not defined by Apple, I made them up
myself, for instance kConnected, kDialing, kIdle, etc...)
---8<-----8<-----8<-----
static pascal void Notifier(void *context, OTEventCode event, OTResult
result, void *cookie)
{
#pragma unused(result)
EndpointRef ep;
int errorCode;
errorCode = (int) cookie;
ep = (EndpointRef) context;
switch(event)
{
case kPPPConnectCompleteEvent:
switch(errorCode)
{
case 0:
SetStatus(kConnected);
break;
case 1:
SetStatus(kDialing);
break;
case -6020: // No Dialtone
SetStatus(kIdle);
break;
case -6019: // Timeout (no answer, voice answer, illegal
phone#, busy, etc.)
SetStatus(kIdle);
break;
case -7114: // Modem in use
SetStatus(kIdle);
break;
case -7129: // Authentication failed
SetStatus(kIdle);
break;
case -7136: // Connection refused (Eg. can happen if TCP/IP
is set to use DHCP)
SetStatus(kIdle);
break;
default: // Save error code for debugging
gRealErrorCode = errorCode;
break;
}
break;
case kPPPSetScriptCompleteEvent:
// don't know if we get this
break;
case kPPPDisconnectCompleteEvent:
switch(errorCode)
{
case 0:
// SetStatus(kDisconnected);
SetStatus(kIdle);
break;
case 1:
SetStatus(kDisconnecting);
break;
default:
gRealErrorCode = errorCode;
break;
}
break;
// Here follows a bunch of events that I don't handle...
case kPPPDisconnectEvent:
break;
case kPPPIPCPUpEvent:
break;
case kPPPIPCPDownEvent:
break;
case kPPPLCPUpEvent:
break;
case kPPPLCPDownEvent:
break;
case kPPPLowerLayerUpEvent:
break;
case kPPPLowerLayerDownEvent:
break;
case kPPPAuthenticationStartedEvent:
break;
case kPPPAuthenticationFinishedEvent:
break;
case kPPPDCEInitStartedEvent:
break;
case kPPPDCEInitFinishedEvent:
break;
case kPPPDCECallStartedEvent:
// We get this, when dialing, cookie seem to always be 0.
break;
case kPPPDCECallFinishedEvent:
// We get this.
// if there's no modem, cookie is set to -6020
switch(errorCode)
{
case -6020:
SetLastError(kNoDialTone);
break;
case -6019:
SetLastError(kTimeout);
break;
default:
gRealErrorCode = errorCode;
SetLastError(kUnknownError);
break;
}
break;
case kStreamIoctlEvent:
switch((int) cookie)
{
case I_OTGetMiscellaneousEvents:
// we get this
break;
case I_OTConnect:
// we get this too
break;
default:
break;
}
break;
default:
break;
}
}
--->8----->8----->8-----
Here's a snippet creating the endpoint:
---8<-----8<-----8<-----
#include <stdio.h>
#include <OpenTransport.h>
#include <OpenTransportProviders.h> /* note: instead of <OpenTptPPP.h> */
#include <Dialogs.h>
#ifndef _MWERKS_
QDGlobals qd;
#endif
static pascal void Notifier(void *context, OTEventCode event, OTResult
result, void *cookie)
{
/* output the event, result and cookie values here (you might get away
with using printf, I did, but it's definately not a good practise!) */
}
void Start()
{
OSStatus err;
EndpointRef ep;
OTNotifyUPP notifier;
err = InitOpenTransport();
{
notifier = NewOTNotifyUPP(Notifier);
ep = OTOpenEndpoint(OTCreateConfiguration(kPPPControlName), 0, NULL, &err);
if(kOTNoError == err)
{
err = OTInstallNotifier(ep, notifier, ep);
err = OTSetAsynchronous(ep);
err = OTSetBlocking(ep);
err = OTIoctl(ep, I_OTGetMiscellaneousEvents, (void *) 1);
(completion event received in notifier)
err = OTIoctl(ep, I_OTConnect, NULL);
(completion event received in notifier)
Wait(60000);
err = OTCloseProvider(ep);
}
if(notifier)
{
DisposeOTNotifyUPP(notifier);
}
CloseOpenTransport();
}
void main()
{
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(NULL);
InitCursor();
Start();
}
--->8----->8----->8-----
These snippets were taken from earlier emails I've sent, so if you have
any questions, let me know, and I'll answer them.
If you need to setup the phone number and all the other fancy things, I'd
recommend that you get the dialing function working first. The other
stuff is easy; you'll need MoreNetworkSetup for that (MoreSCF on Mac OS X)
-If you need this to work on Mac OS X, you'll furthermore need to use ppplib.
Love,
Jens
--
Jens Bauer, Faster Software.
-Let's make the World better, shall we ?
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
- Follow-Ups:
- Re: PPP
- From: "Todd Casey" <email@hidden>
References: | |
| >PPP (From: "Todd Casey" <email@hidden>) |