org.dhcp4java
Class DHCPResponseFactory

java.lang.Object
  extended by org.dhcp4java.DHCPResponseFactory

public final class DHCPResponseFactory
extends java.lang.Object

This class provides some standard factories for DHCP responses.

This simplifies DHCP Server development as basic behaviour is already usable as-is.

Author:
Stephan Hadinger

Method Summary
static java.net.InetSocketAddress getDefaultSocketAddress(DHCPPacket request, byte responseType)
          Calculates the addres/port to which the response must be sent, according to rfc 2131, section 4.1.
static DHCPPacket makeDHCPAck(DHCPPacket request, java.net.InetAddress offeredAddress, int leaseTime, java.net.InetAddress serverIdentifier, java.lang.String message, DHCPOption[] options)
          Create a populated DHCPACK response.
static DHCPPacket makeDHCPNak(DHCPPacket request, java.net.InetAddress serverIdentifier, java.lang.String message)
          Create a populated DHCPNAK response.
static DHCPPacket makeDHCPOffer(DHCPPacket request, java.net.InetAddress offeredAddress, int leaseTime, java.net.InetAddress serverIdentifier, java.lang.String message, DHCPOption[] options)
          Create a populated DHCPOFFER response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeDHCPOffer

public static final DHCPPacket makeDHCPOffer(DHCPPacket request,
                                             java.net.InetAddress offeredAddress,
                                             int leaseTime,
                                             java.net.InetAddress serverIdentifier,
                                             java.lang.String message,
                                             DHCPOption[] options)
Create a populated DHCPOFFER response.

Reponse is populated according to the DHCP request received (must be DHCPDISCOVER), the proposed client address and a set of pre-set options.

Note: getDefaultSocketAddress is called internally to populate address and port number to which response should be sent.

Parameters:
request -
offeredAddress -
options -
Returns:
the newly created OFFER Packet

makeDHCPAck

public static final DHCPPacket makeDHCPAck(DHCPPacket request,
                                           java.net.InetAddress offeredAddress,
                                           int leaseTime,
                                           java.net.InetAddress serverIdentifier,
                                           java.lang.String message,
                                           DHCPOption[] options)
Create a populated DHCPACK response.

Reponse is populated according to the DHCP request received (must be DHCPREQUEST), the proposed client address and a set of pre-set options.

Note: getDefaultSocketAddress is called internally to populate address and port number to which response should be sent.

Parameters:
request -
offeredAddress -
options -
Returns:
the newly created ACK Packet

makeDHCPNak

public static final DHCPPacket makeDHCPNak(DHCPPacket request,
                                           java.net.InetAddress serverIdentifier,
                                           java.lang.String message)
Create a populated DHCPNAK response.

Reponse is populated according to the DHCP request received (must be DHCPREQUEST), the proposed client address and a set of pre-set options.

Note: getDefaultSocketAddress is called internally to populate address and port number to which response should be sent.

Parameters:
request -
serverIdentifier -
message -
Returns:
the newly created NAK Packet

getDefaultSocketAddress

public static java.net.InetSocketAddress getDefaultSocketAddress(DHCPPacket request,
                                                                 byte responseType)
Calculates the addres/port to which the response must be sent, according to rfc 2131, section 4.1.

This is a method ready to use for *standard* behaviour for any RFC compliant DHCP Server.

If giaddr is null, it is the client's addres/68, otherwise giaddr/67.

Standard behaviour is to set the response packet as follows:

                response.setAddrPort(getDefaultSocketAddress(request), response.getOp());
 

Parameters:
request - the client DHCP request
responseType - the DHCP Message Type the servers wants to send (DHCPOFFER, DHCPACK, DHCPNAK)
Returns:
the ip/port to send back the response
Throws:
java.lang.IllegalArgumentException - if request is null.
java.lang.IllegalArgumentException - if responseType is not valid.