Network.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright 1998-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* A representation of an IP network from DHCP's point of view; we're
* primarily interested in the address and subnet mask.
*/
// Serialization id for this class
static final long serialVersionUID = 7221738570228102243L;
/**
* Construct an empty network object
*/
public Network() {
}
/**
* Construct a network with the supplied address and a default mask
* @param addr The IP address of the network
*/
}
// Common initialization routine
// Initialize a default netmask based on address class
byte [] b = address.getAddress();
try {
if (msb < 128) {
} else if (msb < 192) {
} else {
}
} catch (ValidationException e) {
// This shouldn't happen, above masks are all valid IP addrs
}
}
/**
* Construct a network with the supplied address.
* @param addr The IP address of the network.
*/
try {
} catch (ValidationException e) {
throw new ValidationException(msg);
}
}
/**
* Construct a network with the supplied address and subnet mask
* @param addr The IP address of the network as a <code>String</code>
* @param mask The subnet mask as an <code>int</code>
*/
try {
} catch (ValidationException e) {
throw new ValidationException(msg);
}
}
/**
* Construct a network with the supplied address and subnet mask.
* @param addr The IP address as an <code>IPAddress</code>
* @param mask The subnet mask as an <code>IPAddress</code>
*/
}
/**
* Construct a network with the supplied address and subnet mask.
* @param addr The IP address as a dotted decimal <code>String</code>
* @param mask The subnet mask as a dotted decimal <code>String</code>
*/
try {
} catch (ValidationException e) {
throw new ValidationException(msg);
}
try {
} catch (ValidationException e) {
throw new ValidationException(msg);
}
}
/**
* @return The IP address of the network
*/
public IPAddress getAddress() {
return address;
}
/**
* Return the actual network number, which is the product of applying
* the subnet mask to the address supplied.
* @return The network number as an <code>IPAddress</code>
*/
public IPAddress getNetworkNumber() {
// If netmask is not set then ignore it and return address raw
return address;
} else {
}
}
/**
* @return The subnet mask of the network
*/
return netmask;
}
/**
* Set the subnet mask.
* @param mask The subnet mask.
*/
}
/**
* Do the math to evaluate whether an address is part of this network.
* @param addr The IP address to evaluate
* @return <code>true</code> if the address is on this network,
* <code>false</code> if not.
*/
}
/**
* Compute the broadcast address for this network and return it.
* @return a string representation of the broadcast address.
*/
public String getBroadcastAddress() {
}
}
} // getBroadcastAddress
/**
* Compare against another network object for equality.
* @param obj The network to compare against.
* @return <code>true</code> if the networks have the same network number
*/
// If object passed isn't of same type, always false.
return false;
}
}
return getNetworkNumber().toString();
}
/**
* Perform comparisons to another Network instance. This is used
* for sorting a list of network tables.
* @param o A <code>Network</code> to compare against.
* @return 0 if the objects have the same address,
* a negative number if this record has a lower IP address than the
* supplied record, a positive number if this record has a higher IP
* address than the supplied record.
*/
n.getNetworkNumber().getBinaryAddress();
if (result < 0) {
return (-1);
} else if (result > 0) {
return (1);
} else {
return (0);
}
}
}