⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dns_relay_atmos.c

📁 DNS 的实现代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 * * Handler for MSG_N_TELL. * * Arguments: *   msg       Pointer to ATMOS TELL message containing command to handle. * * Returns: *   Nothing * *****************************************************************************/static void dns_relay_handle_tell( ATMOS_MESSAGE *msg ){    static char last_cmd[80];    MSG_D_TELL( tell, msg );    char *cmd = tell->cmd;    int i;    foreground_output_begin();    if ( '\0' != *cmd )    {        BOOL found = FALSE;        if (0 == strcmp(".", cmd))            cmd = last_cmd;        else            strncpy( last_cmd, cmd, sizeof(last_cmd) );        for (i = 0; i < commands.count; i++)        {            size_t len = strlen( commands.name[i] );            if (strncmp( cmd, commands.name[i], len ) == 0)            {                (*commands.handler[i]) (cmd + len, stdout );                found = TRUE;                break;            }        }        if ( !found )            printf( "%C: Unknown command '%s', try 'help'.\n", cmd );    }    foreground_output_end();    sendreply(msg);}/***************************************************************************** * * dns_relay_add_command: * * Install a handler for a TELL command. * * Arguments: *   name      Name of command *   handler   Command handler function * * Returns: *   Nothing * *****************************************************************************/static void dns_relay_add_command( const char *name, const char *help_text,                                    void (*handler) (char *, FILE *) ){    if (commands.count >= MAX_COMMANDS)    {        kprintf("%C: Failed to install handler for command %s\n\r", name);    }    else    {        commands.name[commands.count]      = name;        commands.help_text[commands.count] = help_text;        commands.handler[commands.count]   = handler;        commands.count++;    }    return;}#ifdef AUTO_DISCOVERY_SUPPORTED/***************************************************************************** * dns_relay_auto_command: * * Toggles auto-discovery of DNS server address via PPP (or otherwise).                       * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_auto_command( char *arg, FILE *fh ){    UNUSED( arg );        if( !config.automatic_discovery )    {        fprintf( fh, "Server address auto-discovery mode activated.\n" );        if( config.connection_successful )        {            fprintf( fh, "Warning: abandoned working server connection.\n");            config.connection_successful = FALSE;        }        /* Reset DNS server address to default */        os_inet_aton( DNS_DEFAULT_SERVER_ADDR, &config.dns_server_address );        config.retry_discovery = TRUE;        config.rediscover_server = TRUE;    }    else    {        fprintf( fh, "Already in auto-discovery mode.\n" );    }     config.automatic_discovery = TRUE;    return;}#endif /* AUTO_DISCOVERY_SUPPORTED *//***************************************************************************** * * dns_relay_config_command: * * Displays current DNS relay config. * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_config_command( char *arg, FILE *fh ){    UNUSED( arg );    UNUSED( fh );    if( 0 == strcmp( " reset", arg ))    {        dns_relay_process_config( TRUE );    }    else    {        dns_relay_process_config( FALSE );    }    return;}/***************************************************************************** * * dns_relay_help_command: * * Displays quick help about valid commands, or detailed help on the specified * commands, or detailed help on all commands. * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_help_command( char *arg, FILE *fh ){    int count;    BOOL show_details = FALSE;    BOOL command_found = FALSE;    BOOL bad_command = TRUE;    if ( '\0' != *arg )    {        /* Move beyond space between "help" command and argument */        arg++;        if (0 == strncmp( arg, "all", 3 ))        {            bad_command  = FALSE;            show_details = TRUE;        }        else        {            /* Search for help on requested command */            for ( count=0; count < commands.count; count++ )            {                if ( 0 == strncmp( arg, commands.name[count], strlen(commands.name[count])) )                {                    /* List details of requested command, if found */                    fprintf( fh, "DNS relay '%s' command: \n", commands.name[count] );                    fprintf( fh, " %12s - %s\n", commands.name[count], commands.help_text[count]);                    command_found = TRUE;                    break;                }            }        }    }    else    {        bad_command = FALSE;    }    if ( !command_found )    {        /* The request command is unknown, or the user wanted to know details         * of all commands         */        if( bad_command ) fprintf( fh, "Unrecognised command. " );        fprintf( fh, "Valid DNS relay commands are: \n" );                for ( count=0; count < commands.count; count++ )        {            if( show_details )            {                 /* Show detailed list of available commands */                fprintf( fh, " %12s - %s\n", commands.name[count], commands.help_text[count]);            }            else            {                /* Show brief list of available commands */                fprintf( fh, "%12s", commands.name[count] );                if (4 == (count % 5)) fprintf( fh, "\n" );            }        }                if (0 != (count % 5)) fprintf( fh, "\n" );    }    return;}/***************************************************************************** * * dns_relay_retry_command: * * Alters the number of transmission retries the relay will attempt (UDP * only) when trying to contact a DNS server. * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_retry_command( char *arg, FILE *fh ){    int new_retry_value;    UNUSED( fh );    new_retry_value = atoi( arg );    dns_relay_process_retry( new_retry_value );    return;}        /***************************************************************************** * * dns_relay_server_command: * * Command handler to manually tell the DNS relay which server to contact. * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_server_command( char *arg, FILE *fh ){    UNUSED( fh );    arg++; /* move beyond argument space */    dns_relay_process_server( arg , MANUALLY_CONFIGURED_DNS_SERVER);    return;}/***************************************************************************** * * dns_relay_status_command: * * Command handler to show DNS relay activation and connection status.  * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_status_command( char *arg, FILE *fh ){    UNUSED( arg );    UNUSED( fh );    dns_relay_process_status();    return;}/***************************************************************************** * * dns_relay_showdb_command: * * Command handler to tell DNS relay to list the contents of the LAN database * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_showdb_command( char *arg, FILE *fh ){    UNUSED( fh );    UNUSED( arg );    dump_lan_entries();    return;}/***************************************************************************** * * dns_relay_trace_command: * * Command handler to set trace flags (and display current settings) * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_trace_command( char *arg, FILE *fh ){    UNUSED( fh );    dns_relay_process_trace( arg );    return;}/***************************************************************************** * * dns_relay_untrace_command: * * Command handler to clear trace flags (and display current settings) * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_untrace_command( char *arg, FILE *fh ){    UNUSED( fh );    dns_relay_process_untrace( arg );    return;}/***************************************************************************** * * dns_relay_version_command: * * Command handler to display current software version. * * Arguments: *   arg       Tail of command string. *   fh        FILE* for display output. * * Returns: *   Nothing * *****************************************************************************/void dns_relay_version_command( char *arg, FILE *fh ){    UNUSED( arg );    UNUSED( fh );        dns_relay_process_version();    return;}/***************************************************************************** * * dns_relay_bailout * * Emergency bailout function only to be called if there are no other options.  * This function effectively suspends the process, allowing it only to * respond to messages. ATMOS version which uses messages. *     * Arguments: *   none * * Returns: *   Nothing * *****************************************************************************/void dns_relay_bailout( void ){    ATMOS_MESSAGE *m;    foreground_output_begin();    while( TRUE )    {        m = awaitmessage();        if( (m->code) == MSG_N_TELL )        {            printf("%C: DNS relay has suspended due to critical failure.\n");        }        if (!(m->code & MSG_REPLY_BIT))        {            sendreply( m );        }    }    /* never reached */    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -