[Aggregator] Refactoring
This commit is contained in:
parent
d51f136d70
commit
4b2fbf3188
|
@ -66,7 +66,8 @@ typedef struct _couple_list
|
|||
/* Linked list of the known APs */
|
||||
typedef struct _ap_list
|
||||
{
|
||||
unsigned char mac_address_bytes[6] ;
|
||||
unsigned char mac_addr_bytes[6] ;
|
||||
|
||||
struct timeval last_seen ;
|
||||
|
||||
struct _ap_list *previous ;
|
||||
|
@ -91,9 +92,9 @@ void print_couple_info(couple_info_list *info) ;
|
|||
#endif // DEBUG
|
||||
|
||||
void listen_for_aps(void) ;
|
||||
void update_ap(unsigned char mac_address_bytes[6]) ;
|
||||
ap_list* find_ap(unsigned char mac_address_bytes[6]) ;
|
||||
void add_ap_front(unsigned char mac_address_bytes[6]) ;
|
||||
void update_ap(unsigned char mac_addr_bytes[6]) ;
|
||||
ap_list* find_ap(unsigned char mac_addr_bytes[6]) ;
|
||||
void add_ap_front(unsigned char mac_addr_bytes[6]) ;
|
||||
void update_ap_seen(ap_list *ap) ;
|
||||
void push_ap(ap_list *ap) ;
|
||||
|
||||
|
|
|
@ -667,12 +667,12 @@ void listen_for_aps(void)
|
|||
* 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.
|
||||
*/
|
||||
void update_ap(unsigned char mac_address_bytes[6])
|
||||
void update_ap(unsigned char mac_addr_bytes[6])
|
||||
{
|
||||
ap_list *found ;
|
||||
|
||||
if ((found = find_ap(mac_address_bytes)) == NULL)
|
||||
add_ap_front(mac_address_bytes) ;
|
||||
if ((found = find_ap(mac_addr_bytes)) == NULL)
|
||||
add_ap_front(mac_addr_bytes) ;
|
||||
|
||||
else
|
||||
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
|
||||
* 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 ;
|
||||
|
||||
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 ;
|
||||
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. */
|
||||
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)) ;
|
||||
memcpy(ap->mac_address_bytes, mac_address_bytes, 6) ;
|
||||
memcpy(ap->mac_addr_bytes, mac_addr_bytes, 6) ;
|
||||
update_ap_seen(ap) ;
|
||||
push_ap(ap) ;
|
||||
++nb_aps ;
|
||||
|
@ -894,21 +894,23 @@ void print_couple_info(couple_info_list *info)
|
|||
char* ip_bytes_to_string(unsigned char *ip_binary)
|
||||
{
|
||||
int
|
||||
taille = 16,
|
||||
size = 16,
|
||||
i = 0 ;
|
||||
|
||||
for (i = 0 ; i < 4 ; ++i)
|
||||
{
|
||||
if (ip_binary[i] < 0x64)
|
||||
taille-- ;
|
||||
size-- ;
|
||||
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]) ;
|
||||
ret[taille-1] = '\0' ;
|
||||
sprintf(ret, "%d.%d.%d.%d",
|
||||
ip_binary[0], ip_binary[1],
|
||||
ip_binary[2], ip_binary[3]) ;
|
||||
ret[size-1] = '\0' ;
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue