From fb508a83520da9be5ecd2c36bbff6c06eb26f6ca Mon Sep 17 00:00:00 2001 From: Luke De Mouy Date: Sat, 9 Jan 2016 13:00:23 -0700 Subject: [PATCH] Move PortInfo struct out of PortLookUp class, and fiddled with the regex to make it actually work based on testing. The filter operation now will pickup things like 522/tcp in the QStringList if you're searching for 22/tcp, but testing seems to indicate that just taking the first one in the list works for getting what we want. --- src/library/portlookup.cpp | 6 ++---- src/library/portlookup.h | 16 +++++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/library/portlookup.cpp b/src/library/portlookup.cpp index b091e65..52756b9 100644 --- a/src/library/portlookup.cpp +++ b/src/library/portlookup.cpp @@ -1,8 +1,7 @@ #include "portlookup.h" #include - using namespace sysadm; -PortLookUp::PortInfo PortLookUp::LookUpPort(int portNumber, QString portType) +PortInfo PortLookUp::LookUpPort(int portNumber, QString portType) { //Make sure that the port is valid if (portNumber < 0 || portNumber > 65535) @@ -41,8 +40,7 @@ PortLookUp::PortInfo PortLookUp::LookUpPort(int portNumber, QString portType) //Check to see if the port number is listed. The format in the file // is portname/portType. ex.: 22/tcp - QStringList port = portStrings->filter(QRegExp("/\\b("+QString::number(portNumber)+"\\/"+portType+")/g")); - + QStringList port = portStrings->filter(QString::number(portNumber) + "/" + portType); if(port.size() > 0) { //grab the first one, there may be duplicates due to colliding ports in the /etc/services file diff --git a/src/library/portlookup.h b/src/library/portlookup.h index b3ebdab..6ccb58d 100644 --- a/src/library/portlookup.h +++ b/src/library/portlookup.h @@ -9,17 +9,19 @@ #include namespace sysadm { +struct PortInfo{ + int Port; + QString PortType; + QString Keyword; + QString Description; + bool Recommended; +}; + const static int recommendedPorts[] = {22, 80}; const static int recommendedPortsSize = 2; class PortLookUp { - struct PortInfo{ - int Port; - QString PortType; - QString Keyword; - QString Description; - bool Recommended; - }; + public: /** * @description Returns a structure containing information about the port