Click here to Skip to main content
15,115,261 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 9: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

}
   
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
   
A 5. (Sigh...) :-)
--SA
Member 7766180 1-May-11 15:56pm
   
Does (Sigh...) mean the first one or the second one? :)
   
This too. I meant to say: "what's going on with the skill level of CodeProject Inquirers?..".
--SA
Member 7766180 1-May-11 16:24pm
   
How is one to learn if one doesn't ask? At least I have the brain power to ask. If you don't want to help, fine. Everyone must start somewhere. I'm sure at one point your "Skill Level" was not up to snuff. Please don't try to make me feel stupid, because I'm not. I'm just learning and I've taken on a hugh project to begin with. Like I said, if you don't want to help, fine. As quoted from this site. "Let's work to help developers, not make them feel stupid."
   
Your getting offense if counter-productive. Pay attention: you're still getting answers, even though you could get from the documentation. Do you realize how many people did everything on their own, never asking for help? We all were novice and still learning. I never had any teachers.
"How is one to learn if one doesn't ask?" -- it depends on what to ask.
If I'm concerned about level of question, I know what I'm talking about. And it's not about feeling stupid, very often it's about being lazy. Nothing personal.
"Like I said, if you don't want to help, fine." -- you dare! Before saying so to ***me***, look at my answers and at all those people who really got my help.
--SA
Member 7766180 1-May-11 18:03pm
   
Listen, I'm sure you are a fairly intelligent person and I don't want to get into it with you. I'm sure you've helped countless individuals with their coding isuues. If you want to help me, thats fine. If not, thats fine also. I wish you all the best.
Sincerely,
DS
   
Same to you. Please try to take it positively. You're getting help actually, but you cannot avoid some criticism and should better take in productively, by improving. If you point out mistakes of others, they usually also respond constructively, not looking at who is the person telling it. Please understand nobody wants to harm you. Most people here really aimed to reduce amount of the evil and help the good in the world :-).
Best wishes,
--SA
Albert Holguin 1-May-11 16:09pm
   
:D thanks

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