From a5c69a2ef00d52aa79161139910a4c47b179ce70 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Thu, 26 Oct 2017 17:53:28 +0200 Subject: [PATCH] replace string with define --- src/include/utils.h | 2 ++ src/storage/datastorage.c | 21 +++++++++++---------- src/utils/rssi.c | 2 +- src/utils/ubus.c | 8 +++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/include/utils.h b/src/include/utils.h index 5b86370..ec0e87a 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -7,6 +7,8 @@ #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] #define STR2MAC(a) &(a)[0], &(a)[1], &(a)[2], &(a)[3], &(a)[4], &(a)[5] +#define MACSTR "%02X:%02X:%02X:%02X:%02X:%02X" + int hex_to_bin(char ch); int hwaddr_aton(const char *txt, uint8_t *addr); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index 1174a7e..672fd76 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -4,6 +4,7 @@ #include "ubus.h" #include "rssi.h" +#include "utils.h" #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] @@ -435,7 +436,7 @@ ap ap_array_get_ap(uint8_t bssid_addr[]) { ap ret; char bssid_mac_string[20]; - sprintf(bssid_mac_string, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(bssid_addr)); + sprintf(bssid_mac_string, MACSTR, MAC2STR(bssid_addr)); printf("Try to find: %s\n", bssid_mac_string); printf("in\n"); print_ap_array(); @@ -898,9 +899,9 @@ void print_probe_entry(probe_entry entry) { char mac_buf_client[20]; char mac_buf_target[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); - sprintf(mac_buf_target, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.target_addr)); + sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr)); + sprintf(mac_buf_target, MACSTR, MAC2STR(entry.target_addr)); printf( "bssid_addr: %s, client_addr: %s, signal: %d, freq: " @@ -913,9 +914,9 @@ void print_auth_entry(auth_entry entry) { char mac_buf_client[20]; char mac_buf_target[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); - sprintf(mac_buf_target, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.target_addr)); + sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr)); + sprintf(mac_buf_target, MACSTR, MAC2STR(entry.target_addr)); printf( "bssid_addr: %s, client_addr: %s, signal: %d, freq: " @@ -927,8 +928,8 @@ void print_client_entry(client entry) { char mac_buf_ap[20]; char mac_buf_client[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); - sprintf(mac_buf_client, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.client_addr)); + sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr)); printf("bssid_addr: %s, client_addr: %s, freq: %d, ht_supported: %d, vht_supported: %d, ht: %d, vht: %d\n", mac_buf_ap, mac_buf_client, entry.freq, entry.ht_supported, entry.vht_supported, entry.ht, entry.vht); @@ -946,7 +947,7 @@ void print_client_array() { void print_ap_entry(ap entry) { char mac_buf_ap[20]; - sprintf(mac_buf_ap, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(entry.bssid_addr)); + sprintf(mac_buf_ap, MACSTR, MAC2STR(entry.bssid_addr)); printf("bssid_addr: %s, freq: %d, ht: %d, vht: %d, chan_utilz: %d\n", mac_buf_ap, entry.freq, entry.ht, entry.vht, entry.channel_utilization); } diff --git a/src/utils/rssi.c b/src/utils/rssi.c index 59dfead..62d87a5 100644 --- a/src/utils/rssi.c +++ b/src/utils/rssi.c @@ -12,7 +12,7 @@ int parse_rssi(char *iwinfo_string); int get_rssi_from_iwinfo(__uint8_t *client_addr) { char mac_buf[20]; - sprintf(mac_buf, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(client_addr)); + sprintf(mac_buf, MACSTR, MAC2STR(client_addr)); char mac_buf_conv[20]; convert_mac(mac_buf, mac_buf_conv); diff --git a/src/utils/ubus.c b/src/utils/ubus.c index a1716be..b1110c2 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -119,8 +119,6 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir); static int ubus_get_clients(); -/* hostapd function */ -#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" static void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) { @@ -438,7 +436,7 @@ dump_client_table(struct blob_attr *head, int len, const char *bssid_addr, uint3 int tmp_int_mac[ETH_ALEN]; uint8_t tmp_mac[ETH_ALEN]; - sscanf((char *) hdr->name, "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); + sscanf((char *) hdr->name, MACSTR, STR2MAC(tmp_int_mac)); for (int i = 0; i < ETH_ALEN; ++i) tmp_mac[i] = (uint8_t) tmp_int_mac[i]; @@ -535,12 +533,12 @@ void *kick_clients_thread(void *arg) { /* int tmp_int_mac[ETH_ALEN]; uint8_t tmp_mac[ETH_ALEN]; - sscanf("a4:2b:b0:de:f1:fd", "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); + sscanf("a4:2b:b0:de:f1:fd", MACSTR, STR2MAC(tmp_int_mac)); for(int i = 0; i < ETH_ALEN; ++i ) tmp_mac[i] = (uint8_t) tmp_int_mac[i]; //kick_clients(tmp_mac); - sscanf("a4:2b:b0:de:f1:fe", "%02X:%02X:%02X:%02X:%02X:%02X", STR2MAC(tmp_int_mac)); + sscanf("a4:2b:b0:de:f1:fe", MACSTR, STR2MAC(tmp_int_mac)); for(int i = 0; i < ETH_ALEN; ++i ) tmp_mac[i] = (uint8_t) tmp_int_mac[i];*/ //kick_clients(tmp_mac);