Skip to content

Commit

Permalink
Support for quiet mode
Browse files Browse the repository at this point in the history
New option -q is introduced. If option is used, only state
changes are displayed, but not received packets. Option
can be used multiple times and then even state changes
are not displayed.

Resolves: tt#10
  • Loading branch information
jfriesse committed Dec 16, 2010
1 parent 80f5a1c commit f0b4634
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
12 changes: 8 additions & 4 deletions cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ static void usage();
* be 0. mcast_addr will be filled by requested mcast address or will be NULL. Port will be filled
* by requested port (string value) or will be NULL. ai_list will be initialized and requested
* hostnames will be stored there. ttl is pointer where user set TTL or default TTL will be stored.
* single_addr is boolean set if only one remote address is entered.
* single_addr is boolean set if only one remote address is entered. quiet is flag for quiet mode.
*/
int
cli_parse(struct ai_list *ai_list, int argc, char * const argv[], char **local_ifname, int *ip_ver,
struct ai_item *local_addr, int *wait_time, enum sf_transport_method *transport_method,
struct ai_item *mcast_addr, uint16_t *port, uint8_t *ttl, int *single_addr)
struct ai_item *mcast_addr, uint16_t *port, uint8_t *ttl, int *single_addr, int *quiet)
{
struct ai_item *ai_item;
struct ifaddrs *ifa_list, *ifa_local;
Expand All @@ -82,13 +82,14 @@ cli_parse(struct ai_list *ai_list, int argc, char * const argv[], char **local_i
*wait_time = DEFAULT_WAIT_TIME;
*ttl = DEFAULT_TTL;
*single_addr = 0;
*quiet = 0;
*transport_method = SF_TM_ASM;
port_s = DEFAULT_PORT_S;
force = 0;

logging_set_verbose(0);

while ((ch = getopt(argc, argv, "46FVvi:M:m:p:t:")) != -1) {
while ((ch = getopt(argc, argv, "46FqVvi:M:m:p:t:")) != -1) {
switch (ch) {
case '4':
*ip_ver = 4;
Expand All @@ -99,6 +100,9 @@ cli_parse(struct ai_list *ai_list, int argc, char * const argv[], char **local_i
case 'F':
force++;
break;
case 'q':
(*quiet)++;
break;
case 'V':
show_version();
exit(0);
Expand Down Expand Up @@ -591,7 +595,7 @@ static void
usage()
{

printf("usage: %s [-46FVv] [-i interval] [-M transport_method] [-m mcast_addr]\n",
printf("usage: %s [-46FqVv] [-i interval] [-M transport_method] [-m mcast_addr]\n",
PROGRAM_NAME);
printf(" [-p port] [-t ttl] remote_addr...\n");
}
2 changes: 1 addition & 1 deletion cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern "C" {
extern int cli_parse(struct ai_list *ai_list, int argc, char * const argv[],
char **local_ifname, int *ip_ver, struct ai_item *local_addr, int *wait_time,
enum sf_transport_method *transport_method, struct ai_item *mcast_addr,
uint16_t *port, uint8_t *ttl, int *single_addr);
uint16_t *port, uint8_t *ttl, int *single_addr, int *quiet);

#ifdef __cplusplus
}
Expand Down
35 changes: 24 additions & 11 deletions omping.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct omping_instance {
int hn_max_len;
int ip_ver;
int mcast_socket;
int quiet;
int single_addr;
int ucast_socket;
int wait_time;
Expand Down Expand Up @@ -180,7 +181,8 @@ omping_instance_create(struct omping_instance *instance, int argc, char *argv[])

cli_parse(&instance->remote_addrs, argc, argv, &instance->local_ifname, &instance->ip_ver,
&instance->local_addr, &instance->wait_time, &instance->transport_method,
&instance->mcast_addr, &instance->port, &instance->ttl, &instance->single_addr);
&instance->mcast_addr, &instance->port, &instance->ttl, &instance->single_addr,
&instance->quiet);

rh_list_create(&instance->remote_hosts, &instance->remote_addrs);

Expand Down Expand Up @@ -512,8 +514,11 @@ omping_process_answer_msg(struct omping_instance *instance, const char *msg, siz
loss = (int)((1.0 - (float)received / (float)rh_item->client_info.seq_num) * 100.0);
}

print_packet_stats(rh_item->addr->host_name, instance->hn_max_len, msg_decoded->seq_num, 0,
msg_len, dist_set, dist, rtt_set, rtt, avg_rtt, loss, ucast);
if (instance->quiet == 0) {
print_packet_stats(rh_item->addr->host_name, instance->hn_max_len,
msg_decoded->seq_num, 0, msg_len, dist_set, dist, rtt_set, rtt, avg_rtt, loss,
ucast);
}

return (0);
}
Expand Down Expand Up @@ -665,8 +670,12 @@ omping_process_response_msg(struct omping_instance *instance, const char *msg, s
} else {
DEBUG_PRINTF("Client was not in query state. Put it to stop state");
rh_item->client_info.state = RH_CS_STOP;
print_client_state(rh_item->addr->host_name, instance->hn_max_len,
instance->transport_method, NULL, &rh_item->addr->sas, RH_CS_STOP);

if (instance->quiet < 2) {
print_client_state(rh_item->addr->host_name, instance->hn_max_len,
instance->transport_method, NULL, &rh_item->addr->sas,
RH_CS_STOP);
}
}

return (-5);
Expand Down Expand Up @@ -700,9 +709,11 @@ omping_process_response_msg(struct omping_instance *instance, const char *msg, s
if (old_cstate == RH_CS_INITIAL) {
rh_item->client_info.seq_num++;

print_client_state(rh_item->addr->host_name, instance->hn_max_len,
instance->transport_method, &instance->mcast_addr.sas, &rh_item->addr->sas,
RH_CS_QUERY);
if (instance->quiet < 2) {
print_client_state(rh_item->addr->host_name, instance->hn_max_len,
instance->transport_method, &instance->mcast_addr.sas,
&rh_item->addr->sas, RH_CS_QUERY);
}
}

return (ms_query(instance->ucast_socket, from, &instance->mcast_addr.sas,
Expand Down Expand Up @@ -732,9 +743,11 @@ omping_send_client_msgs(struct omping_instance *instance)
*/
if (util_time_absdiff(ci->last_init_ts, util_get_time()) >
DEFAULT_WAIT_TIME) {
print_client_state(remote_host->addr->host_name,
instance->hn_max_len, instance->transport_method, NULL,
&remote_host->addr->sas, RH_CS_INITIAL);
if (instance->quiet < 2) {
print_client_state(remote_host->addr->host_name,
instance->hn_max_len, instance->transport_method, NULL,
&remote_host->addr->sas, RH_CS_INITIAL);
}

send_res = ms_init(instance->ucast_socket, &remote_host->addr->sas,
&instance->mcast_addr.sas, ci->client_id, 0);
Expand Down

0 comments on commit f0b4634

Please sign in to comment.