How to programmatically PING from a MS C++ program?

I'd like to be able to PING from my MS C++ program.    I'd rather not do it by a command line and then parse the string response, because I think different language PCs emit a different text response, and I just need this to work on all PCs.   Ideally I want to call

int ms = Ping("192.168.1.20");

in my C++ program, and "ms" is the trip time that ping normally reports.   Or maybe I need a variant where I can set the timeout duration in ms, like:

int ms = Ping("192.168.1.20", 500);

I happen to know that this is pretty easily done in C# but I can't find how to do it from C++.
tullheadAsked:
Who is Participating?
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
0
 
Kevin StanushApplication DeveloperCommented:
I've never seen it done easily and usually involves a lot of low level code to do it.  There are several ways, including raw sockets (which requires admin rights and probably too low level), calling functions in ICMP.DLL, or calling functions in IpHlpApi.DLL.  The last one will let you selectively ping ipv4 or ipv6.

Search on CodeProject.com for some samples, depending on whether you are using C, C++ w/MFC, or a .NET variation.
1
 
tullheadAuthor Commented:
Shaun - that's exactly what I needed.  Thanks for tracking it down for me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.