From ce2f251cd5064bab481dbf6d8715dc54f8acf0e6 Mon Sep 17 00:00:00 2001 From: sean Date: Sat, 4 Aug 2012 01:08:31 +0000 Subject: [PATCH] Added a function to check if port specification will do anything. Changed over my logic to use this new functioni. (scan_mode_uses_target_ports) --- nping/NpingOps.cc | 4 ++++ nping/NpingOps.h | 3 +++ nping/nping.cc | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nping/NpingOps.cc b/nping/NpingOps.cc index 2ddb8014a..121439aef 100644 --- a/nping/NpingOps.cc +++ b/nping/NpingOps.cc @@ -1537,6 +1537,10 @@ bool NpingOps::issetTargetPorts(){ return this->target_ports_set; } /* End of issetTargetPorts() */ +/*Returns true if the scan type can use the -p option*/ +bool NpingOps::scan_mode_uses_target_ports(int mode){ + return (mode==TCP_CONNECT || mode==TCP || mode == UDP || mode == UDP_UNPRIV); +} /*End of scan_mode_uses_target_ports*/ /** Sets TCP/UPD source port. Supplied parameter must be an integer >=0 && * <=65535 diff --git a/nping/NpingOps.h b/nping/NpingOps.h index 74366f9d0..04ff48ead 100644 --- a/nping/NpingOps.h +++ b/nping/NpingOps.h @@ -327,6 +327,9 @@ class NpingOps { u16 *getTargetPorts( int *len ); int setTargetPorts( u16 *pnt, int n ); bool issetTargetPorts(); + bool scan_mode_uses_target_ports(int mode); + + int setSourcePort(u16 val); u16 getSourcePort(); diff --git a/nping/nping.cc b/nping/nping.cc index f9cb34cf2..c3a9dcd31 100644 --- a/nping/nping.cc +++ b/nping/nping.cc @@ -167,7 +167,7 @@ int main(int argc, char *argv[] ){ * we should alert the user that their port command is going to be ignored * I choose to print out a Fatal error since the scan doesn't make sense. */ - if(o.issetTargetPorts() && (o.getMode() != TCP || o.getMode() != UDP || o.getMode !=UDP_PRIV)) + if(o.issetTargetPorts() && !o.scan_mode_uses_target_ports(o.getMode())) outFatal(QT_3, "You cannot use -p (explicit port selection) in your current scan mode.\n(Perhaps you meant to use --tcp or --udp"); @@ -228,7 +228,7 @@ int do_safe_checks(){ test_stuff(); /* Little function that is called quite early to test some misc stuff. */ return OP_SUCCESS; } /* End of do_safe_checks() */ - +// /** Use this function whenever you have some code that you want to test, but