diff --git a/src/liboping.c b/src/liboping.c index 5253e8c..21c4f98 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -1779,6 +1779,65 @@ pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter) return ((pingobj_iter_t *) iter->next); } +int ping_host_update_ident (pingobj_t *obj, const char *host) +{ + pinghost_t *pre, *cur, *target; + + if ((obj == NULL) || (host == NULL)) + return (-1); + + pre = NULL; + cur = obj->head; + + while (cur != NULL) + { + if (strcasecmp (host, cur->username) == 0) + break; + + pre = cur; + cur = cur->next; + } + + if (cur == NULL) + { + ping_set_error (obj, "ping_host_update_ident", "Host not found"); + return (-1); + } + + target = cur; + pre = NULL; + + cur = obj->table[target->ident % PING_TABLE_LEN]; + + while (cur != NULL) + { + if (cur == target) + break; + + pre = cur; + cur = cur->table_next; + } + + if (cur == NULL) + { + ping_set_error(obj, "ping_host_update_ident", "Host not found (T)"); + ping_free(target); + return (-1); + } + + if (pre == NULL) + obj->table[target->ident % PING_TABLE_LEN] = cur->table_next; + else + pre->table_next = cur->table_next; + + target->ident = ping_get_ident () & 0xFFFF; + + target->table_next = obj->table[target->ident % PING_TABLE_LEN]; + obj->table[target->ident % PING_TABLE_LEN] = target; + + return (0); +} + int ping_iterator_count (pingobj_t *obj) { if (obj == NULL) diff --git a/src/oping.c b/src/oping.c index c087c80..5ea8ebf 100644 --- a/src/oping.c +++ b/src/oping.c @@ -208,6 +208,7 @@ static char *opt_device = NULL; static char *opt_mark = NULL; static char *opt_filename = NULL; static int opt_count = -1; +static int opt_resetcount = -1; static int opt_send_ttl = 64; static uint8_t opt_send_qos = 0; #define OPING_DEFAULT_PERCENTILE 95.0 @@ -461,6 +462,7 @@ static void usage_exit (const char *name, int status) /* {{{ */ "\nAvailable options:\n" " -4|-6 force the use of IPv4 or IPv6\n" + " -C count number of ICMP requests in a flow (reset ICMP ID)\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" @@ -682,7 +684,7 @@ static int read_options (int argc, char **argv) /* {{{ */ while (1) { - optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:O:P:m:w:b" + optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:O:P:m:w:bC:" #if USE_NCURSES "uUg:H:" #endif @@ -698,6 +700,20 @@ static int read_options (int argc, char **argv) /* {{{ */ opt_addrfamily = (optchar == '4') ? AF_INET : AF_INET6; break; + case 'C': + { + int new_count; + new_count = atoi (optarg); + if (new_count > 0) + { + opt_resetcount = new_count; + } + else + fprintf(stderr, "Ignoring invalid count: %s\n", + optarg); + } + break; + case 'c': { int new_count; @@ -1790,6 +1806,7 @@ int main (int argc, char **argv) /* {{{ */ int optind; int i; + int opt_resetcount_loop; int status; #if _POSIX_SAVED_IDS uid_t saved_set_uid; @@ -2036,12 +2053,25 @@ int main (int argc, char **argv) /* {{{ */ perror ("sigaction"); return (1); } + opt_resetcount_loop = opt_resetcount; pre_loop_hook (ping); while (opt_count != 0) { int index; + if (opt_resetcount_loop > 0) + { + opt_resetcount_loop--; + if (opt_resetcount_loop == 0) + { + opt_resetcount_loop = opt_resetcount; + for (i = optind; i < argc; i++) + { + ping_host_update_ident (ping, argv[i]); + } + } + } if (gettimeofday (&tv_begin, NULL) < 0) { diff --git a/src/oping.h b/src/oping.h index ff144e8..3c4d38f 100644 --- a/src/oping.h +++ b/src/oping.h @@ -72,6 +72,7 @@ int ping_send (pingobj_t *obj); int ping_host_add (pingobj_t *obj, const char *host); int ping_host_remove (pingobj_t *obj, const char *host); +int ping_host_update_ident (pingobj_t *obj, const char *host); pingobj_iter_t *ping_iterator_get (pingobj_t *obj); pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter);