ArpaImpl.mesa
Copyright Ó 1991 by Xerox Corporation. All rights reserved.
Demers, November 22, 1988 5:15:09 pm PST
Carl Hauser, November 23, 1988 10:17:52 am PST
Willie-s, August 13, 1991 4:22 pm PDT
DIRECTORY
Arpa,
ArpaUDP,
DatagramSocket
;
ArpaImpl: CEDAR PROGRAM
IMPORTS Arpa, DatagramSocket
EXPORTS Arpa
~ {
Types
Address: TYPE ~ Arpa.Address;
Class: TYPE ~ Arpa.Net;
broadcastAddress: Address ~ Arpa.broadcastAddress;
nullAddress: Address ~ Arpa.nullAddress;
Parameters
xeroxClassANet: Address ¬ [13, 0, 0, 0]; -- INTERIM HACK!
xeroxSubnetMask: Address ¬ [255, 255, 252, 0];
Procedures
NetClass: PUBLIC PROC [address: Address] RETURNS [Class] ~ {
RETURN[SELECT address.a FROM < 080H => a, < 0C0H => b, ENDCASE => c] };
NetType: PUBLIC PROC [address: Address] RETURNS [Class] ~ {
RETURN[SELECT address.a FROM < 080H => a, < 0C0H => b, ENDCASE => c] };
NetMask: PUBLIC PROC [address: Address] RETURNS [Address] ~ {
RETURN[SELECT address.a FROM
< 080H => Arpa.netMasks[a],
< 0C0H => Arpa.netMasks[b],
ENDCASE => Arpa.netMasks[c]
];
};
NetNumber: PUBLIC PROC [address: Address] RETURNS [Address] ~ {
RETURN[SELECT address.a FROM
< 080H => Arpa.AddressAnd[address, Arpa.netMasks[a]],
< 0C0H => Arpa.AddressAnd[address, Arpa.netMasks[b]],
ENDCASE => Arpa.AddressAnd[address, Arpa.netMasks[c]]
];
};
SubnetAndHostNumber: PUBLIC PROC [address: Address] RETURNS [Address] ~ {
RETURN[
Arpa.AddressAnd[address, Arpa.MaskNot[NetMask[address]]]
];
};
NetAndSubnetMask: PUBLIC PROC [address: Address] RETURNS [Address]
~ {
net: Address ¬ NetNumber[address];
INTERIM HACK ...
IF net = xeroxClassANet THEN RETURN [xeroxSubnetMask];
RETURN [NetMask[address]];
};
IsMyAddress: PUBLIC PROC [address: Address] RETURNS [BOOL]
~ {
IF address # nullAddress THEN RETURN[address = MyAddress[]];
RETURN [FALSE];
};
MyAddress: PUBLIC PROC RETURNS [address: Address ¬ nullAddress] ~ {
ENABLE DatagramSocket.Error => CONTINUE;
h: DatagramSocket.Handle;
port: ArpaUDP.Port;
h ¬ DatagramSocket.Create[];
[address, port] ¬ DatagramSocket.GetLocal[h];
DatagramSocket.Destroy[h];
};
MyAddresses: PUBLIC PROC RETURNS [addresses: LIST OF Address] ~ {
INTERIM HACK ...
RETURN[ LIST[MyAddress[]] ];
};
}.