Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <a href="http://en.wikipedia.org/wiki/Ping" rel="nofollow noreferrer">ping</a> tool is usually implemented in C and works by sending <a href="http://en.wikipedia.org/wiki/Internet_Control_Message_Protocol" rel="nofollow noreferrer">ICMP</a> <a href="http://en.wikipedia.org/wiki/Ping#Echo_request" rel="nofollow noreferrer">Echo request</a> packets over a <a href="http://en.wikipedia.org/wiki/Raw_socket" rel="nofollow noreferrer">raw socket</a>,. The system time is recorded -- usually with <a href="http://www.opengroup.org/onlinepubs/000095399/functions/gettimeofday.html" rel="nofollow noreferrer">gettimeofday</a> on under <a href="http://en.wikipedia.org/wiki/POSIX" rel="nofollow noreferrer">posix</a> -- when the Echo request is made and again when an <a href="http://en.wikipedia.org/wiki/Ping#Echo_reply" rel="nofollow noreferrer">Echo reply</a> (if any) is received to determine the round-trip time. You can put the same functionality in your C++ application using <a href="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#theory" rel="nofollow noreferrer">sockets</a>.</p> <p>Otherwise, extracting the information from a ping system call is probably easier than you think. The key is to open a <a href="http://en.wikipedia.org/wiki/Pipeline_(Unix)" rel="nofollow noreferrer">pipe</a> to allow reading of the <a href="http://en.wikipedia.org/wiki/Stdout#Standard_output_.28stdout.29" rel="nofollow noreferrer">standard output</a> of the ping command (see <a href="http://opengroup.org/onlinepubs/007908775/xsh/popen.html" rel="nofollow noreferrer"><code>popen</code></a> or <a href="http://msdn.microsoft.com/en-us/library/96ayss4b(VS.80).aspx" rel="nofollow noreferrer"><code>_popen</code></a>). A <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="nofollow noreferrer">regular expression</a> (e.g. "time=([0-9]*)") could be used to pluck out the desired data. If you don't have a regex library available, then extracting this data only requires fairly trivial string manipulation. The <a href="http://www.sgi.com/tech/stl/basic_string.html" rel="nofollow noreferrer">STL string class</a> provides several algorithms that may be of use.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload