programatic ping from C++

How can you do a ping programatically from Visual C++ 4.1 using winsock ? Is there any other way of doing this without winsock ?
kandalaiAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
pradeConnect With a Mentor Commented:
Consider executing ping via a shell call from within your
program. Or you might port the UNIX sources of ping to WIndows.
(Wich shouldn't be too much work)

0
 
kandalaiAuthor Commented:
Thanks for the suggestion. But I can't really use the shell command. That's what I mean by 'ping programatically'. I have to do it using winsock from Visual C++, creating asynchronous sockets. This is all to know if a remote machine is up or down. I can attach my source code if you are interested. Please let me know.
0
 
pradeCommented:
if you only need to check if a machine is up, it would be enough to just try to connect to its ping port.
If the connection is refused, that machine is propably down.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
kandalaiAuthor Commented:
Is the ping port on all machines is the same as FTP etc. Can I make a socket and try connect to this port on the remote machine
and see if it lets me do that ? If so what standard ping port number I have to use while connecting ? Does it have to be a stream socket ? How does the whole thing work if connection less sockets (SOCK_DGRAM) are used ? Any literature or code available on this ? I appreciate your help. Thank You
0
 
pradeCommented:
yes you can. use the echo port
(not "ping port", ping uses something else than udp/tcp)
the echo port number is 7
(also to be found in your /etc/services)
you can use either stream or dgram sockets (tcp or udp)
it shouldn't matter.
0
 
kandalaiAuthor Commented:
Thank you very much. I will try this.
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.