How are bShowTCP, bShowUDP and bShowICMP initialized before that code?
Also the case where no argument is provided also need to be handled.
The following code would be an improvement. First, it make more sense to initialize
bShowSomething
to
FALSE
and have to update a single flag in each condition. IKt is much more maintanable when no protocole are added as you won't have to update existing code to disable the new protocole everywhere but you will enable it at a single place in the newly added condition.
bool bShowTCP = FALSE;
bool bShowUDP = FALSE;
bool bShowICMP = FALSE;
bool bShowUsage = FALSE;
if ( _argc > 1 )
{
if ( !_stricmp(_argv[1], "icmp") )
{ bShowICMP = TRUE;
}
else if ( !_stricmp(_argv[1], "tcp") )
{
bShowTCP = TRUE;
}
else if ( !_stricmp(_argv[1], "udp") )
{
bShowUDP = TRUE;
}
else
{
bShowUsage = TRUE;
}
}
else
{
bShowUsage = TRUE;
}
if (bShowUsage)
{
printf( "\nUsage lsniff [ICMP|TCP|UDP]\n" );
exit(0); }