Author Topic: ICMP Ping & Trace  (Read 381 times)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
ICMP Ping & Trace
« on: January 06, 2023, 02:58:06 AM »
Hi
Recently I needed to check if a server is down, and the easiest way to do this is to use the ping command.
If you need to do this from your application, you either have to deal with raw sockets, all their complexities and admin privileges, or you can use the well-known IcmpSendEcho API.

With the latter, the implementation is fairly straightforward, and as a bonus, the trace command can be coded just as easily.
I had to translate the appropriate header file and the rest was more or less standard coding.

In the attachments I've included as reference a 32-bit test application, the ping and trace code, and the IcmpAPI.inc and IPExport.inc files, that are required to use the IcmpSendEcho API.  :biggrin:

Biterider

K_F

  • Member
  • *****
  • Posts: 1770
  • Anybody out there?
Re: ICMP Ping & Trace
« Reply #1 on: January 06, 2023, 06:10:08 AM »
 :bgrin:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

LiaoMi

  • Member
  • *****
  • Posts: 1055
Re: ICMP Ping & Trace
« Reply #2 on: January 08, 2023, 12:28:27 AM »
Hi Biterider,

 :thumbsup: Thanks for the example! Is it possible to extend the example to a library?

liboping-master Protocol independent ANSI-C ping library and command line utility
https://github.com/octo/liboping

  liboping was inspired by ping, libping and fping: It differs from these
  existing solutions in that it can “ping” multiple hosts in parallel using
  IPv4 or IPv6 transparently. Other design principles were an object oriented
  interface, simplicity and extensibility.



Features
━━━━━━━━

  • Support for multiple hosts.

  • Support for IPv4 and IPv6.

  • Object oriented interface.

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: ICMP Ping & Trace
« Reply #3 on: January 08, 2023, 06:15:15 AM »
Hi LiaoMi
Yes, it is quite possible to create a static library, but I don't think it is worth it.  :rolleyes:
Basically, you only need to call 1 Win32 API (IcmpSendEcho/Icmp6SendEcho2) to execute a single ICMP ping.
To save time you can execute multiple pings asynchronously. This only requires an event object and a call to IcmpSendEcho2/Icmp6SendEcho2 for each host.

Biterider