ICMP ping library v2.0

A few years ago I posted my ICMP ping library here. Motivated by a bunch of recent inquiries about it, I've released version 2.0 of the library. It now lives in Github:

The big improvement over version 1.0 (which was geared more toward a specific use) is that it returns the response as an object instead of a string, and lets the caller decide what to do with it. I also fixed a few minor bugs.

I hope that someone finds it useful, or even better, improves it and pushes the changes back upstream.

Cheers,
Blake

Thanks for sharing, looks really good!

A quick look at the code shows little opportunity to make serious improvements.
The only point I found is that sending the ping has a while loop that can timeout. That always makes me wandering if it can be done async ?

You might check - RFC 792 - Internet Control Message Protocol - to map the error codes to the RFC spec (minor point),
(maybe add the RFC or link to, as documentation?

Thanks for the comments. You actually hit on my next TODO--I've been tinkering with making the error codes match the RFC.

I could see how having an asynchronous version of the API might be useful as well. Probably three functions, one to send a request, one to check if a response is available, and one to receive a response.

Probably three functions, one to send a request, one to check if a response is available, and one to receive a response.

That would be a good implementation

The other one could involve register a callback function (event driven), but for an Arduino I think that is overkill.

Hi Blake, i really enjoyed your first version of ICMP Ping library (as a bcontent i am :), now i try to use your new version but there is a line that i don't understand..

ICMPPing ping(pingSocket, (uint16_t)random(0, 255));

I remember in your previously version it was ICMPPing ping(ping Socket), what means the "new" part ? i tried to delete but it doesn't work.

I am getting error message as this:

C:\Program Files\Arduino\libraries\icmp_ping\ICMPPing.cpp: In member function 'void ICMPPing::receiveEchoReply(const ICMPEcho&, const IPAddress&, ICMPEchoReply&)':
C:\Program Files\Arduino\libraries\icmp_ping\ICMPPing.cpp:177: error: invalid conversion from 'uint16_t' to 'volatile uint8_t*'
C:\Program Files\Arduino\libraries\icmp_ping\ICMPPing.cpp:177: error:   initializing argument 2 of 'void W5100Class::read_data(SOCKET, volatile uint8_t*, volatile uint8_t*, uint16_t)'
C:\Program Files\Arduino\libraries\icmp_ping\ICMPPing.cpp:185: error: invalid conversion from 'uint16_t' to 'volatile uint8_t*'
C:\Program Files\Arduino\libraries\icmp_ping\ICMPPing.cpp:185: error:   initializing argument 2 of 'void W5100Class::read_data(SOCKET, volatile uint8_t*, volatile uint8_t*, uint16_t)'

my error for this line

ICMPPing ping(pingSocket, (uint16_t)random(0, 255));

and i changed this line

byte pingAddr(74,125,26,147); // ip address to ping
i use arduino software 1.6.5

icmp ping ver 2 fixed ?

Thanks for your answer
I need a program that will ping a device or tar mention being able to tell if something is not working and why Ardynv instance. Please note Hara.
Have you completed the program.
Can be used on the Snmp Ardynv
Should I use the ARm . Bnanpi
Do not respond to the ping Ardiono Where is my problem.

خیلی ممنونم اگر زودتر جواب بدین

HI There

I've just installed the ICMP_Ping library from : GitHub - BlakeFoster/Arduino-Ping: ICMP ping library for the Arduino

When trying to compile an empty sketch, I get the errors below.

Any help would be appreciated.

Thank You.


Arduino: 1.6.7 (Windows 8), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Gail\Documents\Arduino\libraries\ICMPPing\ICMPPing.cpp: In member function 'uint8_t ICMPPing::receiveEchoReply(byte*, uint8_t&, time_t&)':

C:\Users\Gail\Documents\Arduino\libraries\ICMPPing\ICMPPing.cpp:113:67: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint16_t {aka unsigned int}' [-fpermissive]

W5100.read_data(socket, (uint8_t *)buffer, header, sizeof(header));

^

In file included from C:\Users\Gail\Documents\Arduino\libraries\ICMPPing\ICMPPing.h:12:0,

from C:\Users\Gail\Documents\Arduino\libraries\ICMPPing\ICMPPing.cpp:10:

C:\Program Files (x86)\Arduino\libraries\Ethernet\src/utility/w5100.h:142:8: error: initializing argument 2 of 'void W5100Class::read_data(SOCKET, uint16_t, volatile uint8_t*, uint16_t)' [-fpermissive]

void read_data(SOCKET s, volatile uint16_t src, volatile uint8_t * dst, uint16_t len);

^

C:\Users\Gail\Documents\Arduino\libraries\ICMPPing\ICMPPing.cpp:119:75: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'uint16_t {aka unsigned int}' [-fpermissive]

W5100.read_data(socket, (uint8_t *)buffer, (uint8_t *)&echoReply, dataLen);

^

In file included from C:\Users\Gail\Documents\Arduino\libraries\ICMPPing\ICMPPing.h:12:0,

from C:\Users\Gail\Documents\Arduino\libraries\ICMPPing\ICMPPing.cpp:10:

C:\Program Files (x86)\Arduino\libraries\Ethernet\src/utility/w5100.h:142:8: error: initializing argument 2 of 'void W5100Class::read_data(SOCKET, uint16_t, volatile uint8_t*, uint16_t)' [-fpermissive]

void read_data(SOCKET s, volatile uint16_t src, volatile uint8_t * dst, uint16_t len);

^

exit status 1
Error compiling.
Invalid library found in C:\Program Files (x86)\Arduino\libraries\Arduino-Ping-master: C:\Program Files (x86)\Arduino\libraries\Arduino-Ping-master

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

hi,
can i do a IP range scan?

It looks like the ICMPPing library no longer works with the new Ethernet library 2.0 that was released a few days ago. I am now getting these messages:

ICMPPing.cpp: In member function Status ICMPPing::sendEchoRequest(const IPAddress&, const ICMPEcho&)

ICMPPing.cpp: 184:11: error: 'class W5100Class' has no member named 'send_data_processing
W5100.send_data_processing(_socket, serialized, sizeof(ICMPEcho))
ICMPPing.cpp: In member function void ICMPPing::receiveEchoReply(const ICMPEcho&, const IPAddress&, ICMPEchoReply&)

ICMPPing.cpp: 207:19: error: 'class W5100Class' has no member named 'getRXReceivedSize
if (W5100.getRXReceivedSize(_socket) < 1)
Error compiling libraries

ICMPPing.cpp: 219:9: error: 'class W5100Class' has no member named 'read_data
W5100.read_data(_socket, (uint16_t) buffer, ipHeader, sizeof(ipHeader))
Build failed for project 'SecuritySystem'

ICMPPing.cpp: 229:9: error: 'class W5100Class' has no member named 'read_data
W5100.read_data(_socket, (uint16_t) buffer, serialized, dataLen)

Yea same issue here, had to revert to an older ethernet library.

me too, and revert to an older ethernet library is not an option

post my problem in this topic
https://forum.arduino.cc/index.php?topic=573949.0

who lands here then finds the solution