📄 console.c
字号:
void ConsoleClose()
{
HANDLE hTmp;
if( hConsole )
{
hTmp = hConsole;
hConsole = 0;
#ifdef _INCLUDE_PPPOE_CODE
// If PPPOE is running, kill it
if( hPPPOE )
{
pppoeFree( hPPPOE );
hPPPOE = 0;
}
#endif
// Close the console socket session. This will cause
// the console app thread to terminate with socket
// error.
fdCloseSession( hTmp );
}
}
//---------------------------------------------------------------------
// console()
//
// This is the main console task.
//
// Arg1 = IP Addr, Arg2 = UDP Foreign Port
//---------------------------------------------------------------------
static void console( SOCKET sCon, PSA pClient )//响应外部输入命令操作
{
uint tmp;
char tstr[80];
char *tok[6];
int i,logon=0;
fdOpenSession( TaskSelf() );
// Get our socket
scon = sCon;
// New console connection
// ConPrintf( VerStr );
ConPrintf("Welcome connection : ");
ConPrintIPN( pClient->sin_addr.s_addr );
ConPrintf(":%d\n", htons( pClient->sin_port ) );
//
// Just for fun, ask for a password
//
for( tmp=0; tmp<3; tmp++ )
{
if( !strlen(Password) )
break;
ConPrintf("\nPassword: ");
ConGetString( tstr, 32, CGSECHO_PASSWORD );
if( !strcmp(tstr, Password) )
break;
ConPrintf("\nInvalid login\n");
}
if( tmp >= 3 )
logon = 0;
else
{
ConPrintf("\n\nWelcome to the console program.\n");
ConPrintf("Enter '?' or 'help' for a list of commands.\n\n");
logon = 1;
}
//
// Start the console command loop
//
while( logon )
{
// Get a command string
ConPrintf(">");
ConGetString( tstr, 80, CGSECHO_INPUT );
ConPrintf("\n");
// Break the string down into tokens
tmp = 0;
i = 0;
tok[0] = tstr;
while( tstr[i] && tmp < 6 )
{
if( tstr[i] == ' ' )
{
tstr[i] = 0;
if( ++tmp < 6 )
tok[tmp] = tstr+i+1;
}
i++;
}
// We terminated due to a NULL, then we have one more token
if( tmp < 6 )
tmp++;
// Process the command i 表示输入命令的长度
if( i )
{
if( *tok[0] == '?' || !stricmp( tok[0], "help" ) )
{
// ConPrintf( VerStr );
ConPrintf("\n[Help Command]\n\nThe basic commands are:\n");
ConPrintf(" acct - Manage PPP user accounts\n");
ConPrintf(" bye - Logoff the console\n");
ConPrintf(" echo - Perform echo test\n");
ConPrintf(" help - Displays this message\n");
ConPrintf(" log - Dump debug log entries\n");
ConPrintf(" mem - Display memory status\n");
ConPrintf(" nslookup - Lookup hostname or IP address\n");
#ifdef _INCLUDE_PPPOE_CODE
ConPrintf(" pppoe - Invoke PPPOE client logon\n");
#endif
ConPrintf(" pswd - Change console password\n");
ConPrintf(" ping - Test echo request\n");
ConPrintf(" quit - Logoff the console\n");
ConPrintf(" reboot - Reboot system (terminates session)\n");
ConPrintf(" route - Maintain route table\n");
ConPrintf(" test - 测试各个命令\n");
ConPrintf(" shutdown - Shutdown stack (terminates session)\n");
ConPrintf(" socket - Print socket table\n");
ConPrintf(" stat - Print internal stack statistics\n");
ConPrintf(" tftp - Test TFTP file transfer\n");
ConPrintf("\nSome commands have additional help information. For example\n");
ConPrintf("entering 'route' gives more information on the route command.\n\n");
}
else if( !stricmp( tok[0], "bye" ) || !stricmp( tok[0], "quit" ) )
logon = 0;
else if( !stricmp( tok[0], "route" ) )
ConCmdRoute( tmp-1, tok[1], tok[2], tok[3], tok[4] );
else if( !stricmp( tok[0], "acct" ) )
ConCmdAcct( tmp-1, tok[1], tok[2], tok[3], tok[4] );
else if( !stricmp( tok[0], "stat" ) )
ConCmdStat( tmp-1, tok[1] );
else if( !stricmp( tok[0], "nslookup" ) )
ConCmdLookup( tmp-1, tok[1] );
else if( !stricmp( tok[0], "ping" ) )
ConCmdPing( tmp-1, tok[1], tok[2] );
else if( !stricmp( tok[0], "echo" ) )
ConCmdEcho( tmp-1, tok[1], tok[2] );
else if( !stricmp( tok[0], "socket" ) )
ConCmdSocket( tmp-1, tok[1] );
else if( !stricmp( tok[0], "tftp" ) )
ConCmdTFTP( tmp-1, tok[1], tok[2] );
else if( !stricmp( tok[0], "test" ) )
ConCmdTest( tmp-1, tok[1], tok[2] );
#ifdef _INCLUDE_PPPOE_CODE
else if( !stricmp( tok[0], "pppoe" ) )
ConCmdPPPOE( tmp-1, tok[1], tok[2], tok[3] );
#endif
else if( !stricmp( tok[0], "reboot" ) )
NC_NetStop(1);
else if( !stricmp( tok[0], "shutdown" ) )
NC_NetStop(0);
else if( !stricmp( tok[0], "mem" ) )
_mmCheck( MMCHECK_MAP, &ConPrintf );
else if( !stricmp( tok[0], "pswd" ) )
{
if( tmp<2 || strlen(tok[1]) > 31 )
ConPrintf("Usage: pswd newpassword\n\n");
else
{
strcpy(Password,tok[1]);
ConPrintf("Console password is now '%s'\n\n",Password);
}
}
else if( !stricmp( tok[0], "log" ) )
{
if( !DebugLogSize )
ConPrintf("\nThe debug log is empty\n\n");
send( scon, DebugLog, DebugLogSize, 0 );
DebugLogSize = 0;
}
else
ConPrintf("Invalid command - Enter '?' or 'help' for a list of commands.\n");
}
}
// Close the console
ConPrintf("\nGoodbye\n");
// Close console thread
ConsoleClose();
fdClose( scon );
TaskExit();
}
//---------------------------------------------------------------------
// PPPOE Client Command
//---------------------------------------------------------------------
#ifdef _INCLUDE_PPPOE_CODE
static void ConCmdPPPOE( int ntok, char *tok1, char *tok2, char *tok3 );
static char *callerr[] = { "Dropped", "LCP Failed", "Authorization Failed",
"IP Config Failed" };
static void ConCmdPPPOE( int ntok, char *tok1, char *tok2, char *tok3 )
{
uint tmp;
// Check for 'acct 1 userid password'
if( ntok == 3 )
{
tmp = *tok1 - '0';
if( tmp<1 || tmp>9 )
goto ERROR;
if( hPPPOE )
{
ConPrintf("\nSession already open\n\n");
return;
}
// Initiate "call"
hPPPOE = pppoeNew( IFIndexGetHandle(tmp),
PPPFLG_CLIENT | PPPFLG_OPT_USE_MSE, tok2, tok3 );
if( !hPPPOE )
ConPrintf("PPPOE Open failed\n");
else while(1)
{
// Get status of call
tmp = pppoeGetStatus( hPPPOE );
// If disconnected, print message and close
if( tmp >= SI_CSTATUS_DISCONNECT )
{
ConPrintf("Disconnected - '%s'\n", callerr[tmp-SI_CSTATUS_DISCONNECT]);
goto DISCONNECT;
}
// If connected, print message and break
if( tmp == SI_CSTATUS_CONNECTED )
{
ConPrintf("Connected\n");
break;
}
// Else wait half a second and try again
TaskSleep( 500 );
}
}
// Check for 'close'
else if( ntok == 1 && !stricmp( tok1, "close" ) )
{
if( !hPPPOE )
ConPrintf("\nPPPOE not connected\n\n");
else
{
DISCONNECT:
pppoeFree( hPPPOE );
hPPPOE = 0;
ConPrintf("\nPPPOE closed\n\n");
}
}
else if( ntok == 0 )
{
ConPrintf("\n[PPPOE Command]\n");
ConPrintf("\nCalled to invoke a PPPOE client session.\n\n");
ConPrintf("pppoe 1 userid password - Connect on Ethernet If-1\n");
ConPrintf("pppoe close - Close PPPOE session\n\n");
}
else
{
ERROR:
ConPrintf("\nError in command. Type 'PPPOE' for usage.\n\n");
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -