Package org.opennms.protocols.icmp
Class IcmpSocket
java.lang.Object
org.opennms.protocols.icmp.IcmpSocket
This class provides a bridge between the host operating system so that ICMP
messages may be sent and received.
- Author:
- Brian Weaver, OpenNMS
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionIcmpSocket(short id) Constructs a new socket that is able to send and receive ICMP messages. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()This method is used to close and release the resources associated with the instance.final voidThis method is used to set the "Don't Fragment" bit for the socket.final DatagramPacketreceive()This method is used to receive the next ICMP datagram from the operating system.final voidsend(DatagramPacket packet) This method is used to send the passed datagram using the ICMP transport.final voidsetTrafficClass(int tc) This method is used to set the traffic class for the socket.
-
Constructor Details
-
IcmpSocket
Constructs a new socket that is able to send and receive ICMP messages. The newly constructed socket will receive all ICMP messages directed at the local machine. The application must be prepared to handle any and discard any non-interesting ICMP messages.- Throws:
IOException- This exception is thrown if the socket fails to be opened correctly.
-
-
Method Details
-
setTrafficClass
This method is used to set the traffic class for the socket. (Essentially, the QoS flags for the packets sent through this socket.) This is equivalent to Java'sSocket.setTrafficClass(int).- Parameters:
tc- the traffic class- Throws:
IOException
-
dontFragment
This method is used to set the "Don't Fragment" bit for the socket.- Throws:
IOException
-
receive
This method is used to receive the next ICMP datagram from the operating system. The returned datagram packet's address is set to the sending host's address. The port number is always set to Zero, and the buffer is set to the contents of the raw ICMP message.- Throws:
IOException- Thrown if an error occurs reading the next ICMP message.
-
send
This method is used to send the passed datagram using the ICMP transport. The destination of the datagram packet is used as the send to destination for the underlying ICMP socket. The port number of the datagram packet is ignored completely.- Throws:
IOException- Thrown if an error occurs sending the datagram to the remote host.NoRouteToHostException- Thrown if the destination address is a broadcast address.
-
close
public final void close()This method is used to close and release the resources associated with the instance. The file descriptor is closed at the operating system level and any subsequent calls to this instance should result in exceptions being generated.
-