From 074cd5a27a5519147520fba66976242da90caeb1 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 14 Oct 2010 12:05:11 +0200 Subject: [PATCH] [Aggregator] Handle AP IP address (from Hello) --- .../owlps-aggregator/owlps-aggregator.h | 6 ++++-- .../owlps-aggregator/owlps-aggregatord.c | 20 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregator.h b/infrastructure-centred/owlps-aggregator/owlps-aggregator.h index 9f1f0ef..b0d8c6c 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregator.h +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregator.h @@ -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) ; diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c index 5d24b66..54d5ccb 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c @@ -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) ; }