Skip to content

Add loop-reset count which causes the ICMP ID to update #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/liboping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 31 additions & 1 deletion src/oping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/oping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down