Class DHCPSocket
- java.lang.Object
-
- java.net.DatagramSocket
-
- com.github.markusbernhardt.proxy.search.wpad.dhcp.DHCPSocket
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class DHCPSocket extends java.net.DatagramSocket
This class represents a Socket for sending DHCP Messages- See Also:
DatagramSocket
-
-
Field Summary
Fields Modifier and Type Field Description private int
mtu
Default MTU (Maximum Transmission Unit) for ethernet (in bytes)private static int
SOCKET_TIMEOUT
Default socket timeout (1 second)
-
Constructor Summary
Constructors Constructor Description DHCPSocket(int inPort)
Constructor for creating DHCPSocket on a specific port on the local machine.DHCPSocket(int inPort, java.net.InetAddress lAddr)
Constructor for creating DHCPSocket on a specific local address and port on the local machine.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getMTU()
Returns the set MTU for this socketboolean
receive(DHCPMessage outMessage)
Receives a datagram packet containing a DHCP Message into a DHCPMessage object.void
send(DHCPMessage inMessage)
Sends a DHCPMessage object to a predefined host.void
setMTU(int inSize)
Sets the Maximum Transfer Unit for the UDP DHCP Packets to be set.-
Methods inherited from class java.net.DatagramSocket
bind, close, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalAddress, getLocalPort, getLocalSocketAddress, getOption, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, receive, send, setBroadcast, setDatagramSocketImplFactory, setOption, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass, supportedOptions
-
-
-
-
Field Detail
-
SOCKET_TIMEOUT
private static final int SOCKET_TIMEOUT
Default socket timeout (1 second)- See Also:
- Constant Field Values
-
mtu
private int mtu
Default MTU (Maximum Transmission Unit) for ethernet (in bytes)
-
-
Constructor Detail
-
DHCPSocket
public DHCPSocket(int inPort) throws java.net.SocketException
Constructor for creating DHCPSocket on a specific port on the local machine.- Parameters:
inPort
- The port for the application to bind.- Throws:
java.net.SocketException
- As thrown by theSocket
constructor
-
DHCPSocket
public DHCPSocket(int inPort, java.net.InetAddress lAddr) throws java.net.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:
java.net.SocketException
- As thrown by theSocket
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 java.io.IOException
Sends a DHCPMessage object to a predefined host.- Parameters:
inMessage
- Well-formed DHCPMessage to be sent to a server- Throws:
java.io.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.
-
-