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.
This commit is contained in:
Luke De Mouy
2016-01-09 13:00:23 -07:00
parent 5cc11be9e6
commit fb508a8352
2 changed files with 11 additions and 11 deletions

View File

@@ -1,8 +1,7 @@
#include "portlookup.h"
#include <QtCore>
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

View File

@@ -9,17 +9,19 @@
#include <QtCore>
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