java.lang.Object
java.net.DatagramSocket
com.github.markusbernhardt.proxy.search.wpad.dhcp.DHCPSocket
All Implemented Interfaces:
Closeable, AutoCloseable

public class DHCPSocket extends DatagramSocket
This class represents a Socket for sending DHCP Messages
See Also:
  • Field Details

    • SOCKET_TIMEOUT

      private static final int SOCKET_TIMEOUT
      Default socket timeout (1 second)
      See Also:
    • mtu

      private int mtu
      Default MTU (Maximum Transmission Unit) for ethernet (in bytes)
  • Constructor Details

    • DHCPSocket

      public DHCPSocket(int inPort) throws SocketException
      Constructor for creating DHCPSocket on a specific port on the local machine.
      Parameters:
      inPort - The port for the application to bind.
      Throws:
      SocketException - As thrown by the Socket constructor
    • DHCPSocket

      public DHCPSocket(int inPort, InetAddress lAddr) throws SocketException
      Constructor for creating DHCPSocket on a specific local address and port on the local machine.
      Parameters:
      inPort - The port for the application to bind.
      lAddr - The local address for the application to bind.
      Throws:
      SocketException - As thrown by the Socket constructor
  • Method Details

    • setMTU

      public void setMTU(int inSize)
      Sets the Maximum Transfer Unit for the UDP DHCP Packets to be set.
      Parameters:
      inSize - Integer representing desired MTU
    • getMTU

      public int getMTU()
      Returns the set MTU for this socket
      Returns:
      The Maximum Transfer Unit set for this socket
    • send

      public void send(DHCPMessage inMessage) throws IOException
      Sends a DHCPMessage object to a predefined host.
      Parameters:
      inMessage - Well-formed DHCPMessage to be sent to a server
      Throws:
      IOException - If the message could not be sent.
    • receive

      public boolean receive(DHCPMessage outMessage)
      Receives a datagram packet containing a DHCP Message into a DHCPMessage object.
      Parameters:
      outMessage - DHCPMessage object to receive new message into
      Returns:
      true if message is received, false if timeout occurs.