Code

Merge branches 'mark' and 'timeout'
authorFlorian Forster <ff@octo.it>
Fri, 13 Feb 2015 12:46:06 +0000 (13:46 +0100)
committerFlorian Forster <ff@octo.it>
Fri, 13 Feb 2015 12:46:06 +0000 (13:46 +0100)
1  2 
src/oping.c

diff --combined src/oping.c
index 5442d6039c29dc11557ed5b8b2a4c65cc6823bbb,3ae226c6f5e64d25e31d3ab3d960e0e673a8289f..6263a4def36459c7d94c8dbbb362cc89b56a9f6e
@@@ -192,10 -192,10 +192,11 @@@ typedef struct ping_contex
  } ping_context_t;
  
  static double  opt_interval   = 1.0;
+ static double  opt_timeout    = PING_DEF_TIMEOUT;
  static int     opt_addrfamily = PING_DEF_AF;
  static char   *opt_srcaddr    = NULL;
  static char   *opt_device     = NULL;
 +static char   *opt_mark       = NULL;
  static char   *opt_filename   = NULL;
  static int     opt_count      = -1;
  static int     opt_send_ttl   = 64;
@@@ -431,12 -431,12 +432,13 @@@ static void usage_exit (const char *nam
                        "  -4|-6        force the use of IPv4 or IPv6\n"
                        "  -c count     number of ICMP packets to send\n"
                        "  -i interval  interval with which to send ICMP packets\n"
+                       "  -w timeout   time to wait for replies, in seconds\n"
                        "  -t ttl       time to live for each ICMP packet\n"
                        "  -Q qos       Quality of Service (QoS) of outgoing packets\n"
                        "               Use \"-Q help\" for a list of valid options.\n"
                        "  -I srcaddr   source address\n"
                        "  -D device    outgoing interface name\n"
 +                      "  -m mark      mark to set on outgoing packets\n"
                        "  -f filename  filename to read hosts from\n"
  #if USE_NCURSES
                        "  -u / -U      force / disable UTF-8 output\n"
@@@ -647,7 -647,7 +649,7 @@@ static int read_options (int argc, cha
  
        while (1)
        {
-               optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:P:m:"
 -              optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:P:w:"
++              optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:P:m:w:"
  #if USE_NCURSES
                                "uUg:"
  #endif
                                }
                                break;
  
+                       case 'w':
+                               {
+                                       char *endp = NULL;
+                                       double t = strtod (optarg, &endp);
+                                       if ((optarg[0] != 0) && (endp != NULL) && (*endp == 0))
+                                               opt_timeout = t;
+                                       else
+                                               fprintf (stderr, "Ignoring invalid timeout: %s\n",
+                                                               optarg);
+                               }
+                               break;
                        case 'I':
                                {
                                        if (opt_srcaddr != NULL)
                                opt_device = optarg;
                                break;
  
 +                      case 'm':
 +                              opt_mark = optarg;
 +                              break;
 +
                        case 't':
                        {
                                int new_send_ttl;
@@@ -1670,7 -1678,7 +1684,7 @@@ int main (int argc, char **argv) /* {{
        }
  #endif
  
-         setlocale(LC_ALL, "");
+       setlocale(LC_ALL, "");
        optind = read_options (argc, argv);
  
  #if !_POSIX_SAVED_IDS
                /* printf ("ts_int = %i.%09li\n", (int) ts_int.tv_sec, ts_int.tv_nsec); */
        }
  
+       if (ping_setopt (ping, PING_OPT_TIMEOUT, (void*)(&opt_timeout)) != 0)
+       {
+               fprintf (stderr, "Setting timeout failed: %s\n",
+                               ping_get_error (ping));
+       }
        if (opt_addrfamily != PING_DEF_AF)
                ping_setopt (ping, PING_OPT_AF, (void *) &opt_addrfamily);
  
                }
        }
  
 +      if(opt_mark != NULL)
 +      {
 +              char *endp;
 +              int mark = strtoul(opt_mark, &endp, 0);
 +              if(opt_mark[0] != '\0' && *endp == '\0')
 +              {
 +                      if(ping_setopt(ping, PING_OPT_MARK, (void*)(&mark)) != 0)
 +                      {
 +                              fprintf (stderr, "Setting mark failed: %s\n",
 +                                      ping_get_error (ping));
 +                      }
 +              }
 +              else{
 +                      fprintf(stderr, "Ignoring invalid mark: %s\n", optarg);
 +              }
 +      }
 +
        if (opt_filename != NULL)
        {
                FILE *infile;