Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I want to add a third argument to this code, how would I do it?

C#
{
      if ( !_stricmp(_argv[1], "icmp") )
         bShowTCP = FALSE;
      else if ( !_stricmp(_argv[1], "tcp") )
         bShowICMP = FALSE;
      else
      {
         printf( "\nUsage lsniff [ICMP|TCP]\n" );
         exit(0);
      }
   }


Like This, but not working.....
C#
{
      if ( !_stricmp(_argv[1], "icmp") )
         bShowTCP = FALSE;bShowUDP = FALSE:
      else if ( !_stricmp(_argv[1], "tcp") )
         bShowICMP = FALSE;bShowUDP = FALSE;
      else
         bShowUDP = TRUE;
      {
         printf( "\nUsage lsniff [ICMP|TCP]\n" );
         exit(0);
      }
   }



The logic is as follows...
If ICMP then TCP and UDP = False
If TCP then ICMP and UDP = False
If UDP then ICMP and TCP = False
Posted
Updated 1-May-11 8:29am
v4
Comments
Albert Holguin 1-May-11 14:30pm    
edit: changed title to something more appropriate

1 solution

I think what you're trying to do is add extra code to the conditional statements:

C++
if ( !_stricmp(_argv[1], "icmp") )
{ //<-- Need to add brackets for more than one statement
   bShowTCP = FALSE;
   bShowUDP = FALSE;
}
else if ( !_stricmp(_argv[1], "tcp") )
{
   bShowICMP = FALSE;
   bShowUDP = FALSE;
}
else
{
   bShowUDP = TRUE; //<-- Needs to be within else statement brackets
   printf( "\nUsage lsniff [ICMP|TCP]\n" );
   exit(0); //<-- FYI... this ends execution of the program

}
 
Share this answer
 
v5
Comments
Member 7766180 1-May-11 14:47pm    
Thank you Albert. Just one question. Does this need to be...
printf( "\nUsage lsniff [ICMP|TCP|UDP]\n" );
or this...
printf( "\nUsage lsniff [ICMP|TCP]\n" );
Thank you so much!
DS
Albert Holguin 1-May-11 16:09pm    
The reason that printf statement is there is to alert the user that the program is not set up for UDP right before the program exits (using the exit(0) statement). That printf is only used to alert the user of something, its not critical to anything.
Member 7766180 1-May-11 16:45pm    
Thank You Albert. I now have UDP added to the code and the sniffer is now returning UDP, ICMP and TCP packets. Very happy with the progress. And a BIG thanks to you for your patience and understanding. This is a bear coming from VB and VBA.
DS
Sergey Alexandrovich Kryukov 1-May-11 15:50pm    
A 5. (Sigh...) :-)
--SA
Member 7766180 1-May-11 15:56pm    
Does (Sigh...) mean the first one or the second one? :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900