Class IcmpSocket

java.lang.Object
org.opennms.protocols.icmp.IcmpSocket

public final class IcmpSocket extends Object
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
    Modifier and Type
    Class
    Description
    static interface 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    IcmpSocket(short id)
    Constructs a new socket that is able to send and receive ICMP messages.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    This method is used to close and release the resources associated with the instance.
    final void
    This method is used to set the "Don't Fragment" bit for the socket.
    This method is used to receive the next ICMP datagram from the operating system.
    final void
    This method is used to send the passed datagram using the ICMP transport.
    final void
    This method is used to set the traffic class for the socket.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IcmpSocket

      public IcmpSocket(short id) throws IOException
      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

      public final void setTrafficClass(int tc) throws IOException
      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's Socket.setTrafficClass(int).
      Parameters:
      tc - the traffic class
      Throws:
      IOException
    • dontFragment

      public final void dontFragment() throws IOException
      This method is used to set the "Don't Fragment" bit for the socket.
      Throws:
      IOException
    • receive

      public final DatagramPacket receive() throws IOException
      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

      public final void send(DatagramPacket packet) throws IOException
      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.