[Client] Add option -f (flood mode)
This commit is contained in:
parent
f951ce95f2
commit
e705801bb1
|
@ -25,8 +25,11 @@
|
|||
#define DEFAULT_DELAY_CALIB 50000 // Calibration request
|
||||
#define DEFAULT_DELAY_NORMAL 25000 // Localisation request
|
||||
|
||||
/* Delay between two requests in loop mode (in milliseconds) */
|
||||
#define DEFAULT_FLOOD_DELAY 1000
|
||||
|
||||
/* Program arguments (getopt string) */
|
||||
#define OPTIONS "d:hi:l::n:p:t:V"
|
||||
#define OPTIONS "d:f::hi:l::n:p:t:V"
|
||||
|
||||
|
||||
/* Function headers */
|
||||
|
@ -53,6 +56,7 @@ struct {
|
|||
char iface[IFNAMSIZ + 1] ; // Source network interface
|
||||
int_fast32_t delay ; // Time between two packet transmissions
|
||||
uint_fast16_t nb_pkt ; // Number of packets to send
|
||||
int_fast32_t flood_delay ; // Time between two request transmissions
|
||||
uint_fast16_t listening_port ;
|
||||
// Calibration data:
|
||||
owl_direction direction ;
|
||||
|
@ -65,6 +69,7 @@ struct {
|
|||
"",
|
||||
-1,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
0, 0, 0, 0
|
||||
} ;
|
||||
|
@ -88,10 +93,18 @@ int main(int argc, char *argv[])
|
|||
parse_command_line(argc, argv) ;
|
||||
|
||||
create_socket() ;
|
||||
|
||||
request_transmission:
|
||||
make_packet() ;
|
||||
send_request() ;
|
||||
|
||||
free(packet) ;
|
||||
|
||||
if (options.flood_delay >= 0)
|
||||
{
|
||||
usleep(options.flood_delay * 1000) ;
|
||||
goto request_transmission ;
|
||||
}
|
||||
|
||||
close(sockfd) ;
|
||||
|
||||
if (options.listening_port > 0)
|
||||
|
@ -127,6 +140,28 @@ void parse_main_options(int argc, char **argv)
|
|||
case 'd' :
|
||||
strncpy(options.dest_ip, optarg, INET_ADDRSTRLEN) ;
|
||||
break ;
|
||||
case 'f' :
|
||||
/* Facultative getopt options do not handle separated values
|
||||
* (like -f <delay>), so we have to test separately.
|
||||
*/
|
||||
if (optarg) // We got an option like -f<delay>, it's OK
|
||||
options.flood_delay = strtoul(optarg, NULL, 0) ;
|
||||
else // We got -f alone or -f <port>
|
||||
{
|
||||
/* If we are at the end of the string, or the next optind
|
||||
* is an option, we have the option without argument */
|
||||
if (argv[optind] == NULL || argv[optind][0] == '-')
|
||||
// Take the default value:
|
||||
options.flood_delay = DEFAULT_FLOOD_DELAY ;
|
||||
else
|
||||
{
|
||||
// Take the optind value:
|
||||
options.flood_delay =
|
||||
strtoul(argv[optind], NULL, 0) ;
|
||||
optind++ ;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
case 'h' :
|
||||
print_usage() ;
|
||||
exit(0) ;
|
||||
|
@ -275,7 +310,17 @@ void check_configuration()
|
|||
#ifdef DEBUG
|
||||
fprintf(stderr, "Warning! You cannot wait for a server answer when"
|
||||
" you calibrate. Option -l ignored…\n") ;
|
||||
#endif // DEBUG
|
||||
#endif // DEBUG
|
||||
options.listening_port = 0 ;
|
||||
}
|
||||
|
||||
// We want to flood AND to be located, which is not allowed:
|
||||
if (options.flood_delay >= 0 && options.listening_port > 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Warning! You cannot wait for a server answer when"
|
||||
" you flood. Option -l ignored…\n") ;
|
||||
#endif // DEBUG
|
||||
options.listening_port = 0 ;
|
||||
}
|
||||
}
|
||||
|
@ -289,8 +334,9 @@ void print_configuration()
|
|||
"\tDestination IP: %s\n"
|
||||
"\tDestination port: %"PRIuFAST16"\n"
|
||||
"\tInterface: %s\n"
|
||||
"\tDelay: %"PRIuFAST32"\n"
|
||||
"\tDelay: %"PRIdFAST32"\n"
|
||||
"\tNumber of packets: %"PRIuFAST16"\n"
|
||||
"\tFlood delay: %"PRIdFAST32"\n"
|
||||
"\tListening port: %"PRIuFAST16"\n"
|
||||
"\tDirection: %"PRIu8"\n"
|
||||
"\tX: %f\n"
|
||||
|
@ -302,6 +348,7 @@ void print_configuration()
|
|||
options.iface,
|
||||
options.delay,
|
||||
options.nb_pkt,
|
||||
options.flood_delay,
|
||||
options.listening_port,
|
||||
options.direction,
|
||||
options.x,
|
||||
|
@ -406,7 +453,7 @@ void print_usage()
|
|||
printf("Usage:\n"
|
||||
"Localisation request:\n"
|
||||
"\t%s -d dest_ip [-p dest_port] [-i iface] [-t delay]"
|
||||
" [-n nb_packets] [-l [port]]\n"
|
||||
" [-n nb_packets] [-f [delay]] [-l [port]]\n"
|
||||
"Calibration request:\n"
|
||||
"\t%s -d dest_ip [-p dest_port] [-i iface] [-t delay]"
|
||||
" [-n nb_packets] direction x y z\n"
|
||||
|
@ -414,7 +461,8 @@ void print_usage()
|
|||
"Options:\n"
|
||||
"\t-h\t\tPrint this help.\n"
|
||||
"\t-V\t\tPrint version information.\n"
|
||||
"\t-d dest_ip\tDestination IP address of the localisation request.\n"
|
||||
"\t-d dest_ip\tDestination IP address of the localisation"
|
||||
" request.\n"
|
||||
"\t-p dest_port\tDestination port of the localisation request"
|
||||
" (default: %d).\n"
|
||||
"\t-t delay\tTime between each packet transmission (default: %d"
|
||||
|
@ -426,8 +474,10 @@ void print_usage()
|
|||
" request (e.g. \"eth2\"). If this option is absent, interface"
|
||||
" is selected automatically. You must be root to use this"
|
||||
" option.\n"
|
||||
"\t-f [delay]\t\"Flood mode\": loop undefinitely, sending a"
|
||||
" new request every <delay> milliseconds (default: %d ms).\n"
|
||||
"\t-l [port]\tWait for the computed position and display it."
|
||||
" Optional argument 'port' allows to specify the listening"
|
||||
" The Optional argument <port> allows to specify the listening"
|
||||
" port (default: %d).\n"
|
||||
,
|
||||
program_name,
|
||||
|
@ -437,6 +487,7 @@ void print_usage()
|
|||
DEFAULT_DELAY_CALIB,
|
||||
DEFAULT_NBPKT_NORMAL,
|
||||
DEFAULT_NBPKT_CALIB,
|
||||
DEFAULT_FLOOD_DELAY,
|
||||
MOBILE_DEFAULT_PORT
|
||||
) ;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue