Code example for InetAddress

Methods: getAddress, isAnyLocalAddress, isLinkLocalAddress, isLoopbackAddress, isMulticastAddress, isSiteLocalAddress

0
 *  
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
 
package freenet.io.comm; 
 
import java.io.DataInput; 
import java.io.DataOutputStream; 
import java.io.IOException; 
import java.net.InetAddress; 
import java.net.UnknownHostException; 
 
import freenet.io.WritableToDataOutputStream; 
import freenet.support.transport.ip.HostnameSyntaxException; 
import freenet.support.transport.ip.IPUtil; 
 
/** 
 * @author ian 
 * 
 * To change the template for this generated type comment go to Window - Preferences - Java - Code Generation - Code and 
 * Comments 
 */ 
public class Peer implements WritableToDataOutputStream { 
 
    public static class LocalAddressException extends Exception {
    	private static final long serialVersionUID = -1;
	} 
 
	public static final String VERSION = "$Id: Peer.java,v 1.4 2005/08/25 17:28:19 amphibian Exp $";
 
    private final FreenetInetAddress addr;
	private final int _port;
 
	public Peer(DataInput dis) throws IOException {
		addr = new FreenetInetAddress(dis);
		_port = dis.readInt();
		if(_port > 65535 || _port < 0) throw new IOException("bogus port");
	} 
 
	public Peer(DataInput dis, boolean checkHostnameOrIPSyntax) throws HostnameSyntaxException, IOException {
		addr = new FreenetInetAddress(dis, checkHostnameOrIPSyntax);
		_port = dis.readInt();
		if(_port > 65535 || _port < 0) throw new IOException("bogus port");
	} 
 
	/** 
	 * Create a Peer from an InetAddress and a port. The IP address is primary; that is 
	 * to say, it will remain the same regardless of DNS changes. Don't do this if you 
	 * are dealing with domain names whose IP may change. 
	 */ 
	public Peer(InetAddress address, int port) {
		addr = new FreenetInetAddress(address);
		_port = port;
		if(_port > 65535 || _port < 0) throw new IllegalArgumentException("bogus port");
	} 
 
	/** 
	 * Create a Peer from a string. This may be an IP address or a domain name. If it 
	 * is the latter, the name is primary rather than the IP address;  
	 * getHandshakeAddress() will do a new lookup on the name, and change the IP address 
	 * if the domain name has changed. 
	 * @param physical The string to be parsed, in the format [ ip or domain name ]:[ port number].