[Aggregator] Refactoring

This commit is contained in:
Matteo Cypriani 2010-10-12 15:09:14 +02:00
parent d51f136d70
commit 4b2fbf3188
2 changed files with 20 additions and 17 deletions

View File

@ -66,7 +66,8 @@ typedef struct _couple_list
/* Linked list of the known APs */ /* Linked list of the known APs */
typedef struct _ap_list typedef struct _ap_list
{ {
unsigned char mac_address_bytes[6] ; unsigned char mac_addr_bytes[6] ;
struct timeval last_seen ; struct timeval last_seen ;
struct _ap_list *previous ; struct _ap_list *previous ;
@ -91,9 +92,9 @@ void print_couple_info(couple_info_list *info) ;
#endif // DEBUG #endif // DEBUG
void listen_for_aps(void) ; void listen_for_aps(void) ;
void update_ap(unsigned char mac_address_bytes[6]) ; void update_ap(unsigned char mac_addr_bytes[6]) ;
ap_list* find_ap(unsigned char mac_address_bytes[6]) ; ap_list* find_ap(unsigned char mac_addr_bytes[6]) ;
void add_ap_front(unsigned char mac_address_bytes[6]) ; void add_ap_front(unsigned char mac_addr_bytes[6]) ;
void update_ap_seen(ap_list *ap) ; void update_ap_seen(ap_list *ap) ;
void push_ap(ap_list *ap) ; void push_ap(ap_list *ap) ;

View File

@ -667,12 +667,12 @@ void listen_for_aps(void)
* Updates the timestamp of the AP with the given MAC address if it is in * Updates the timestamp of the AP with the given MAC address if it is in
* the AP list, or add a new AP with this MAC address to the AP list. * the AP list, or add a new AP with this MAC address to the AP list.
*/ */
void update_ap(unsigned char mac_address_bytes[6]) void update_ap(unsigned char mac_addr_bytes[6])
{ {
ap_list *found ; ap_list *found ;
if ((found = find_ap(mac_address_bytes)) == NULL) if ((found = find_ap(mac_addr_bytes)) == NULL)
add_ap_front(mac_address_bytes) ; add_ap_front(mac_addr_bytes) ;
else else
update_ap_seen(found) ; update_ap_seen(found) ;
@ -683,13 +683,13 @@ void update_ap(unsigned char mac_address_bytes[6])
* Searches the AP list for an AP with the given MAC address and returns * Searches the AP list for an AP with the given MAC address and returns
* it. * it.
*/ */
ap_list* find_ap(unsigned char mac_address_bytes[6]) ap_list* find_ap(unsigned char mac_addr_bytes[6])
{ {
ap_list *found = aps ; ap_list *found = aps ;
while (found != NULL) while (found != NULL)
{ {
if (mac_cmp(found->mac_address_bytes, mac_address_bytes)) if (mac_cmp(found->mac_addr_bytes, mac_addr_bytes))
return found ; return found ;
found = found->next ; found = found->next ;
} }
@ -699,10 +699,10 @@ ap_list* find_ap(unsigned char mac_address_bytes[6])
/* Adds a new AP in front of the AP list. */ /* Adds a new AP in front of the AP list. */
inline void add_ap_front(unsigned char mac_address_bytes[6]) inline void add_ap_front(unsigned char mac_addr_bytes[6])
{ {
ap_list *ap = malloc(sizeof(ap_list)) ; ap_list *ap = malloc(sizeof(ap_list)) ;
memcpy(ap->mac_address_bytes, mac_address_bytes, 6) ; memcpy(ap->mac_addr_bytes, mac_addr_bytes, 6) ;
update_ap_seen(ap) ; update_ap_seen(ap) ;
push_ap(ap) ; push_ap(ap) ;
++nb_aps ; ++nb_aps ;
@ -894,21 +894,23 @@ void print_couple_info(couple_info_list *info)
char* ip_bytes_to_string(unsigned char *ip_binary) char* ip_bytes_to_string(unsigned char *ip_binary)
{ {
int int
taille = 16, size = 16,
i = 0 ; i = 0 ;
for (i = 0 ; i < 4 ; ++i) for (i = 0 ; i < 4 ; ++i)
{ {
if (ip_binary[i] < 0x64) if (ip_binary[i] < 0x64)
taille-- ; size-- ;
if (ip_binary[i] < 0x10) if (ip_binary[i] < 0x10)
taille-- ; size-- ;
} }
char *ret = malloc(sizeof(char) * taille) ; char *ret = malloc(sizeof(char) * size) ;
sprintf(ret, "%d.%d.%d.%d", ip_binary[0], ip_binary[1], ip_binary[2], ip_binary[3]) ; sprintf(ret, "%d.%d.%d.%d",
ret[taille-1] = '\0' ; ip_binary[0], ip_binary[1],
ip_binary[2], ip_binary[3]) ;
ret[size-1] = '\0' ;
return ret ; return ret ;
} }