[Client] Add option -s (packet size)

This commit is contained in:
Matteo Cypriani 2012-05-09 21:57:39 +02:00
parent 07f5b16ca0
commit 775687a1dc
1 changed files with 64 additions and 14 deletions

View File

@ -35,8 +35,11 @@
/* Delay between two requests in loop mode (in milliseconds) */
#define DEFAULT_FLOOD_DELAY 1000
/* Maximal size of a packet */
#define MAX_PKT_SIZE 1450u
/* Program arguments (getopt string) */
#define OPTIONS "DF::hi:I:l::n:p:t:V"
#define OPTIONS "DF::hi:I:l::n:p:s:t:V"
/* Function headers */
@ -49,8 +52,9 @@ void check_configuration(void) ;
void print_configuration(void) ;
#endif // DEBUG
void create_socket(void) ;
void make_packet(void) ;
void send_request(void) ;
void make_packet(void) ;
void add_padding(void) ;
#ifdef ENABLE_RECEIVE_POSITION
int receive_position(void) ;
#endif // ENABLE_RECEIVE_POSITION
@ -66,6 +70,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
uint_fast16_t pkt_size ; // Size of the packet to send
int_fast32_t flood_delay ; // Time between two request transmissions
uint_fast16_t listening_port ;
// Calibration data:
@ -74,15 +79,16 @@ struct {
float y ;
float z ;
} options = {
owl_false,
"",
OWL_DEFAULT_REQUEST_PORT,
"",
-1,
0,
-1,
0,
0, 0, 0, 0
owl_false, // daemon
"", // dest_ip
OWL_DEFAULT_REQUEST_PORT, // dest_port
"", // iface
-1, // delay
0, // nb_pkt
0, // pkt_size
-1, // flood_delay
0, // listening_port
0, 0, 0, 0 // Calibration data
} ;
char *program_name = NULL ;
@ -233,6 +239,9 @@ void parse_main_options(int argc, char **argv)
case 'p' :
options.dest_port = strtoul(optarg, NULL, 0) ;
break ;
case 's' :
options.pkt_size = strtoul(optarg, NULL, 0) ;
break ;
case 't' :
options.delay = strtol(optarg, NULL, 0) ;
break ;
@ -313,6 +322,17 @@ void check_configuration()
options.nb_pkt = DEFAULT_NBPKT_NORMAL ;
}
// Packet size too big
if (options.pkt_size > MAX_PKT_SIZE)
{
#ifdef DEBUG
fprintf(stderr,
"Warning! pkt_size cannot be greater than %hu bytes:"
" failing back to %hu.\n", MAX_PKT_SIZE, MAX_PKT_SIZE) ;
#endif // DEBUG
options.pkt_size = MAX_PKT_SIZE ;
}
// Calibration request but bad direction
if (is_calibration_request)
if (options.direction < OWL_DIRECTION_MIN ||
@ -456,6 +476,7 @@ void make_packet()
packet_size =
sizeof(uint8_t) * 2 + sizeof(owl_timestamp) + sizeof(float) * 3 +
sizeof(uint16_t) * 2 ;
add_padding() ;
packet = malloc(packet_size) ;
// Packet type:
@ -487,6 +508,7 @@ void make_packet()
memcpy(&packet[offset], &options.y, sizeof(float)) ;
offset += sizeof(float) ;
memcpy(&packet[offset], &options.z, sizeof(float)) ;
offset += sizeof(float) ;
// Convert the coordinates back to the host endianess (mandatory
// in flood mode):
options.x = owl_ntohf(options.x) ;
@ -501,6 +523,7 @@ void make_packet()
offset = 0 ;
packet_size =
sizeof(uint8_t) + sizeof(owl_timestamp) + sizeof(uint16_t) * 2 ;
add_padding() ;
packet = malloc(packet_size) ;
// Packet type:
@ -515,9 +538,28 @@ void make_packet()
offset += sizeof(uint16_t) ;
// Request time:
memcpy(&packet[offset], &request_time, sizeof(request_time)) ;
offset += sizeof(request_time) ;
}
printf("Packet timestamp: %s\n", request_time_str) ;
// Initialize padding bytes with 0xFF:
while (offset < packet_size)
packet[offset++] = 0xFF ;
printf("Packet timestamp: %s\n"
"Packet size: %"PRIuFAST16"\n",
request_time_str,
packet_size) ;
}
/*
* Increases the packet size to add padding.
*/
void add_padding()
{
if (options.pkt_size > packet_size)
packet_size = options.pkt_size ;
}
@ -561,9 +603,10 @@ void print_usage()
" -i dest_ip"
" [-p dest_port]"
" [-I iface]"
"\n\t"
" [-t delay]"
"\n\t"
" [-n nb_packets]"
" [-s packet_size]"
" [-F [delay] [-D]]"
" [-l [port]]\n"
"Calibration request:\n"
@ -571,9 +614,10 @@ void print_usage()
" -i dest_ip"
" [-p dest_port]"
" [-I iface]"
"\n\t"
" [-t delay]"
"\n\t"
" [-n nb_packets]"
" [-s packet_size]"
" [-F [delay] [-D]]"
" direction x y z\n"
@ -590,6 +634,12 @@ void print_usage()
"\t-n nb_packets\tNumber of packet transmitted for the request"
" (default:\n\t\t\t%d for a normal request, %d for a"
" calibration request).\n"
"\t-s packet_size\tData size of the transmitted packets. The"
" minimal value\n\t\t\tis the size of the request's data"
" fields; if packet_size\n\t\t\tis less than this size, it is"
" ignored. Note that this\n\t\t\tsize does not take into"
" account the headers, so the\n\t\t\twhole 802.11 frame will be"
" bigger.\n"
"\t-I iface\tName of the network interface used to transmit the"
"\n\t\t\trequest (e.g. \"eth2\"). If this option is absent, the"
"\n\t\t\tinterface is selected automatically. You must be root"