Class DHCPSocket

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class DHCPSocket
    extends DatagramSocket
    This class represents a Socket for sending DHCP Messages
    Author:
    Markus Bernhardt, Copyright 2016, Jason Goldschmidt and Simon Frankenberger, Bernd Rosstauscher, Copyright 2009
    See Also:
    DatagramSocket
    • Constructor Detail

      • 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 Detail

      • 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.