Class DHCPSocket
java.lang.Object
java.net.DatagramSocket
com.github.markusbernhardt.proxy.search.wpad.dhcp.DHCPSocket
- All Implemented Interfaces:
Closeable
,AutoCloseable
This class represents a Socket for sending DHCP Messages
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Default MTU (Maximum Transmission Unit) for ethernet (in bytes)private static final int
Default socket timeout (1 second) -
Constructor Summary
ConstructorsConstructorDescriptionDHCPSocket
(int inPort) Constructor for creating DHCPSocket on a specific port on the local machine.DHCPSocket
(int inPort, InetAddress lAddr) Constructor for creating DHCPSocket on a specific local address and port on the local machine. -
Method Summary
Modifier and TypeMethodDescriptionint
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, joinGroup, leaveGroup, receive, send, setBroadcast, setDatagramSocketImplFactory, setOption, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass, supportedOptions
-
Field Details
-
SOCKET_TIMEOUT
private static final int SOCKET_TIMEOUTDefault socket timeout (1 second)- See Also:
-
mtu
private int mtuDefault MTU (Maximum Transmission Unit) for ethernet (in bytes)
-
-
Constructor Details
-
DHCPSocket
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 theSocket
constructor
-
DHCPSocket
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 theSocket
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
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
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.
-