org.opennms.protocols.icmp
Class IcmpSocket

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

public final class IcmpSocket
extends java.lang.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
static class IcmpSocket.Stuff
           
 
Constructor Summary
IcmpSocket()
          Constructs a new socket that is able to send and receive ICMP messages.
 
Method Summary
 void close()
          This method is used to close and release the resources assocated with the instance.
static void main(java.lang.String[] argv)
           
 java.net.DatagramPacket receive()
          This method is used to receive the next ICMP datagram from the operating system.
 void send(java.net.DatagramPacket packet)
          This method is used to send the passed datagram using the ICMP transport.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IcmpSocket

public IcmpSocket()
           throws java.io.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:
java.io.IOException - This exception is thrown if the socket fails to be opened correctly.
Method Detail

receive

public final java.net.DatagramPacket receive()
                                      throws java.io.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:
java.io.IOException - Thrown if an error occurs reading the next ICMP message.

send

public final void send(java.net.DatagramPacket packet)
                throws java.io.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:
java.io.IOException - Thrown if an error occurs sending the datagram to the remote host.
java.net.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 assocated 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.


main

public static void main(java.lang.String[] argv)


Copyright © 2007. All Rights Reserved.