Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a small code that uses <a href="http://verplant.org/liboping/" rel="nofollow noreferrer">liboping</a> to ping www.xively.com every second and display the latency. You can install liboping static/dynamic library files and header files on your ubuntu box like so: <code>sudo apt-get install liboping0 liboping-dev oping</code></p> <p>Then compile the following program with the above library (<code>gcc -o test test.c -loping</code>). And run the executable as a super user (sudo).</p> <p><strong>test.c:</strong></p> <pre><code> /* * 1. install liboping, e.g. `sudo apt-get install liboping0 liboping-dev oping` * 2. Compile with -loping, e.g. `gcc -o test test.c -loping` * 3. Execute using sudo as super user, e.g. `sudo ./test` */ #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;oping.h&gt; int main(int argc, char **argv) { pingobj_t *ping; pingobj_iter_t *iter; if ((ping = ping_construct()) == NULL) { fprintf(stderr, "ping_construct failed\n"); return (-1); } printf("ping_construct() success\n"); if (ping_host_add(ping, "www.xively.com") &lt; 0) { const char * errmsg = ping_get_error(ping); fprintf(stderr, "ping_host_add(www.xively.com) failed. %s\n", errmsg); return (-1); } printf("ping_host_add() success\n"); while (1) { if (ping_send(ping) &lt; 0) { fprintf(stderr, "ping_send failed\n"); return (-1); } printf("ping_send() success\n"); for (iter = ping_iterator_get(ping); iter != NULL; iter = ping_iterator_next(iter)) { char hostname[100]; double latency; unsigned int len; printf("ping_iterator_get() success\n"); len = 100; ping_iterator_get_info(iter, PING_INFO_HOSTNAME, hostname, &amp;len); len = sizeof(double); ping_iterator_get_info(iter, PING_INFO_LATENCY, &amp;latency, &amp;len); printf("hostname = %s, latency = %f\n", hostname, latency); } sleep(1); } printf("exiting...\n"); ping_destroy( ping ); return 0; } </code></pre> <p><strong>Output:</strong></p> <pre><code>anurag@anurag-PC:~$ sudo ./test ping_construct() success ping_host_add() success ping_send() success ping_iterator_get() success hostname = www.xively.com, latency = 233.666000 ping_send() success ping_iterator_get() success hostname = www.xively.com, latency = 234.360000 ping_send() success ping_iterator_get() success hostname = www.xively.com, latency = 234.076000 ping_send() success ping_iterator_get() success hostname = www.xively.com, latency = 231.761000 ping_send() success ping_iterator_get() success hostname = www.xively.com, latency = 235.085000 ^C </code></pre> <p>liboping is good if you want to check for internet connectivity from your linux device provided your ISP or target does not block ICMP packets. If these are blocked, you can use some HTTP library to try and fetch the index.html page from www.google.com or any other website and check if that succeeds</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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