[Aggregator] Handle AP IP address (from Hello)

This commit is contained in:
Matteo Cypriani 2010-10-14 12:05:11 +02:00
parent fe0ea4bcdc
commit 074cd5a27a
2 changed files with 18 additions and 8 deletions

View File

@ -67,6 +67,7 @@ typedef struct _couple_list
typedef struct _ap_list
{
unsigned char mac_addr_bytes[6] ;
char ip_addr[16] ;
struct timeval last_seen ;
@ -92,9 +93,10 @@ void print_couple_info(couple_info_list *info) ;
#endif // DEBUG
void listen_for_aps(void) ;
void update_ap(unsigned char mac_addr_bytes[6]) ;
void update_ap(unsigned char mac_addr_bytes[6], char ip_addr[16]) ;
ap_list* find_ap(unsigned char mac_addr_bytes[6]) ;
void add_ap_front(unsigned char mac_addr_bytes[6]) ;
ap_list* add_ap_front(unsigned char mac_addr_bytes[6]) ;
void update_ap_ip_addr(ap_list *ap, char ip_addr[16]) ;
void update_ap_seen(ap_list *ap) ;
void push_ap(ap_list *ap) ;

View File

@ -630,7 +630,6 @@ void listen_for_aps(void)
struct sockaddr_in client; // UDP client structure
socklen_t client_len = sizeof(client) ; // Size of clients
autocalibration_hello message ;
unsigned char ap_mac_addr_bytes[6] ;
listen_sockfd =
create_udp_listening_socket(cfg_getint(cfg,
@ -654,8 +653,7 @@ void listen_for_aps(void)
continue ;
}
memcpy(&ap_mac_addr_bytes, message.ap_mac_addr_bytes, 6) ;
update_ap(ap_mac_addr_bytes) ;
update_ap(message.ap_mac_addr_bytes, message.ap_ip_addr) ;
}
(void) close(listen_sockfd) ;
@ -667,12 +665,15 @@ 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_addr_bytes[6])
void update_ap(unsigned char mac_addr_bytes[6], char ip_addr[16])
{
ap_list *found ;
if ((found = find_ap(mac_addr_bytes)) == NULL)
add_ap_front(mac_addr_bytes) ;
{
ap_list *new_ap = add_ap_front(mac_addr_bytes) ;
update_ap_ip_addr(new_ap, ip_addr) ;
}
else
update_ap_seen(found) ;
@ -699,13 +700,20 @@ ap_list* find_ap(unsigned char mac_addr_bytes[6])
/* Adds a new AP in front of the AP list. */
inline void add_ap_front(unsigned char mac_addr_bytes[6])
inline ap_list* add_ap_front(unsigned char mac_addr_bytes[6])
{
ap_list *ap = malloc(sizeof(ap_list)) ;
memcpy(ap->mac_addr_bytes, mac_addr_bytes, 6) ;
update_ap_seen(ap) ;
push_ap(ap) ;
++nb_aps ;
return ap ;
}
inline void update_ap_ip_addr(ap_list *ap, char ip_addr[16])
{
strncpy(ap->ip_addr, ip_addr, 16) ;
}