ICMP packet listeners

We need a way for programs and other systems of networking, to listen for possible incoming icmp packets. For example the TCP socket implementation may listen for destination or port unreachable, and abort before timeout expires.

For the ping command, I have added the following listeners system.

A ICMPListener interface with a method packetReceived(SocketBuffer).

The ICMPProtocol has a Hashtable called listeners. The Keys of this Hashtable is a ICMPListenerCriteria object, which overrides the equals method and will be used to filter the listeners who will be notified (for example the ping command will use a ICMPListenerCriteria object that match only the echo reply packets).

The ICMPProtocol has also the methods addListener(ICMPListener), removeListener(ICMPListener) and notifyListeners(SocketBuffer) which calls the packetReceived method of the matched listeners. The notifyListeners method will be called from ICMPProtocol.receive().

The main problem of this system, is that the notifyListeners method may call the packetReceived method of many listeners. And if the particular implementation of packetReceived blocks for long times there would be a problem. So there must be some caution in implementation of packetReceived.