From 98386514e5d95dd0194f7593144da1a87dc584a8 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 24 Mar 2011 08:40:35 +0100 Subject: [PATCH] Use INET_ADDRSTRLEN instead of 16 --- owlps-aggregator/owlps-aggregator.h | 6 +++--- owlps-aggregator/owlps-aggregatord.c | 10 +++++----- owlps-client/owlps-client.c | 4 ++-- owlps-listener/owlps-listener.h | 4 ++-- owlps-listener/owlps-listenerd.c | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/owlps-aggregator/owlps-aggregator.h b/owlps-aggregator/owlps-aggregator.h index b9e2eef..822ca71 100644 --- a/owlps-aggregator/owlps-aggregator.h +++ b/owlps-aggregator/owlps-aggregator.h @@ -72,7 +72,7 @@ typedef struct _request_list typedef struct _ap_list { uint8_t mac_addr_bytes[6] ; - char ip_addr[16] ; + char ip_addr[INET_ADDRSTRLEN] ; owl_timestamp last_seen ; @@ -98,10 +98,10 @@ void print_request_info(request_info_list *info) ; #endif // DEBUG void* listen_for_aps(void *NULL_value) ; -void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[16]) ; +void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[INET_ADDRSTRLEN]) ; ap_list* find_ap(uint8_t mac_addr_bytes[6]) ; ap_list* add_ap_front(uint8_t mac_addr_bytes[6]) ; -void update_ap_ip_addr(ap_list *ap, char ip_addr[16]) ; +void update_ap_ip_addr(ap_list *ap, char ip_addr[INET_ADDRSTRLEN]) ; void update_ap_seen(ap_list *ap) ; void push_ap(ap_list *ap) ; diff --git a/owlps-aggregator/owlps-aggregatord.c b/owlps-aggregator/owlps-aggregatord.c index 1d5b828..d8e8a3b 100644 --- a/owlps-aggregator/owlps-aggregatord.c +++ b/owlps-aggregator/owlps-aggregatord.c @@ -814,7 +814,7 @@ void* listen_for_aps(void *NULL_value) struct sockaddr_in client; // UDP client structure socklen_t client_len = sizeof(client) ; // Size of clients owl_autocalibration_hello message ; - char ap_ip_addr[16] ; + char ap_ip_addr[INET_ADDRSTRLEN] ; #ifdef DEBUG fprintf(stderr, "Autocalibration Hello thread launched.\n") ; @@ -842,7 +842,7 @@ void* listen_for_aps(void *NULL_value) continue ; } - strncpy(ap_ip_addr, inet_ntoa(client.sin_addr), 16) ; + strncpy(ap_ip_addr, inet_ntoa(client.sin_addr), INET_ADDRSTRLEN) ; #ifdef DEBUG fprintf(stderr, "Got a Hello message from « %s »\n", @@ -863,7 +863,7 @@ void* listen_for_aps(void *NULL_value) * 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(uint8_t mac_addr_bytes[6], char ip_addr[16]) +void update_ap(uint8_t mac_addr_bytes[6], char ip_addr[INET_ADDRSTRLEN]) { ap_list *found ; @@ -924,9 +924,9 @@ ap_list* add_ap_front(uint8_t mac_addr_bytes[6]) /* * Change the IP address of the AP 'ap' with 'ip_addr'. */ -void update_ap_ip_addr(ap_list *ap, char ip_addr[16]) +void update_ap_ip_addr(ap_list *ap, char ip_addr[INET_ADDRSTRLEN]) { - strncpy(ap->ip_addr, ip_addr, 16) ; + strncpy(ap->ip_addr, ip_addr, INET_ADDRSTRLEN) ; } diff --git a/owlps-client/owlps-client.c b/owlps-client/owlps-client.c index 289a38e..75426e3 100644 --- a/owlps-client/owlps-client.c +++ b/owlps-client/owlps-client.c @@ -39,7 +39,7 @@ void print_usage(void) ; /* Options */ struct { - char dest_ip[16] ; // Destination IP of the packets + char dest_ip[INET_ADDRSTRLEN] ; // Destination IP of the packets uint_fast16_t dest_port ; char iface[IFNAMSIZ + 1] ; // Source network interface int_fast32_t delay ; // Time between two packet transmissions @@ -115,7 +115,7 @@ void parse_main_options(int argc, char **argv) switch (opt) { case 'd' : - strncpy(options.dest_ip, optarg, 16) ; + strncpy(options.dest_ip, optarg, INET_ADDRSTRLEN) ; break ; case 'h' : print_usage() ; diff --git a/owlps-listener/owlps-listener.h b/owlps-listener/owlps-listener.h index efb46a5..bf85999 100644 --- a/owlps-listener/owlps-listener.h +++ b/owlps-listener/owlps-listener.h @@ -189,7 +189,7 @@ void print_version(void) ; #define GET_MODE() \ (options.mode) #define SET_AGGREGATION_IP(IP) \ - (strncpy(options.aggregation_ip, (IP), 16)) + (strncpy(options.aggregation_ip, (IP), INET_ADDRSTRLEN)) #define GET_AGGREGATION_IP() \ (options.aggregation_ip) #ifdef USE_PTHREAD @@ -221,7 +221,7 @@ void print_version(void) ; #define GET_AUTOCALIBRATION() \ (options.autocalibration) #define SET_AUTOCALIBRATION_IP(IP) \ - (strncpy(options.autocalibration_ip, (IP), 16)) + (strncpy(options.autocalibration_ip, (IP), INET_ADDRSTRLEN)) #define GET_AUTOCALIBRATION_IP() \ (options.autocalibration_ip) #define SET_AUTOCALIBRATION_REQUEST_PORT(PORT) \ diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index b2ab9e6..e9bddb2 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -9,7 +9,7 @@ char *program_name = NULL ; uint8_t my_mac_bytes[6] ; // AP MAC address -char my_ip[16] ; // AP IP address +char my_ip[INET_ADDRSTRLEN] ; // AP IP address int aggregation_sockfd ; struct sockaddr_in aggregation_server ; @@ -25,7 +25,7 @@ cfg_t *cfg ; // Configuration structure */ struct { char mode ; - char aggregation_ip[16] ; + char aggregation_ip[INET_ADDRSTRLEN] ; uint_fast16_t aggregation_port ; uint_fast16_t listening_port ; #ifdef USE_PTHREAD @@ -35,7 +35,7 @@ struct { char wifi_iface[IFNAMSIZ + 1] ; #ifdef USE_PTHREAD owl_bool autocalibration ; - char autocalibration_ip[16] ; + char autocalibration_ip[INET_ADDRSTRLEN] ; uint_fast16_t autocalibration_request_port ; uint_fast16_t autocalibration_port ; uint_fast32_t autocalibration_hello_delay ; @@ -1001,7 +1001,7 @@ void get_mac_addr(char *eth, uint8_t mac_bytes[6]) /* * Get our own IP address and copy it to 'ip'. */ -void get_ip_addr(char *eth, char ip[16]) +void get_ip_addr(char *eth, char ip[INET_ADDRSTRLEN]) { struct ifreq ifr; int sockfd ; @@ -1022,7 +1022,7 @@ void get_ip_addr(char *eth, char ip[16]) memcpy(&ip_addr, &ifr.ifr_addr.sa_data[sizeof(sa.sin_port)], sizeof(ip_addr)) ; - strncpy(ip, inet_ntoa(ip_addr), 16) ; + strncpy(ip, inet_ntoa(ip_addr), INET_ADDRSTRLEN) ; }