X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Foping.c;h=d4469a8f94f4744a4f5e77c8e40f62c44354b39a;hb=33a84dc3dca4be5fe92061153277eb5df8a54e7f;hp=48f6db51886a5fe323f30756011f418959a51ce2;hpb=aad7132669a318c360102c353bbad1f445d9a7fc;p=liboping.git diff --git a/src/oping.c b/src/oping.c index 48f6db5..d4469a8 100644 --- a/src/oping.c +++ b/src/oping.c @@ -4,8 +4,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * the Free Software Foundation; only version 2 of the License is + * applicable. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -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) @@ -355,7 +372,8 @@ int main (int argc, char **argv) if (ping_send (ping) < 0) { - fprintf (stderr, "ping_send failed\n"); + fprintf (stderr, "ping_send failed: %s\n", + ping_get_error (ping)); return (1); }