Nmap Development mailing list archives

RE: nping command line parsing: set source IP address


From: Perry Hooker <phooker () terraechos com>
Date: Thu, 16 May 2013 17:01:17 +0000

EDIT: The assignment

fakeargv[argc] = NULL; 

in nmap.cc has nothing to do with this issue; apologies for the misdirection.  Changing grab_next_host_spec() method in 
netutil.cc to eliminate the comparison between optind and argc works because argv[] is terminated with a null value 
(per the C++ language standard).  I still don't know why the value of argc changes after the call to atoIP(); my best 
guess is that argc is overwritten by an overzealous reference into argv somewhere down the line.

-----Original Message-----
From: dev [mailto:dev-bounces () nmap org] On Behalf Of Perry Hooker
Sent: Wednesday, May 15, 2013 5:12 PM
To: dev () nmap org
Subject: nping command line parsing: set source IP address

I've run in to some problems using nping 0.6.25 with the command-line option to set the source IP address (-S, 
--source-ip) on CentOS 6.2.  Specifically, when I specify a numeric source IP address, e.g.

$ nping -c 1 -S 192.168.1.1 127.0.0.1

I get the error message 

WARNING: No targets specified, so 0 hosts pinged.

However, the command 

$ nping -c 1 -S random 127.0.0.1 

functions as expected.

An examination of the 

case 'S': 

clause in ArgParser.cc reveals that the value of argc is reset to 0 by the call to atoIP.  This causes the  
grab_next_host_spec method in netutil.cc to return NULL before parsing the target argument.  Changing the line in 
grab_next_host_spec function from


return( (optind < argc) ? fakeargv[optind++] : NULL);

to

return fakeargv[optind++]; 

seems to work around the problem, but I'm unclear as to why this does NOT result in an infinite loop during parsing of 
target host specifications (at the end of the parseArguments method in ArgParser.cc).  Removing the line 

fakeargv[argc] = NULL; 

in nmap.cc doesn't seem to change this behavior.   I'm also not sure why the value of argc is modified in the first 
place.  I suspect it's related to the getopt family of functions, but I'm not sure.  Guidance / corrections to my 
reasoning much appreciated.

rphv

_______________________________________________
Sent through the dev mailing list
http://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/
_______________________________________________
Sent through the dev mailing list
http://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/


Current thread: