Arpa.mesa
Copyright Ó 1986, 1991 by Xerox Corporation. All rights reserved.
Hal Murray, April 5, 1986 4:22:42 pm PST
Doug Wyatt, December 11, 1986 11:52:44 am PST
JKF October 25, 1988 4:50:45 pm PDT
Arpa IP (Internet Protocol) Addresses are a combination of net and host numbers. There are 3 cases.
If the first bit is a 0, the next 7 are a type A net number, and the remaining 24 are the host number within that net.
If the first two bits are 10, the next 14 are a type B net number, and the remaining 16 are the host number within that net.
If the first two bits are 11, the next 22 are a type C net number, and the remaining 8 are the host number within that net.
Willie-s, August 13, 1991 4:04 pm PDT
Addressing
Address: TYPE = PACKED RECORD [a, b, c, d: BYTE];
nullAddress: Address = [0, 0, 0, 0];
broadcastAddress: Address = [255, 255, 255, 255];
Net: TYPE = {a, b, c};
netMasks:
ARRAY Net
OF Address = [
a: [0FF, 0, 0, 0],
b: [0FF, 0FFH, 0, 0],
c: [0FF, 0FFH, 0FFH, 0]
];
NetType: PROC [address: Address] RETURNS [Net];
NetNumber: PROC [address: Address] RETURNS [Address];
Address Manipulations
BEWARE: nullAddress looks like a class A net, and broadcastAddress looks like a class C net. Use IsSpecificNet[address] if this matters to you.
Generic ones
Class: TYPE ~ Arpa.Net; -- Net was poor name choice; don't use it!
NetClass: PROC [address: Address] RETURNS [Class];
NetMask: PROC [address: Address] RETURNS [Address];
NetNumber: PROC [address: Address] RETURNS [Address]; (in Arpa.mesa)
SubnetAndHostNumber: PROC [address: Address] RETURNS [Address];
IsSpecificNet:
PROC [address: Address]
RETURNS [
BOOL] ~
INLINE {
Quick test that net is not unknown (net 0) or broadcast. Note the address may be a broadcast address on some specific net.
RETURN[SELECT address.a FROM 0 => FALSE, >=224 => FALSE, ENDCASE => TRUE]
};
Expensive ones — check subnet masks of all connected interfaces (hence not all that expensive unless there are several connected interfaces).
NetAndSubnetMask: PROC [address: Address] RETURNS [Address];
NetAndSubnetNumber:
PROC [address: Address]
RETURNS [Address] ~
INLINE {
RETURN[LOOPHOLE[Basics32.BITAND[LOOPHOLE[address], LOOPHOLE[NetAndSubnetMask[address]]]]] };
HostNumber:
PROC [address: Address]
RETURNS [Address] ~
INLINE {
RETURN[LOOPHOLE[Basics32.BITAND[LOOPHOLE[address], Basics32.BITNOT[LOOPHOLE[NetAndSubnetMask[address]]]]]] };
IsBroadcast:
PROC [address: Address]
RETURNS [
BOOL] ~
INLINE {
RETURN[(LOOPHOLE[Basics32.BITOR[LOOPHOLE[address], LOOPHOLE[NetAndSubnetMask[address]]], Address] = broadcastAddress)] };
IsMyAddress: PROC [address: Address] RETURNS [BOOL];
Cheap ones — subnet-specific
NetAndSubnetNumberWithMask:
PROC [address: Address, mask: Address]
RETURNS [Address] ~
INLINE {
RETURN [LOOPHOLE[Basics32.BITAND[LOOPHOLE[address], LOOPHOLE[mask]]]] };
HostNumberWithMask:
PROC [address: Address, mask: Address]
RETURNS [Address] ~
INLINE {
RETURN [LOOPHOLE[Basics32.BITAND[LOOPHOLE[address], Basics32.BITNOT[LOOPHOLE[mask]]]]] };
IsBroadcastWithMask:
PROC [address: Address, mask: Address]
RETURNS [
BOOL]
~
INLINE {
RETURN [
(LOOPHOLE[Basics32.BITOR[LOOPHOLE[address], LOOPHOLE[mask]], Address] = broadcastAddress)
];
};
BroadcastAddressOnSubnetWithMask:
PROC [address: Address, mask: Address]
RETURNS [Address]
~
INLINE {
RETURN [
LOOPHOLE[Basics32.BITOR[LOOPHOLE[address], Basics32.BITNOT[LOOPHOLE[mask]]], Address]
];
};
Utilities — for rolling your own
AddressAnd:
PROC [address: Address, mask: Address]
RETURNS [Address] ~
INLINE {
RETURN[LOOPHOLE[Basics32.BITAND[LOOPHOLE[address], LOOPHOLE[mask]]]] };
AddressOr:
PROC [address: Address, mask: Address]
RETURNS [Address] ~
INLINE {
RETURN[LOOPHOLE[Basics32.BITOR[LOOPHOLE[address], LOOPHOLE[mask]]]] };
MaskNot:
PROC [address: Address]
RETURNS [Address] ~
INLINE {
RETURN[LOOPHOLE[Basics32.BITNOT[LOOPHOLE[address]]]] };