[lib] Add timestamp_now()

Use the new function timestamp_now() everywhere instead of
gettimeofday().
This commit is contained in:
Matteo Cypriani 2011-03-10 15:04:12 +01:00
parent ff81d43cb1
commit db8f6dff22
6 changed files with 20 additions and 8 deletions

View File

@ -426,7 +426,7 @@ void* monitor_couples()
couple_ptr = couples ;
couple_prev = NULL ;
couple_info_ptr = NULL ;
gettimeofday(&current_time, NULL) ;
timestamp_now(&current_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) >

View File

@ -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
{

View File

@ -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",

View File

@ -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.
*/

View File

@ -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) ;

View File

@ -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.
}