com.limegroup.gnutella.util
Class NetworkUtils

java.lang.Object
  extended bycom.limegroup.gnutella.util.NetworkUtils

public final class NetworkUtils
extends java.lang.Object

This class handles common utility functions for networking tasks.


Method Summary
static java.lang.String ip2string(byte[] ip)
          Returns the ip (given in BIG-endian) format as standard dotted-decimal, e.g., 192.168.0.1
static java.lang.String ip2string(byte[] ip, int offset)
          Returns the ip (given in BIG-endian) format of buf[offset]...buf[offset+3] as standard dotted-decimal, e.g., 192.168.0.1
static boolean isCloseIP(byte[] addr0, byte[] addr1)
          Returns whether or not the two ip addresses share the same first octet in their address.
static boolean isLocalAddress(java.net.InetAddress addr)
          Returns whether or not the supplied address is a local address.
static boolean isMe(java.lang.String host, int port)
          If host is not a valid host address, returns false.
static boolean isPrivate()
          Returns whether or not this node has a private address.
static boolean isPrivateAddress(byte[] address)
          Checks to see if the given address is a firewalled address.
static boolean isPrivateAddress(java.net.InetAddress address)
          Utility method for determing whether or not the given address is private taking an InetAddress object as argument like the isLocalAddress(InetAddress) method.
static boolean isPrivateAddress(java.lang.String address)
          Utility method for determing whether or not the given address is private.
static boolean isValidAddress(byte[] addr)
          Returns whether or not the specified address is valid.
static boolean isValidAddress(java.net.InetAddress addr)
          Returns whether or not the specified InetAddress is valid.
static boolean isValidAddress(java.lang.String host)
          Returns whether or not the specified host is a valid address.
static boolean isValidPort(int port)
          Returns whether or not the specified port is within the valid range of ports.
static boolean isVeryCloseIP(byte[] addr)
          Returns whether or not the given ip address shares the same first three octets as the address for this node -- the most common indication that they may be on the same network.
static boolean isVeryCloseIP(byte[] addr0, byte[] addr1)
          Returns whether or not the two ip addresses share the same first two octets in their address -- the most common indication that they may be on the same network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isValidPort

public static boolean isValidPort(int port)
Returns whether or not the specified port is within the valid range of ports.

Parameters:
port - the port number to check

isValidAddress

public static boolean isValidAddress(byte[] addr)
Returns whether or not the specified address is valid.


isValidAddress

public static boolean isValidAddress(java.net.InetAddress addr)
Returns whether or not the specified InetAddress is valid.


isValidAddress

public static boolean isValidAddress(java.lang.String host)
Returns whether or not the specified host is a valid address.


isLocalAddress

public static boolean isLocalAddress(java.net.InetAddress addr)
Returns whether or not the supplied address is a local address.


isCloseIP

public static boolean isCloseIP(byte[] addr0,
                                byte[] addr1)
Returns whether or not the two ip addresses share the same first octet in their address.

Parameters:
addr0 - the first address to compare
addr1 - the second address to compare

isVeryCloseIP

public static boolean isVeryCloseIP(byte[] addr0,
                                    byte[] addr1)
Returns whether or not the two ip addresses share the same first two octets in their address -- the most common indication that they may be on the same network. Private networks are NOT CONSIDERED CLOSE.

Parameters:
addr0 - the first address to compare
addr1 - the second address to compare

isVeryCloseIP

public static boolean isVeryCloseIP(byte[] addr)
Returns whether or not the given ip address shares the same first three octets as the address for this node -- the most common indication that they may be on the same network.

Parameters:
addr - the address to compare

isPrivate

public static boolean isPrivate()
Returns whether or not this node has a private address.

Returns:
true if this node has a private address, otherwise false

isPrivateAddress

public static boolean isPrivateAddress(byte[] address)
Checks to see if the given address is a firewalled address.

Parameters:
address - the address to check

isPrivateAddress

public static boolean isPrivateAddress(java.net.InetAddress address)
Utility method for determing whether or not the given address is private taking an InetAddress object as argument like the isLocalAddress(InetAddress) method. Delegates to isPrivateAddress(byte[] address).

Returns:
true if the specified address is private, otherwise false

isPrivateAddress

public static boolean isPrivateAddress(java.lang.String address)
Utility method for determing whether or not the given address is private. Delegates to isPrivateAddress(byte[] address). Returns true if the host is unknown.

Returns:
true if the specified address is private, otherwise false

ip2string

public static final java.lang.String ip2string(byte[] ip)
Returns the ip (given in BIG-endian) format as standard dotted-decimal, e.g., 192.168.0.1

Parameters:
ip - the ip address in BIG-endian format
Returns:
the IP address as a dotted-quad string

ip2string

public static final java.lang.String ip2string(byte[] ip,
                                               int offset)
Returns the ip (given in BIG-endian) format of buf[offset]...buf[offset+3] as standard dotted-decimal, e.g., 192.168.0.1

Parameters:
ip - the IP address to convert
offset - the offset into the IP array to convert
Returns:
the IP address as a dotted-quad string

isMe

public static boolean isMe(java.lang.String host,
                           int port)
If host is not a valid host address, returns false. Otherwise, returns true if connecting to host:port would connect to this servent's listening port.

Returns:
true if the specified host/port combo is this servent, otherwise false.