Merge branch 'ab/prettyping'
authorFlorian Forster <octo@verplant.org>
Wed, 24 Sep 2014 23:55:36 +0000 (16:55 -0700)
committerFlorian Forster <octo@verplant.org>
Wed, 24 Sep 2014 23:55:36 +0000 (16:55 -0700)
.gitignore
autogen.sh [new file with mode: 0755]
src/liboping.c
src/oping.c

index 8588514..e39f4fb 100644 (file)
@@ -35,3 +35,4 @@ src/noping
 *.o
 *.tar.gz
 *.tar.bz2
+bindings/perl/MYMETA.yml
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..f273d64
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+libtoolize
+aclocal -I m4
+autoheader
+automake --add-missing
+autoconf
+echo "autoconfiguration done, to build: ./configure ; make"
index 74122a8..40a0ba2 100644 (file)
@@ -637,6 +637,9 @@ static int ping_receive_one (pingobj_t *obj, const pinghost_t *ph,
        return (0);
 }
 
+/* Blocks until a packet was received from all hosts or the timeout is reached.
+ * When interrupted, (-EINTR) is returned. On error, -1 is returned. On
+ * success, returns zero. */
 static int ping_receive_all (pingobj_t *obj)
 {
        fd_set read_fds;
@@ -726,7 +729,8 @@ static int ping_receive_all (pingobj_t *obj)
                if ((status == -1) && (errno == EINTR))
                {
                        dprintf ("select was interrupted by signal..\n");
-                       continue;
+                       ping_set_errno (obj, EINTR);
+                       return (-EINTR);
                }
                else if (status < 0)
                {
@@ -764,7 +768,7 @@ static int ping_receive_all (pingobj_t *obj)
        } /* while (1) */
        
        return (ret);
-}
+} /* int ping_receive_all */
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Sending functions:                                                        *
@@ -1328,18 +1332,13 @@ int ping_setopt (pingobj_t *obj, int option, void *value)
 
 int ping_send (pingobj_t *obj)
 {
-       int ret;
-
        if (obj == NULL)
                return (-1);
 
        if (ping_send_all (obj) < 0)
                return (-1);
 
-       if ((ret = ping_receive_all (obj)) < 0)
-               return (-2);
-
-       return (ret);
+       return (ping_receive_all (obj));
 }
 
 static pinghost_t *ping_host_search (pinghost_t *ph, const char *host)
index 5c0ead5..b3beeb0 100644 (file)
@@ -128,6 +128,10 @@ static size_t const hist_colors_num = sizeof (hist_colors_utf8)
 # define _POSIX_SAVED_IDS 0
 #endif
 
+#ifndef IPTOS_MINCOST
+# define IPTOS_MINCOST 0x02
+#endif
+
 /* Remove GNU specific __attribute__ settings when using another compiler */
 #if !__GNUC__
 # define __attribute__(x) /**/
@@ -1402,7 +1406,12 @@ int main (int argc, char **argv) /* {{{ */
                        return (1);
                }
 
-               if (ping_send (ping) < 0)
+               status = ping_send (ping);
+               if (status == -EINTR)
+               {
+                       continue;
+               }
+               else if (status < 0)
                {
                        fprintf (stderr, "ping_send failed: %s\n",
                                        ping_get_error (ping));
@@ -1435,14 +1444,13 @@ int main (int argc, char **argv) /* {{{ */
                /* printf ("Sleeping for %i.%09li seconds\n", (int) ts_wait.tv_sec, ts_wait.tv_nsec); */
                while ((status = nanosleep (&ts_wait, &ts_wait)) != 0)
                {
-                       if (errno != EINTR)
+                       if (errno == EINTR)
                        {
-                               perror ("nanosleep");
-                               break;
+                               continue;
                        }
-                       else if (opt_count == 0)
+                       else
                        {
-                               /* sigint */
+                               perror ("nanosleep");
                                break;
                        }
                }