diff --git a/libowlps-client/libowlps-client.c b/libowlps-client/libowlps-client.c index 0c0ef81..a1cb93f 100644 --- a/libowlps-client/libowlps-client.c +++ b/libowlps-client/libowlps-client.c @@ -103,25 +103,27 @@ void owl_use_iface(const int sockfd, const char *const iface) * @param[in] packet_size The buffer's size. * @param[in] nb_pkt Number of packets to transmit. * @param[in] delay Delay between two transmissions, in milliseconds. + * @param[in] verbose If `true`, a "progress bar" will be printed on the + * standard output. */ void owl_send_request(const int sockfd, const struct sockaddr_in *const server, const void *const packet, const uint_fast16_t packet_size, const uint_fast16_t nb_pkt, - const uint_fast32_t delay) + const uint_fast32_t delay, + const bool verbose) { uint_fast16_t i ; if (nb_pkt == 0 || !owl_run) return ; -#ifdef OWLPS_DEBUG - printf("Sent packets: ") ; -#endif // OWLPS_DEBUG + if (verbose) + printf("Sent packets: ") ; // Transmit first packet: - owl_send_packet(sockfd, server, packet, packet_size) ; + owl_send_packet(sockfd, server, packet, packet_size, verbose) ; // Transmit remaining packets (if any): for (i = 1 ; i < nb_pkt ; ++i) @@ -132,12 +134,11 @@ void owl_send_request(const int sockfd, break ; // Update the packet number: memcpy(&((char*) packet)[1], ¤t_pkt, sizeof(uint16_t)) ; - owl_send_packet(sockfd, server, packet, packet_size) ; + owl_send_packet(sockfd, server, packet, packet_size, verbose) ; } -#ifdef OWLPS_DEBUG - putchar('\n') ; -#endif // OWLPS_DEBUG + if (verbose) + putchar('\n') ; } @@ -146,11 +147,14 @@ void owl_send_request(const int sockfd, * Transmits a single packet of a request. * See the documentation of the `owl_send_request()` function for an * explanation on the parameters. + * When `verbose` if `true`, a dot will be printed on the standard output + * and the standard output will be flushed. */ void owl_send_packet(const int sockfd, const struct sockaddr_in *const server, const void *const packet, - const uint_fast16_t packet_size) + const uint_fast16_t packet_size, + const bool verbose) { ssize_t nsent = sendto(sockfd, packet, packet_size, 0, (struct sockaddr *) server, @@ -161,8 +165,9 @@ void owl_send_packet(const int sockfd, exit(OWL_ERR_SOCKET_SEND) ; } -#ifdef OWLPS_DEBUG - putchar('.') ; - fflush(stdout) ; -#endif // OWLPS_DEBUG + if (verbose) + { + putchar('.') ; + fflush(stdout) ; + } } diff --git a/libowlps-client/owlps-client.h b/libowlps-client/owlps-client.h index 01dbd53..b1cf8fc 100644 --- a/libowlps-client/owlps-client.h +++ b/libowlps-client/owlps-client.h @@ -40,11 +40,13 @@ void owl_send_request(const int sockfd, const void *const packet, const uint_fast16_t packet_size, const uint_fast16_t nb_pkt, - const uint_fast32_t delay) ; + const uint_fast32_t delay, + const bool verbose) ; void owl_send_packet(const int sockfd, const struct sockaddr_in *const server, const void *const packet, - const uint_fast16_t packet_size) ; + const uint_fast16_t packet_size, + const bool verbose) ; #endif // _LIBOWLPS_CLIENT_ diff --git a/owlps-client/owlps-client.c b/owlps-client/owlps-client.c index 3d0c66a..ea139ce 100644 --- a/owlps-client/owlps-client.c +++ b/owlps-client/owlps-client.c @@ -473,7 +473,7 @@ void send_request() { make_packet() ; owl_send_request(sockfd, &server, packet, packet_size, - options.nb_pkt, options.delay) ; + options.nb_pkt, options.delay, options.verbose) ; free(packet) ; } diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index 3c3a8ae..33a767d 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -1424,7 +1424,7 @@ void* autocalibrate_hello(void *NULL_value) while (owl_run) { owl_send_packet(send_sockfd, &serv, - &message, sizeof(message)) ; + &message, sizeof(message), VERBOSE_INFO) ; sleep(GET_AUTOCALIBRATION_HELLO_DELAY()) ; } @@ -1506,7 +1506,8 @@ void send_autocalibration_request() &autocalibration_send_server, packet, packet_size, GET_AUTOCALIBRATION_NBPKT(), - GET_AUTOCALIBRATION_DELAY()) ; + GET_AUTOCALIBRATION_DELAY(), + VERBOSE_INFO) ; free(packet) ; }