From: Florian Forster Date: Mon, 12 Jun 2006 20:48:54 +0000 (+0200) Subject: Updated the oping library to understand the `-I' option (bind to a specified address). X-Git-Tag: liboping-0.3.0~6 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6b629adbd538389a34eb07cb95ecced520b260ee;p=liboping.git Updated the oping library to understand the `-I' option (bind to a specified address). --- diff --git a/src/oping.c b/src/oping.c index 48f6db5..8bc119e 100644 --- a/src/oping.c +++ b/src/oping.c @@ -70,9 +70,10 @@ typedef struct ping_context double latency_total_square; } ping_context_t; -static double opt_interval = 1.0; -static int opt_addrfamily = PING_DEF_AF; -static int opt_count = -1; +static double opt_interval = 1.0; +static int opt_addrfamily = PING_DEF_AF; +static char *opt_srcaddr = NULL; +static int opt_count = -1; void sigint_handler (int signal) { @@ -115,7 +116,7 @@ int read_options (int argc, char **argv) while (1) { - optchar = getopt (argc, argv, "46c:hi:"); + optchar = getopt (argc, argv, "46c:hi:I:"); if (optchar == -1) break; @@ -144,6 +145,13 @@ int read_options (int argc, char **argv) opt_interval = new_interval; } break; + case 'I': + { + if (opt_srcaddr != NULL) + free (opt_srcaddr); + opt_srcaddr = strdup (optarg); + } + break; case 'h': default: @@ -294,6 +302,15 @@ int main (int argc, char **argv) if (opt_addrfamily != PING_DEF_AF) ping_setopt (ping, PING_OPT_AF, (void *) &opt_addrfamily); + if (opt_srcaddr != NULL) + { + if (ping_setopt (ping, PING_OPT_SOURCE, (void *) opt_srcaddr) != 0) + { + fprintf (stderr, "Setting source address failed: %s\n", + ping_get_error (ping)); + } + } + for (i = optind; i < argc; i++) { if (ping_host_add (ping, argv[i]) < 0)