Use INET_ADDRSTRLEN instead of 16
This commit is contained in:
parent
f71a4650e2
commit
98386514e5
|
@ -72,7 +72,7 @@ typedef struct _request_list
|
||||||
typedef struct _ap_list
|
typedef struct _ap_list
|
||||||
{
|
{
|
||||||
uint8_t mac_addr_bytes[6] ;
|
uint8_t mac_addr_bytes[6] ;
|
||||||
char ip_addr[16] ;
|
char ip_addr[INET_ADDRSTRLEN] ;
|
||||||
|
|
||||||
owl_timestamp last_seen ;
|
owl_timestamp last_seen ;
|
||||||
|
|
||||||
|
@ -98,10 +98,10 @@ void print_request_info(request_info_list *info) ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
void* listen_for_aps(void *NULL_value) ;
|
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* find_ap(uint8_t mac_addr_bytes[6]) ;
|
||||||
ap_list* add_ap_front(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 update_ap_seen(ap_list *ap) ;
|
||||||
void push_ap(ap_list *ap) ;
|
void push_ap(ap_list *ap) ;
|
||||||
|
|
||||||
|
|
|
@ -814,7 +814,7 @@ void* listen_for_aps(void *NULL_value)
|
||||||
struct sockaddr_in client; // UDP client structure
|
struct sockaddr_in client; // UDP client structure
|
||||||
socklen_t client_len = sizeof(client) ; // Size of clients
|
socklen_t client_len = sizeof(client) ; // Size of clients
|
||||||
owl_autocalibration_hello message ;
|
owl_autocalibration_hello message ;
|
||||||
char ap_ip_addr[16] ;
|
char ap_ip_addr[INET_ADDRSTRLEN] ;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Autocalibration Hello thread launched.\n") ;
|
fprintf(stderr, "Autocalibration Hello thread launched.\n") ;
|
||||||
|
@ -842,7 +842,7 @@ void* listen_for_aps(void *NULL_value)
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ap_ip_addr, inet_ntoa(client.sin_addr), 16) ;
|
strncpy(ap_ip_addr, inet_ntoa(client.sin_addr), INET_ADDRSTRLEN) ;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Got a Hello message from « %s »\n",
|
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
|
* 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(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 ;
|
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'.
|
* 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) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ void print_usage(void) ;
|
||||||
|
|
||||||
/* Options */
|
/* Options */
|
||||||
struct {
|
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 ;
|
uint_fast16_t dest_port ;
|
||||||
char iface[IFNAMSIZ + 1] ; // Source network interface
|
char iface[IFNAMSIZ + 1] ; // Source network interface
|
||||||
int_fast32_t delay ; // Time between two packet transmissions
|
int_fast32_t delay ; // Time between two packet transmissions
|
||||||
|
@ -115,7 +115,7 @@ void parse_main_options(int argc, char **argv)
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
case 'd' :
|
case 'd' :
|
||||||
strncpy(options.dest_ip, optarg, 16) ;
|
strncpy(options.dest_ip, optarg, INET_ADDRSTRLEN) ;
|
||||||
break ;
|
break ;
|
||||||
case 'h' :
|
case 'h' :
|
||||||
print_usage() ;
|
print_usage() ;
|
||||||
|
|
|
@ -189,7 +189,7 @@ void print_version(void) ;
|
||||||
#define GET_MODE() \
|
#define GET_MODE() \
|
||||||
(options.mode)
|
(options.mode)
|
||||||
#define SET_AGGREGATION_IP(IP) \
|
#define SET_AGGREGATION_IP(IP) \
|
||||||
(strncpy(options.aggregation_ip, (IP), 16))
|
(strncpy(options.aggregation_ip, (IP), INET_ADDRSTRLEN))
|
||||||
#define GET_AGGREGATION_IP() \
|
#define GET_AGGREGATION_IP() \
|
||||||
(options.aggregation_ip)
|
(options.aggregation_ip)
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
|
@ -221,7 +221,7 @@ void print_version(void) ;
|
||||||
#define GET_AUTOCALIBRATION() \
|
#define GET_AUTOCALIBRATION() \
|
||||||
(options.autocalibration)
|
(options.autocalibration)
|
||||||
#define SET_AUTOCALIBRATION_IP(IP) \
|
#define SET_AUTOCALIBRATION_IP(IP) \
|
||||||
(strncpy(options.autocalibration_ip, (IP), 16))
|
(strncpy(options.autocalibration_ip, (IP), INET_ADDRSTRLEN))
|
||||||
#define GET_AUTOCALIBRATION_IP() \
|
#define GET_AUTOCALIBRATION_IP() \
|
||||||
(options.autocalibration_ip)
|
(options.autocalibration_ip)
|
||||||
#define SET_AUTOCALIBRATION_REQUEST_PORT(PORT) \
|
#define SET_AUTOCALIBRATION_REQUEST_PORT(PORT) \
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
char *program_name = NULL ;
|
char *program_name = NULL ;
|
||||||
uint8_t my_mac_bytes[6] ; // AP MAC address
|
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 ;
|
int aggregation_sockfd ;
|
||||||
struct sockaddr_in aggregation_server ;
|
struct sockaddr_in aggregation_server ;
|
||||||
|
@ -25,7 +25,7 @@ cfg_t *cfg ; // Configuration structure
|
||||||
*/
|
*/
|
||||||
struct {
|
struct {
|
||||||
char mode ;
|
char mode ;
|
||||||
char aggregation_ip[16] ;
|
char aggregation_ip[INET_ADDRSTRLEN] ;
|
||||||
uint_fast16_t aggregation_port ;
|
uint_fast16_t aggregation_port ;
|
||||||
uint_fast16_t listening_port ;
|
uint_fast16_t listening_port ;
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
|
@ -35,7 +35,7 @@ struct {
|
||||||
char wifi_iface[IFNAMSIZ + 1] ;
|
char wifi_iface[IFNAMSIZ + 1] ;
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
owl_bool autocalibration ;
|
owl_bool autocalibration ;
|
||||||
char autocalibration_ip[16] ;
|
char autocalibration_ip[INET_ADDRSTRLEN] ;
|
||||||
uint_fast16_t autocalibration_request_port ;
|
uint_fast16_t autocalibration_request_port ;
|
||||||
uint_fast16_t autocalibration_port ;
|
uint_fast16_t autocalibration_port ;
|
||||||
uint_fast32_t autocalibration_hello_delay ;
|
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'.
|
* 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;
|
struct ifreq ifr;
|
||||||
int sockfd ;
|
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)],
|
memcpy(&ip_addr, &ifr.ifr_addr.sa_data[sizeof(sa.sin_port)],
|
||||||
sizeof(ip_addr)) ;
|
sizeof(ip_addr)) ;
|
||||||
strncpy(ip, inet_ntoa(ip_addr), 16) ;
|
strncpy(ip, inet_ntoa(ip_addr), INET_ADDRSTRLEN) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue