socks
Class InetRange

java.lang.Object
  |
  +--socks.InetRange

public class InetRange
extends java.lang.Object
implements java.lang.Cloneable

Class InetRange provides the means of defining the range of inetaddresses. It's used by Proxy class to store and look up addresses of machines, that should be contacted directly rather then through the proxy.

InetRange provides several methods to add either standalone addresses, or ranges (e.g. 100.200.300.0:100.200.300.255, which covers all addresses on on someones local network). It also provides methods for checking wether given address is in this range. Any number of ranges and standalone addresses can be added to the range.


Constructor Summary
InetRange()
          Creates the empty range.
 
Method Summary
 void add(java.net.InetAddress ip)
          Adds another ip for this range.
 void add(java.net.InetAddress from, java.net.InetAddress to)
          Adds another range of ips for this range.Any host with ip address greater than or equal to the address of from and smaller than or equal to the address of to will be included in the range.
 boolean add(java.lang.String s)
          Adds another host or range to this range.
 java.lang.Object clone()
          Creates a clone of this Object
 boolean contains(java.net.InetAddress ip)
          Checks wether the given ip is in the range.
 boolean contains(java.lang.String host)
          Checks wether the givan host is in the range.
 boolean contains(java.lang.String host, boolean attemptResolve)
          Checks wether the given host is in the range.
 java.lang.String[] getAll()
          Get all entries in the range as strings.
 boolean remove(java.lang.String s)
          Removes an entry from this range.
 java.lang.String toString()
          Get string representaion of this Range.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InetRange

public InetRange()
Creates the empty range.
Method Detail

add

public boolean add(java.lang.String s)
Adds another host or range to this range. The String can be one of those:

add

public void add(java.net.InetAddress ip)
Adds another ip for this range.
Parameters:
ip - IP os the host which should be added to this range.

add

public void add(java.net.InetAddress from,
                java.net.InetAddress to)
Adds another range of ips for this range.Any host with ip address greater than or equal to the address of from and smaller than or equal to the address of to will be included in the range.
Parameters:
from - IP from where range starts(including).
to - IP where range ends(including).

contains

public boolean contains(java.lang.String host)
Checks wether the givan host is in the range. Attempts to resolve host name if required.
Parameters:
host - Host name to check.
Returns:
true If host is in the range, false otherwise.
See Also:
contains(String,boolean)

contains

public boolean contains(java.lang.String host,
                        boolean attemptResolve)
Checks wether the given host is in the range.

Algorithm:

  1. Look up if the hostname is in the range (in the Hashtable).
  2. Check if it ends with one of the speciefied endings.
  3. Check if it is ip(eg.130.220.35.98). If it is check if it is in the range.
  4. If attemptResolve is true, host is name, rather than ip, and all previous attempts failed, try to resolve the hostname, and check wether the ip associated with the host is in the range.It also repeats all previos steps with the hostname obtained from InetAddress, but the name is not allways the full name,it is quite likely to be the same. Well it was on my machine.
Parameters:
host - Host name to check.
attemptResolve - Wether to lookup ip address which corresponds to the host,if required.
Returns:
true If host is in the range, false otherwise.

contains

public boolean contains(java.net.InetAddress ip)
Checks wether the given ip is in the range.
Parameters:
ip - Address of the host to check.
Returns:
true If host is in the range, false otherwise.

getAll

public java.lang.String[] getAll()
Get all entries in the range as strings.
These strings can be used to delete entries from the range with remove function.
Returns:
Array of entries as strings.
See Also:
remove(String)

remove

public boolean remove(java.lang.String s)
Removes an entry from this range.
Parameters:
s - Entry to remove.
Returns:
true if successfull.

toString

public java.lang.String toString()
Get string representaion of this Range.
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Creates a clone of this Object