ADC Home > Reference Library > Technical Q&As > Legacy Documents > Networking >
Legacy Document
Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.
Current information on this Reference Library topic can be found here:
Technical Q&A NW05
Ethernet Addresses
|
Q: How can I obtain an Ethernet address programmatically? I can get correct
Ethernet addresses for RAM-based drivers, but this does not appear to work for
all drivers. For example, addresses for PowerBooks with DaynaPort connections
are not available. I am using the following code to obtain Ethernet addresses:
myErr = OpenDriver("\p.ENET", &myRefNum);
theEPB.EParms1.ioRefNum = myRefNum;
theEPB.EParms1.ePointer = NewPtrClear(78);
theEPB.EParms1.eBuffSize = 78;
theEPB.EParms1.ioNamePtr = NULL;
myErr = EGetInfo(&theEPB,false);
|
How can I scan through all the installed Ethernet drivers for the one that's active
and obtain information about that one?
A: Your approach for obtaining Ethernet address information seems appropriate.
Here are a few pieces of information that may help:
- OpenDriver("\p.ENET", &myRefNum) only opens the first Ethernet driver. If the system has more than one Ethernet card installed, you have to open them explicitly.
- Machines such as the SE and PowerBooks that have the Ethernet hardware connected via the SCSI port are accessed through ENET0 (most machines have this ability).
The following is a code fragment that you can use:
/* check internal non slotted card
check if enet0 driver is installed
*/
short saveRes;
saveRes = LMGetResLoad();
LMSetResLoad(0)
GetNamedResource('DRVR',"\p.ENET0"); // check if ENET0 is in ROM
LMSetResLoad(saveRes)
if(!ResError()) {
/* Setup Open PB */
PB.slotDevParam.ioNamePtr = "\p.ENET0"; // Attempt to open it
PB.slotDevParam.ioVRefNum = 0;
PB.slotDevParam.csCode = 0;
PB.slotDevParam.ioSlot = 0;
PB.slotDevParam.ioID = 0;
/* try and open the internal non slotted enet card */
ErrNo = PBOpenSync(&PB); // notice I do a regular open call $A000
refnum = PB.ioRefNum;
|
- For NuBus and SE30 devices (and PCI slots), you have to use the Slot Manager to scan for available Ethernet cards, per this example:
/* Setup Open PB for sloted device */
PB.slotDevParam.ioNamePtr = "\p.ENET";
PB.slotDevParam.ioVRefNum = 0;
PB.slotDevParam.csCode = 0;
/* try Slotmanger Call */
if(!OSTrapAvailable (_SlotManager)) return(Error);
SPB.spExtDev = 0;
SPB.spCategory = 4; /* Network */
SPB.spCType = 1 ; /* EtherNet */
SPB.spTBMask = 0x3;
/* loop on each card */
while((ErrNo = SNextTypeSRsrc(&SPB)) == noErr){
PB.slotDevParam.ioSlot = SPB.spSlot;
PB.slotDevParam.ioID = SPB.spID;
/* try and open the enet card */
ErrNo = PBOpenImmed(&PB); // Notice I Do an OpenImmed $A200
refnum = PB.ioRefNum;
}
|
- An important point to consider:
OpenDriver calls fail when Ethernet devices are not cabled or hooked up, so it's not possible to get the address of Ethernet cards that aren't hooked up.
|
[May 01 1995]