diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c index fdf630c..7bd840c 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c @@ -426,7 +426,7 @@ void* monitor_couples() couple_ptr = couples ; couple_prev = NULL ; couple_info_ptr = NULL ; - gettimeofday(¤t_time, NULL) ; + timestamp_now(¤t_time) ; while (couple_ptr != NULL) // Parsing list { @@ -562,7 +562,7 @@ void got_couple_info(couple_message message) couple_info_list *tmp_info = NULL ; TIMESTAMP start_time ; // Reception time on the aggregator - gettimeofday(&start_time, NULL) ; + timestamp_now(&start_time) ; /* Create a new couple */ tmp_info = malloc(sizeof(couple_info_list)) ; @@ -821,7 +821,7 @@ void update_ap_ip_addr(ap_list *ap, char ip_addr[16]) void update_ap_seen(ap_list *ap) { assert(ap) ; - gettimeofday(&ap->last_seen, NULL) ; + timestamp_now(&ap->last_seen) ; } @@ -885,7 +885,7 @@ void delete_old_aps() { TIMESTAMP now ; - gettimeofday(&now, NULL) ; + timestamp_now(&now) ; while (token_aps != NULL) if (time_elapsed(token_aps->last_seen, now) > diff --git a/infrastructure-centred/owlps-client/owlps-client.c b/infrastructure-centred/owlps-client/owlps-client.c index 1106f3c..28394f7 100644 --- a/infrastructure-centred/owlps-client/owlps-client.c +++ b/infrastructure-centred/owlps-client/owlps-client.c @@ -286,7 +286,7 @@ void make_packet() int offset ; // Index used to create the packet TIMESTAMP request_time ; - gettimeofday(&request_time, NULL) ; + timestamp_now(&request_time) ; if (is_calibration_request) // Calibration packet { diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index 43dbdea..12ea447 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -1025,7 +1025,7 @@ int make_packet(char **packet) int size ; // Packet size TIMESTAMP request_time ; - gettimeofday(&request_time, NULL) ; + timestamp_now(&request_time) ; if (GET_VERBOSE()) printf("Autocalibration time: %llu\n", diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index 6f2d69f..149af98 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -90,6 +90,17 @@ char frequency_to_channel(unsigned short channel) +/* + * Set the TIMESTAMP 'now' at the current time. + */ +void timestamp_now(TIMESTAMP *now) +{ + if (gettimeofday(now, NULL)) + perror("Cannot get the current time") ; +} + + + /* * Converts a TIMESTAMP date value into milliseconds. */ diff --git a/libowlps/owlps.h b/libowlps/owlps.h index b239bd2..c6ab664 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -223,6 +223,7 @@ BOOL mac_equals(unsigned char *mac1, unsigned char *mac2) ; char frequency_to_channel(unsigned short channel) ; // Time +void timestamp_now(TIMESTAMP *now) ; unsigned long long timestamp_to_ms(TIMESTAMP date) ; unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ; diff --git a/mobile-centred/librtapscanmob/librtapscanmob.c b/mobile-centred/librtapscanmob/librtapscanmob.c index 539d8de..98ad5e9 100644 --- a/mobile-centred/librtapscanmob/librtapscanmob.c +++ b/mobile-centred/librtapscanmob/librtapscanmob.c @@ -40,13 +40,13 @@ int capture(char *capture_iface, unsigned long capture_time, mac_list **results, if (capture_time > 0) // Si le temps de capture est positif { - gettimeofday(&tbegin, NULL) ; // Récupère l'heure courante (heure du lancement de la capture) + timestamp_now(&tbegin) ; // Récupère l'heure courante (heure du lancement de la capture) while (run) { pcap_loop(handle, 1, got_packet, NULL) ; // Collecte 1 paquet et appelle la fonction got_packet quand pcaploop a recupéré des paquets - gettimeofday(&tcurrent, NULL) ; // Récupère l'heure courante + timestamp_now(&tcurrent) ; // Récupère l'heure courante if (time_elapsed(tcurrent, tbegin) > capture_time) // Si le temps de capture est écoulé break ; // on arrête la collecte. }