com.dalsemi.tininet.dhcp
Class DHCPClient

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.dalsemi.tininet.dhcp.DHCPClient

public class DHCPClient
extends java.lang.Thread

The DHCPClient supports dynamically obtaining a new IP Address or reclaiming an IP Address lost on reboot from a DHCP server. Both constructors are passed a DHCPListener so that DHCP status messages can be relayed. After the DHCPClient object is constructed, the process in invoked through the start() method. When the user no longer needs the IP Address it is recommended that the stopDHCP method is called to release the IP to the server and close the socket.

Refer to the following RFCs:

           951 - BOOTSTRAP PROTOCOL (BOOTP)
          1048 - BOOTP Vendor Information Extensions
          2131 - Dynamic Host Configuration Protocol
          2132 - DHCP Options and BOOTP Vendor Extentions
RFC repository: http://www.ietf.org/rfc.html


Field Summary
static int LEASE_INFINITE
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DHCPClient(DHCPListener DL)
          Constructs a DHCP object and intializes for obtaining a new IP.
DHCPClient(DHCPListener DL, byte[] serverIP, byte[] localIP)
          Constructs a DHCP object and intializes to attempt to rebind to a previously owned IP that was lost in a reboot.
 
Method Summary
 void addDHCPListener(DHCPListener newListener)
          Adds listener for accepting DHCP status messages.
 long getLeaseTimeout()
          This method returns the DHCP lease expiration timeout.
 void parseOption(byte[] recvdata, int position)
          This method is called at least once for every DHCP packet received from teh DHCP server; it is also called for every DHCP option not handled by the DHCPClient code.
 void removeDHCPListener(DHCPListener thisListener)
          Removes listener, to discontinue acceptance of status messages.
 void run()
          Starts DHCP thread.
 void stopDHCPThread()
          Stops DHCP thread, releases IP, and closes any open sockets.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEASE_INFINITE

public static final int LEASE_INFINITE
Constructor Detail

DHCPClient

public DHCPClient(DHCPListener DL)
           throws java.lang.IllegalStateException
Constructs a DHCP object and intializes for obtaining a new IP.
Parameters:
DL - DHCPListener to report DHCP status messages
Throws:
java.lang.IllegalStateException - if DHCP is already running.

DHCPClient

public DHCPClient(DHCPListener DL,
                  byte[] serverIP,
                  byte[] localIP)
           throws java.lang.IllegalStateException
Constructs a DHCP object and intializes to attempt to rebind to a previously owned IP that was lost in a reboot.
Parameters:
DL - DHCPListener
serverIP - IP of DHCP server where previous IP was obtained
localIP - IP to obtain
Throws:
java.lang.IllegalStateException - if DHCP is already running.
Method Detail

run

public void run()
Starts DHCP thread.
Overrides:
run in class java.lang.Thread

stopDHCPThread

public void stopDHCPThread()
Stops DHCP thread, releases IP, and closes any open sockets.

parseOption

public void parseOption(byte[] recvdata,
                        int position)
This method is called at least once for every DHCP packet received from teh DHCP server; it is also called for every DHCP option not handled by the DHCPClient code. A subclass could override this method to implement its own option handling.
Parameters:
recvdata - byte array - the complete packet received from the DHCP server.
position - position of the current option inside the recvdata[] array.

addDHCPListener

public void addDHCPListener(DHCPListener newListener)
Adds listener for accepting DHCP status messages.
Parameters:
newListener - DHCPListener for accepting status messages

removeDHCPListener

public void removeDHCPListener(DHCPListener thisListener)
Removes listener, to discontinue acceptance of status messages.
Parameters:
thisListener - DHCPListener to be removed from list

getLeaseTimeout

public long getLeaseTimeout()
This method returns the DHCP lease expiration timeout.
Returns:
the number of seconds relative to system start, i.e. subtract System.currentTimeMillis()/1000 from this value to get the remainder of the DHCP lease life in seconds. Note: The value LEASE_INFINITE means "infinite lease".


Also see:
o TINI 1.11 API, Optional Modules
o TINI Home Page
o 1-Wire API

Last update Fri Jan 24 12:06:43 CST 2003
Используются технологии uCoz