Author Topic: ICMP - Echo ping request and reply.  (Read 9610 times)

Offline Renan

  • Newbie
  • *
  • Posts: 15
    • View Profile
ICMP - Echo ping request and reply.
« on: November 16, 2007, 01:41:06 PM »
Hello,

I am starting to work with uTasker and I am sending through function fnSendPing ECHO PING REQUEST, I wonder how do I identify the echo ping reply returned.

Regards,

Renan André Canello

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: ICMP - Echo ping request and reply.
« Reply #1 on: November 16, 2007, 01:42:43 PM »
Hi Renan

As you probably know, there is a ping test demo in debug.c in the demo project.

When the ICMP module receives an ECHO_PING_REPLY it informs the owner task using the event PING_RESULT. This means that even if several ping tests are being made at the same time (and from different tasks), it is possible to recognise the echo responses to each test.

This is possible due to two fields in the ICMP echo request/response frame. These are the "identifier" and "sequence number". The server MUST always echo these back UNMODIFIED.

The PING request uses the identifier field, where it adds the owner task and a (fictive) socket number. When it receives the echo to the test, it simply uses the field to route the PING_RESULT event to the task which originally sent the request and this task can then use the returned (fictive)socket number to distinguish between different echo requests which it may have sent at the same time.

Regards

Mark

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: ICMP - Echo ping request and reply.
« Reply #2 on: February 27, 2008, 12:32:43 PM »
Hi All

Here is some more information about the function fnSendPing():
extern int  fnSendPing(unsigned char *ping_address, unsigned char ucTTL, UTASK_TASK OwnerTask, USOCKET Socket);

Example of use:
    if (NO_ARP_ENTRY == fnSendPing(ping_address, MAX_TTL, OWN_TASK, dummy_socket)) {
        fnDebugMsg("ARP resolution started\n\r");
    }


ping_address is a pointer to the destination IP address, eg:
unsigned char ping_address[IPV4_LENGTH] = {192, 168, 0, 23};
MAX_TTL sets the Time To Live field of the IP frame to the maximum value of 128 (defined in tcpip.h), which is the maximum hops that are allowed to reach the destination address.
OWN_TASK enters the owner so that either ARP or ICMP knows which task to inform when there are events to be handled. As in the case of fnSendPing returning NO_ARP_ENTRY, ARP will inform the task then when either the address has been resolved or if it declares that the address is not resolvable.
dummy-Socket is a fictive socket reference - ICMP doesn't use sockets - so that each pin result can be differentiated from others which may be in process at the same time:

If the above example were called, say, 5 times as fast as possible 5 different IP addresses could be pinged. Each ping call uses a different 'fictive' socket number (eg, 1,2,3,4,5) as a reference.
When an ARP reolution event of the ping test result is ready, the task is woken with an event (eg. ARP_RESOLUTION_SUCCESS or PING_RESULT - the socket parameter accompanies this event so that the software can known wich of the actual ping tests, and which IP address is relevent.
Thus it is quite easily possible (as shown in the demo) to ping several addresses at the same time and individually handle each result.

Regards

Mark