diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt5/horizonwizard.cc | 38 | ||||
-rw-r--r-- | ui/qt5/horizonwizard.hh | 7 | ||||
-rw-r--r-- | ui/qt5/networkifacepage.cc | 33 | ||||
-rw-r--r-- | ui/qt5/networkingpage.cc | 2 |
4 files changed, 42 insertions, 38 deletions
diff --git a/ui/qt5/horizonwizard.cc b/ui/qt5/horizonwizard.cc index dda631f..67ed193 100644 --- a/ui/qt5/horizonwizard.cc +++ b/ui/qt5/horizonwizard.cc @@ -21,6 +21,9 @@ #ifdef HAS_INSTALL_ENV # include <libudev.h> +# include <net/if.h> /* ifreq */ +# include <sys/ioctl.h> /* ioctl */ +# include <unistd.h> /* close */ #endif /* HAS_INSTALL_ENV */ #include "intropage.hh" @@ -63,13 +66,13 @@ static std::map<int, std::string> help_id_map = { #ifdef HAS_INSTALL_ENV -std::map<std::string, HorizonWizard::NetworkInterfaceType> probe_ifaces(void) { +std::map<std::string, HorizonWizard::NetworkInterface> probe_ifaces(void) { struct udev *udev; struct udev_enumerate *if_list; struct udev_list_entry *first, *candidate; struct udev_device *device = nullptr; - std::map<std::string, HorizonWizard::NetworkInterfaceType> ifaces; + std::map<std::string, HorizonWizard::NetworkInterface> ifaces; udev = udev_new(); if(udev == nullptr) { @@ -90,6 +93,7 @@ std::map<std::string, HorizonWizard::NetworkInterfaceType> probe_ifaces(void) { udev_list_entry_foreach(candidate, first) { const char *syspath = udev_list_entry_get_name(candidate); const char *devtype, *cifname; + QString mac; if(device != nullptr) udev_device_unref(device); device = udev_device_new_from_syspath(udev, syspath); @@ -109,18 +113,40 @@ std::map<std::string, HorizonWizard::NetworkInterfaceType> probe_ifaces(void) { continue; } + /* Retrieving the index is always valid, and is not even privileged. */ + struct ifreq request; + int my_sock = ::socket(AF_INET, SOCK_STREAM, 0); + if(my_sock != -1) { + memset(&request, 0, sizeof(request)); + memcpy(&request.ifr_name, cifname, strlen(cifname)); + 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); + } + ::close(my_sock); + } + std::string ifname(cifname); if(strstr(devtype, "wlan")) { - ifaces.insert({ifname, HorizonWizard::Wireless}); + ifaces.insert({ifname, {HorizonWizard::Wireless, mac}}); } else if(strstr(devtype, "bond")) { - ifaces.insert({ifname, HorizonWizard::Bonded}); + ifaces.insert({ifname, {HorizonWizard::Bonded, mac}}); } else if(strstr(syspath, "/virtual/")) { /* Skip lo, tuntap, etc */ continue; } else if(strstr(devtype, "1")) { - ifaces.insert({ifname, HorizonWizard::Ethernet}); + ifaces.insert({ifname, {HorizonWizard::Ethernet, mac}}); } else { - ifaces.insert({ifname, HorizonWizard::Unknown}); + ifaces.insert({ifname, {HorizonWizard::Unknown, mac}}); } } diff --git a/ui/qt5/horizonwizard.hh b/ui/qt5/horizonwizard.hh index d6f84cd..b999daf 100644 --- a/ui/qt5/horizonwizard.hh +++ b/ui/qt5/horizonwizard.hh @@ -58,10 +58,15 @@ public: Unknown }; + struct NetworkInterface { + NetworkInterfaceType type; + QString mac; + }; + HorizonWizard(QWidget *parent = nullptr); QShortcut *f1, *f3, *f5, *f8; - std::map<std::string, NetworkInterfaceType> interfaces; + std::map<std::string, NetworkInterface> interfaces; std::string chosen_auto_iface; }; diff --git a/ui/qt5/networkifacepage.cc b/ui/qt5/networkifacepage.cc index f850cfd..4d292fb 100644 --- a/ui/qt5/networkifacepage.cc +++ b/ui/qt5/networkifacepage.cc @@ -13,12 +13,6 @@ #include "networkifacepage.hh" #include "horizonwizard.hh" -#ifdef HAS_INSTALL_ENV -# include <net/if.h> /* ifreq */ -# include <sys/ioctl.h> /* ioctl */ -# include <unistd.h> /* close */ -#endif - #include <algorithm> #include <QDebug> #include <QLabel> @@ -58,7 +52,7 @@ void NetworkIfacePage::initializePage() { QString ifaceDevName = QString::fromStdString(iface.first); QString ifaceName; - switch(iface.second) { + switch(iface.second.type) { case HorizonWizard::Wireless: ifaceIcon = QIcon::fromTheme("network-wireless"); ifaceName = tr("Wi-Fi (%1)").arg(ifaceDevName); @@ -79,28 +73,7 @@ void NetworkIfacePage::initializePage() { QListWidgetItem *item = new QListWidgetItem(ifaceIcon, ifaceName, ifaceList); - /* Retrieving the index is always valid, and is not even privileged. */ - struct ifreq request; - int my_sock = ::socket(AF_INET, SOCK_STREAM, 0); - if(my_sock == -1) { - continue; - } - memset(&request, 0, sizeof(request)); - memcpy(&request.ifr_name, iface.first.c_str(), iface.first.size()); - 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]); - item->setToolTip(QString(buf)); - free(buf); - } - ::close(my_sock); + item->setToolTip(iface.second.mac); } layout = new QVBoxLayout; @@ -119,7 +92,7 @@ int NetworkIfacePage::nextId() const { auto iterator = horizonWizard()->interfaces.begin(); std::advance(iterator, ifaceList->currentRow()); - switch(iterator->second) { + switch(iterator->second.type) { case HorizonWizard::Wireless: return HorizonWizard::Page_Network_Wireless; default: diff --git a/ui/qt5/networkingpage.cc b/ui/qt5/networkingpage.cc index 8379877..86f8aff 100644 --- a/ui/qt5/networkingpage.cc +++ b/ui/qt5/networkingpage.cc @@ -80,7 +80,7 @@ int NetworkingPage::nextId() const { } else { horizonWizard()->chosen_auto_iface = (horizonWizard()->interfaces.begin())->first; - if((horizonWizard()->interfaces.begin())->second + if((horizonWizard()->interfaces.begin())->second.type == HorizonWizard::Wireless) { return HorizonWizard::Page_Network_Wireless; } else { |