GetEthernetHostNumber:
PUBLIC
ENTRY
PROCEDURE
RETURNS [
CARDINAL] =
BEGIN
i: CARDINAL;
cH: ChannelHandle;
myBufferAccessHandle: BufferDefs.BufferAccessHandle;
hit: BOOLEAN;
b: BufferDefs.OisBuffer;
status: Socket.TransferStatus;
where: LONG POINTER TO NSAddress.ProcessorID;
myID: NSAddress.ProcessorID;
ether: EthernetOneFace.DeviceHandle;
IF myHostNumber#0 THEN RETURN[myHostNumber]; -- easy known case
if the machine has a real ethernetOne then get the address from the device
ether ← EthernetOneFace.GetNextDevice[EthernetOneFace.nullDeviceHandle];
IF ether#EthernetOneFace.nullDeviceHandle
THEN
BEGIN
net, host: [0..256);
[net, host] ← EthernetOneFace.GetEthernet1Address[ether];
RETURN[myHostNumber ← host];
END;
hard case: there is no ethernetOne, so probe for it.
ProcessorFace.SetMP[MPCodes.findPupAddress];
OISCP.OiscpPackageMake[];
cH ← Socket.Create[Socket.AssignNetworkAddress[]];
Socket.SetWaitTime[cH, 3000];
myBufferAccessHandle ← SocketInternal.GetBufferPool[cH];
myID ← NSAddress.GetProcessorID[];
logically, translate ProcessFace.ProcessorID into EthernetFace.ProcessorID
hit ← FALSE;
UNTIL hit
DO
i ← i + 1;
b ← OISCP.GetFreeSendOisBufferFromPool[myBufferAccessHandle];
OISCP.SetOisPacketTextLength[b, 2*(3+SIZE[NSAddress.ProcessorID])];
b.ois.transCntlAndPktTp.packetType ← pupAddrTransPacket;
b.ois.destination.socket ← OISCPConstants.pupAddressTranslation;
b.ois.oisWords[0] ← b.ois.oisWords[1] ← i;
b.ois.oisWords[2] ← translationRequest;
where ← LOOPHOLE[@b.ois.oisWords[3]];
where^ ← myID;
Socket.PutPacketToAllConnectedNets[cH, b];
UNTIL hit
DO
b ← Socket.GetPacket[cH ! Socket.TimeOut => EXIT];
status ← LOOPHOLE[b.status];
IF (status = goodCompletion)
AND (OISCP.GetOisPacketTextLength[b] >= 2*(3 + SIZE[PupDefs.PupAddress]))
AND (b.ois.oisWords[2] = translationResponse)
THEN
BEGIN -- the response we were looking for
myLoc: LONG POINTER TO PupDefs.PupAddress = LOOPHOLE[@b.ois.oisWords[3]];
me: PupDefs.PupAddress ← myLoc^;
myHostNumber ← me.host;
hit ← TRUE;
END;
OISCP.ReturnFreeOisBuffer[b];
ENDLOOP;
ENDLOOP;
Socket.Abort[cH];
Socket.Delete[cH];
OISCP.OiscpPackageDestroy[];
ProcessorFace.SetMP[MPCodes.emptyMP];
RETURN[myHostNumber];
END; -- GetEthernetHostNumber