Author Topic: ICMP use: quick how to or some hints?  (Read 7674 times)

Offline thamanjd

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
ICMP use: quick how to or some hints?
« on: August 29, 2007, 03:57:49 PM »
Can i get an idea of how to start a fnSendPing and how to check for echos please?

John Dowdell

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: ICMP use: quick how to or some hints?
« Reply #1 on: August 29, 2007, 05:12:46 PM »
Hi John

You will possibly find all that you need by looking in debug.c in the uTasker demo project.
This allows a ping test to be executed (command example "ping 192.168.0.100") via the serial interface LAN menu, or via TELNET LAN menu. If you have a device somewhere with which you can communicate with via Telnet you can, for example, use this to see which PCs on its local network are responding.

The way this works is:

1. Defines needed
            #define ICMP_PING                                            // allow PING reply
            #define ICMP_SEND_PING                                       // support PING transmission
remove ICMP_PING if you don't want your device to respond to ping tests
remove ICMP_SEND_PING if you don't need the capability to send PINGs

2. When the ping test is commanded in the demo it saves the destination IP address in ucTempIP (192.168.0.100 in this example) for use by multiple PINGs.

3. It calls the PING send function as follows:
    if (NO_ARP_ENTRY == fnSendPing(ping_address, MAX_TTL, OWN_TASK, dummy_socket)) {
        fnDebugMsg("ARP resolution started\n\r");
    }
Either the ping test will be immediately sent or it will cause ARP resolution to be started.

4. If ARP resolution is started and is successful, the debug task will receive a message from the ARP task and then calls the test again. This will often happen - if the ARP resolution doesn't fail (ARP_RESOLUTION_FAILED) the destination IP has been found in the local network (beware that it may be the gateway if the IP address is in a different sub-net) so it exists. Some destinations will have ping disabled so still may not respond.
ARP_RESOLUTION_FAILED signifies that the destination IP doesn't exist and so the ping test could not be started, which also signifies that the destination IP is not present - so a ping test could not work anyway (this is only valid for destinations in the local subnet because others will always pass through the gateway).

5. If a ping response is received, the ICMP task will inform the debug task (note that the owner task identifies itself by passing OWN_TASK to fnSendPing()) with the message PING_RESULT.
The demo code then displays this as "PING response from 192.168.0.100".

6. For each ping message there is a socket parameter (in the demo it is set to -1 to distinguish from real sockets) but it can be useful to enable multiple ping tests in parallel - each result is reported with the socket number (in fact a fictive socket since ICMP doesn't need one) so that the result can be identified to a particular IP address ping attempt.

7. If there is no reply, there will be no notification (ICMP doesn't use a time out) so to create a ping test with repetitions the application controlling it can use its own timer and counters as appropriate - if there is no ICMP PING_RESULT received within the expected maximum period the test can be assumed to have failed.

The only other ICMP support concerns the UDP DESTINATION UNREACHABLE reply.
            #define ICMP_DEST_UNREACHABLE                                // allow destination unreachable if no UDP port exists

This will automatically be sent if the device receives a UDP frame destined for a non-existent UDP port number. If this is not desired, the define can be commented out in config.h

Good luck

Regards

Mark