projects
/
liboping.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branches 'mark' and 'timeout'
[liboping.git]
/
src
/
oping.c
diff --git
a/src/oping.c
b/src/oping.c
index
5442d60
..
6263a4d
100644
(file)
--- a/
src/oping.c
+++ b/
src/oping.c
@@
-192,6
+192,7
@@
typedef struct ping_context
} ping_context_t;
static double opt_interval = 1.0;
} 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 int opt_addrfamily = PING_DEF_AF;
static char *opt_srcaddr = NULL;
static char *opt_device = NULL;
@@
-431,6
+432,7
@@
static void usage_exit (const char *name, int status) /* {{{ */
" -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"
" -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"
" -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"
@@
-647,7
+649,7
@@
static int read_options (int argc, char **argv) /* {{{ */
while (1)
{
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:m:
w:
"
#if USE_NCURSES
"uUg:"
#endif
#if USE_NCURSES
"uUg:"
#endif
@@
-700,6
+702,18
@@
static int read_options (int argc, char **argv) /* {{{ */
}
break;
}
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)
case 'I':
{
if (opt_srcaddr != NULL)
@@
-1670,7
+1684,7
@@
int main (int argc, char **argv) /* {{{ */
}
#endif
}
#endif
-
setlocale(LC_ALL, "");
+ setlocale(LC_ALL, "");
optind = read_options (argc, argv);
#if !_POSIX_SAVED_IDS
optind = read_options (argc, argv);
#if !_POSIX_SAVED_IDS
@@
-1721,6
+1735,12
@@
int main (int argc, char **argv) /* {{{ */
/* printf ("ts_int = %i.%09li\n", (int) ts_int.tv_sec, ts_int.tv_nsec); */
}
/* 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_addrfamily != PING_DEF_AF)
ping_setopt (ping, PING_OPT_AF, (void *) &opt_addrfamily);