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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Shaun VermaakTechnical SpecialistCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tullheadAuthor Commented:
Shaun - that's exactly what I needed.  Thanks for tracking it down for me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ping

From novice to tech pro — start learning today.