[Aggregator] Refactor read_loop()

Create print_captured_request() out of read_loop().
This commit is contained in:
Matteo Cypriani 2013-06-12 17:59:03 -04:00
parent 0e913a2938
commit ef154b6d91
2 changed files with 58 additions and 50 deletions

View File

@ -108,6 +108,7 @@ int parse_command_line(int argc, char **argv) ;
int check_configuration(void) ; int check_configuration(void) ;
int read_loop(int sockfd) ; int read_loop(int sockfd) ;
void print_captured_request(const owl_captured_request *const request) ;
void got_request(owl_captured_request request) ; void got_request(owl_captured_request request) ;
void* monitor_requests(void *NULL_value) ; void* monitor_requests(void *NULL_value) ;

View File

@ -558,6 +558,22 @@ int read_loop(int sockfd)
request.nb_packets = ntohs(request.nb_packets) ; request.nb_packets = ntohs(request.nb_packets) ;
if (VERBOSE_REQUESTS) if (VERBOSE_REQUESTS)
print_captured_request(&request) ;
else if (VERBOSE_CHATTERBOX)
fprintf(stderr, "Request received from AP \"%s\".\n",
owl_mac_bytes_to_string(request.ap_mac_addr_bytes)) ;
got_request(request) ;
}
return ret ;
}
/*
* Prints an owl_captured_request on the standard error.
*/
void print_captured_request(const owl_captured_request *const request)
{ {
char char
request_time_str[OWL_TIMESTAMP_STRLEN], request_time_str[OWL_TIMESTAMP_STRLEN],
@ -566,15 +582,15 @@ int read_loop(int sockfd)
mobile_mac_addr_str[OWL_ETHER_ADDR_STRLEN], mobile_mac_addr_str[OWL_ETHER_ADDR_STRLEN],
mobile_ip_str[INET_ADDRSTRLEN] ; mobile_ip_str[INET_ADDRSTRLEN] ;
owl_timestamp_to_string(&request.request_time, assert(request) ;
request_time_str) ;
owl_timestamp_to_string(&request.capture_time, owl_timestamp_to_string(&request->request_time, request_time_str) ;
capture_time_str) ; owl_timestamp_to_string(&request->capture_time, capture_time_str) ;
owl_mac_bytes_to_string_r(request.ap_mac_addr_bytes, owl_mac_bytes_to_string_r(request->ap_mac_addr_bytes,
ap_mac_addr_str) ; ap_mac_addr_str) ;
owl_mac_bytes_to_string_r(request.mobile_mac_addr_bytes, owl_mac_bytes_to_string_r(request->mobile_mac_addr_bytes,
mobile_mac_addr_str) ; mobile_mac_addr_str) ;
inet_ntop(AF_INET, &request.mobile_ip_addr_bytes, inet_ntop(AF_INET, &request->mobile_ip_addr_bytes,
mobile_ip_str, INET_ADDRSTRLEN) ; mobile_ip_str, INET_ADDRSTRLEN) ;
fprintf(stderr, fprintf(stderr,
@ -593,30 +609,21 @@ int read_loop(int sockfd)
"\tDirection: %"PRIu8"\n" "\tDirection: %"PRIu8"\n"
"\tPacket number: %"PRIu16"/%"PRIu16"\n" "\tPacket number: %"PRIu16"/%"PRIu16"\n"
, ,
request.type, request->type,
ap_mac_addr_str, ap_mac_addr_str,
mobile_mac_addr_str, mobile_mac_addr_str,
mobile_ip_str, mobile_ip_str,
request_time_str, request_time_str,
capture_time_str, capture_time_str,
request.ss_dbm, request->ss_dbm,
request.x_position, request->x_position,
request.y_position, request->y_position,
request.z_position, request->z_position,
request.direction, request->direction,
request.packet_id, request->packet_id,
request.nb_packets request->nb_packets
) ; ) ;
} }
else if (VERBOSE_CHATTERBOX)
fprintf(stderr, "Request received from AP \"%s\".\n",
owl_mac_bytes_to_string(request.ap_mac_addr_bytes)) ;
got_request(request) ;
}
return ret ;
}
/* /*