diff --git a/interface.cpp b/interface.cpp index 98ed5c3..cdd66bb 100644 --- a/interface.cpp +++ b/interface.cpp @@ -62,7 +62,7 @@ int Interface::setLinkUp() { if(!link_orig) { std::cerr << "can't get link" << std::endl; nl_socket_free(sock); - return 0; + return 1; } link = rtnl_link_alloc(); @@ -71,7 +71,7 @@ int Interface::setLinkUp() { std::cerr << "can't alloc link" << std::endl; rtnl_link_put(link_orig); nl_socket_free(sock); - return 0; + return 1; } int err = 0; @@ -83,7 +83,7 @@ int Interface::setLinkUp() { rtnl_link_put(link); rtnl_link_put(link_orig); nl_socket_free(sock); - return 0; + return 1; } rtnl_link_put(link); @@ -114,7 +114,7 @@ int Interface::setLinkDown() { if(!link_orig) { std::cerr << "can't get link" << std::endl; nl_socket_free(sock); - return 0; + return 1; } link = rtnl_link_alloc(); @@ -123,7 +123,7 @@ int Interface::setLinkDown() { std::cerr << "can't alloc link" << std::endl; rtnl_link_put(link_orig); nl_socket_free(sock); - return 0; + return 1; } int err = 0; @@ -135,7 +135,7 @@ int Interface::setLinkDown() { rtnl_link_put(link); rtnl_link_put(link_orig); nl_socket_free(sock); - return 0; + return 1; } rtnl_link_put(link); @@ -535,7 +535,7 @@ QStringList Interface::list() { nl_socket_free(sock); // workaround for libnl issue: https://github.com/tgraf/libnl/issues/49 - // find any interfaces libnl doesn't know about (e.g. USB wireless adapters after they're been unplugged and replugged) + // find any interfaces libnl doesn't know about (e.g. USB wireless adapters after they've been unplugged and replugged) QDir dir("/sys/class/net"); QStringList interfaces = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); diff --git a/tui/menu.cpp b/tui/menu.cpp index 60c39ed..c0f616e 100644 --- a/tui/menu.cpp +++ b/tui/menu.cpp @@ -730,8 +730,8 @@ void Menu::interfaceSelect(WINDOW *window, QString interface) { }else if(c == '+') { QString error; - if(!obj.setLinkUp(error)) { - QString err = QString("Could not change link state: ") + error; + if(obj.setLinkUp() != 0) { + QString err = "Could not change link state."; QByteArray arr = err.toLatin1(); const char *errorString = arr.constData(); @@ -744,8 +744,8 @@ void Menu::interfaceSelect(WINDOW *window, QString interface) { }else if(c == '-') { QString error; - if(!obj.setLinkDown(error)) { - QString err = QString("Could not change link state: ") + error; + if(obj.setLinkDown() != 0) { + QString err = "Could not change link state."; QByteArray arr = err.toLatin1(); const char *errorString = arr.constData(); diff --git a/tui/tui.pro b/tui/tui.pro index 9bd1cc6..a1d95b3 100644 --- a/tui/tui.pro +++ b/tui/tui.pro @@ -22,6 +22,6 @@ QMAKE_CFLAGS += -Wall -Wextra -Werror -fsanitize=address -fPIE LIBS += -lasan -QMAKE_LFLAGS += -Wl,-rpath,/home/bp/libip +QMAKE_LFLAGS += -Wl,-rpath,../ # Directories diff --git a/wireless.cpp b/wireless.cpp index ce60b36..c1efd38 100644 --- a/wireless.cpp +++ b/wireless.cpp @@ -13,7 +13,6 @@ extern "C" { #include "utils.h" #include #include -#include #define BIT(x) (1ULL<<(x)) @@ -95,6 +94,8 @@ struct nl_interfaceCallback { \brief The Wireless class is used to manage 802.11 wireless information associated with an interface. Currently this class makes the assumption that it will only be used within the United States FCC regulatory domain. Only drivers supporting the Linux kernel nl80211 interface are supported. */ +static QRegularExpression s_noDigitRegex("[^\\d]"); + /*! Constructs a Wireless object. All operations will be limited to the specified \a interface. */ @@ -405,8 +406,7 @@ int Wireless::ChanToFreq(int channel) { */ QString Wireless::ChanToFreq(QString channel, QString outputFormat) { QString freq; - QRegularExpression re("[^\\d]"); - channel = channel.replace(re, ""); + channel = channel.replace(s_noDigitRegex, ""); if(outputFormat.isEmpty()) { bool ok = false; @@ -442,8 +442,7 @@ int Wireless::FreqToChan(int frequency) { */ QString Wireless::FreqToChan(QString frequency, QString outputFormat) { QString chan; - QRegularExpression re("[^\\d]"); - frequency = frequency.replace(re, ""); + frequency = frequency.replace(s_noDigitRegex, ""); if(frequency.length() < 4) { for(int i = frequency.length() + 1; i <= 4; ++i) { diff --git a/wireless.h b/wireless.h index 2ace783..4cb0cd0 100644 --- a/wireless.h +++ b/wireless.h @@ -5,6 +5,7 @@ #include #include "libip_global.h" #include +#include class LIBIP_EXPORT Wireless : public QObject { //Q_OBJECT