Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
GetEAddr.c
/* |
File: GetEAddr.c |
Rich Kubota |
DTS |
June 2, 1992 |
Sample program to demonstrate the use of the LAP Manager to determine the |
current AppleTalk connection device based on the ADEV resource ID. Also |
demonstrates a call to EGetInfo to obtain the burned in Ethernet address |
whether on the card or built-in on the Quadra's. This program assumes the |
use of the Apple Ethernet phase 1 0r 2 driver ADEV's. |
*/ |
#include <Types.h> |
#include <QuickDraw.h> |
#include <Fonts.h> |
#include <Events.h> |
#include <Dialogs.h> |
#include <Resources.h> |
#include <OSUtils.h> |
#include <Files.h> |
#include <ENET.h> |
#include <Devices.h> |
#include <Memory.h> |
#include <Menus.h> |
#include <OSEvents.h> |
#include <AppleTalk.h> |
#define LGetATalkInfo 0x09 /* Get AppleTalk info */ |
#define kSPConfig 0x1FB /* low nibble of global byte indicates whether AppleTalk active */ |
#define kAlertID 1000 |
#define ETalkPh1 2 /* Ethernet Phase 1 ADEV resource ID */ |
#define ETalkPh2 10 /* Ethernet Phase 2 ADEV resource ID */ |
#define kAlertID 1000 |
#define kAddrID 1001 |
Boolean SlotMgrAvailable(); |
void doInitializing(); |
pascal long CallLAPMgr( short selector); /* prototype for assembler routine */ |
main() |
{ |
EParamBlock pb; |
OSErr err; |
long result; |
char adevType; |
char slot; |
char buffer[78], c1, c2; |
Str32 enetAddrStr; |
short i; |
Ptr spConfigPtr; |
doInitializing(); /* set up to display alert dialogs */ |
result = CallLAPMgr(LGetATalkInfo); /* get current connection setting */ |
adevType = result & 0x000000FF; /* atlk resource id is return in LSB */ |
slot = result>>24; /* card slot returned in MSB */ |
spConfigPtr = (Ptr)kSPConfig; |
if ((*spConfigPtr & 0x0F) != 1) /* Check whether AppleTalk is enabled */ |
{ |
ParamText("\pAppleTalk must be active.\ |
Go to the Chooser and turn AppleTalk on.", nil, nil, nil); |
err = StopAlert(kAlertID, nil); |
ExitToShell(); |
} |
if ((adevType != ETalkPh1) && (adevType != ETalkPh2)) |
/* check whether Ethernet is the current setting */ |
{ |
ParamText("\pEthernet is not the default connection. Use the Network CDEV and select the Ethernet driver.", nil, nil, nil); |
err = StopAlert(kAlertID, nil); |
ExitToShell(); |
} |
/* now we know that AppleTalk is active and that EtherTalk is already open */ |
if ((err = OpenDriver("\p.ENET", &pb.EParms1.ioRefNum)) == noErr) |
{ |
pb.EParms1.ePointer = buffer; |
pb.EParms1.eBuffSize = sizeof(buffer); |
err = EGetInfo(&pb, false); |
enetAddrStr[0] = 12; |
/* set up the address string to display in hexidecimal */ |
for (i=0; i<6; i++) |
{ |
c1 = ((buffer[i] >> 4) & 0x0F) + '0'; |
c2 = (buffer[i] & 0x0F) + '0'; |
if (c1 > '9') |
c1 = c1 + ('A' - '9' - 1); |
if (c2 > '9') |
c2 = c2 + ('A' - '9' - 1); |
enetAddrStr[2*i+1] = c1; |
enetAddrStr[2*i+2] = c2; |
} |
/* display the address in an alert dialog */ |
ParamText(enetAddrStr, nil, nil, nil); |
err = Alert(kAddrID, nil); |
} |
else |
{ |
ParamText("\pError opening the Ethernet driver.", nil, nil, nil); |
err = StopAlert(kAlertID, nil); |
ExitToShell(); |
} |
} |
/* |
* doInitializing() Called at application boot to allocate master pointers, |
* check SysEnvirons() for Mac type, check for WaitNextEvent implementation. |
* and call all other initializing routines. |
*/ |
void doInitializing() |
{ |
MaxApplZone(); |
MoreMasters(); |
MoreMasters(); |
MoreMasters(); |
MoreMasters(); |
#ifdef THINK_C |
InitGraf(&thePort); |
#else |
InitGraf(&qd.thePort); |
#endif |
InitFonts(); |
FlushEvents(everyEvent, 0); |
InitWindows(); |
InitMenus(); |
TEInit(); |
InitDialogs(0L); |
InitCursor(); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14