summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-18 00:07:52 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-18 00:07:52 -0600
commit556059bf80e3a368811fd46fe2b6e35104d0eda3 (patch)
tree69194566f54a4d90373f7d3aa37be749beb58d2a /ui
parent27df9474a63890fd289825a4a5039f50946f895c (diff)
downloadhorizon-556059bf80e3a368811fd46fe2b6e35104d0eda3.tar.gz
horizon-556059bf80e3a368811fd46fe2b6e35104d0eda3.tar.bz2
horizon-556059bf80e3a368811fd46fe2b6e35104d0eda3.tar.xz
horizon-556059bf80e3a368811fd46fe2b6e35104d0eda3.zip
Qt UI: Factor out MAC address stringify to function
Diffstat (limited to 'ui')
-rw-r--r--ui/qt5/horizonwizard.cc11
-rw-r--r--ui/qt5/horizonwizard.hh13
2 files changed, 14 insertions, 10 deletions
diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc
index 2679a6e..7a64d2a 100644
--- a/ui/qt5/horizonwizard.cc
+++ b/ui/qt5/horizonwizard.cc
@@ -126,16 +126,7 @@ std::map<std::string, HorizonWizard::NetworkInterface> probe_ifaces(void) {
memcpy(&request.ifr_name, cifname, strnlen(cifname, IFNAMSIZ));
errno = 0;
if(ioctl(my_sock, SIOCGIFHWADDR, &request) != -1) {
- char *buf;
- asprintf(&buf, "%02X:%02X:%02X:%02X:%02X:%02X",
- request.ifr_ifru.ifru_hwaddr.sa_data[0],
- request.ifr_ifru.ifru_hwaddr.sa_data[1],
- request.ifr_ifru.ifru_hwaddr.sa_data[2],
- request.ifr_ifru.ifru_hwaddr.sa_data[3],
- request.ifr_ifru.ifru_hwaddr.sa_data[4],
- request.ifr_ifru.ifru_hwaddr.sa_data[5]);
- mac = QString(buf);
- free(buf);
+ mac = fromMacAddress(request.ifr_ifru.ifru_hwaddr.sa_data);
}
::close(my_sock);
}
diff --git a/ui/qt5/horizonwizard.hh b/ui/qt5/horizonwizard.hh
index cd0d213..2941f08 100644
--- a/ui/qt5/horizonwizard.hh
+++ b/ui/qt5/horizonwizard.hh
@@ -18,6 +18,19 @@
#include <map>
#include <string>
+inline QString fromMacAddress(char address[6]) {
+ char buf[18];
+ snprintf(buf, 18, "%02X:%02X:%02X:%02X:%02X:%02X",
+ address[0] & 0xFF,
+ address[1] & 0xFF,
+ address[2] & 0xFF,
+ address[3] & 0xFF,
+ address[4] & 0xFF,
+ address[5] & 0xFF);
+ QString mac(buf);
+ return mac;
+}
+
class HorizonWizard : public QWizard {
public:
enum {