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

📄 wvdialer.cc

📁 wvdial 软件包是一个自动拨号程序
💻 CC
📖 第 1 页 / 共 3 页
字号:
		    options.auto_reconnect = false;		}		msg = "";		switch (pppd_exit_status) 		{		case  1: 		    msg = "Fatal pppd error"; 		    break;		case  5: 		    msg = "pppd received a signal"; 		    break;		case  6: 		    msg = "Serial port lock failed"; 		    break;		case  7: 		    msg = "Serial port open failed"; 		    break;		case  8: 		    msg = "Connect script failed"; 		    break;		case  9: 		    msg = "Pty program error"; 		    break;		case 16: 		    msg = "A modem hung up the phone"; 		    break;		case 18: 		    msg = "The init script failed"; 		    break;		}		if (msg.len()) 		{		    log("The PPP daemon has died: %s (exit code = %s)\n",			msg, pppd_exit_status);		    log("man pppd explains pppd error codes in more detail.\n");		    log(WvLog::Notice, "Try again and look into /var/log/messages "			"and the wvdial and pppd man pages for more information.\n");		} else		    log(WvLog::Notice, "The PPP daemon has died. (exit code = %s)\n",			pppd_exit_status);	    }	    	    // check to see if we're supposed to redial automatically soon.	    if( options.auto_reconnect && isok() ) 	    {		if( call_duration >= 45 )		    // Connection was more than 45 seconds, so reset the		    // "exponential backup timer".		    auto_reconnect_delay = 0;		// exponentially back up...		auto_reconnect_delay *= 2;		if( auto_reconnect_delay == 0 )		    auto_reconnect_delay = 5;	  // start at 5 seconds		if( auto_reconnect_delay > 600 )		    auto_reconnect_delay = 600;  // no longer than 10 minutes		auto_reconnect_at = time( NULL ) + auto_reconnect_delay;		stat = AutoReconnectDelay;		log( WvLog::Notice, "Auto Reconnect will be attempted in %s "				    "seconds\n", 				    	auto_reconnect_at - time( NULL ) );	    }	}	break;    case AutoReconnectDelay:    	// If enough time has passed after ISP disconnected us that we should    	// redial, do it...    	// We can only get into this state if the Auto Reconnect option is    	// enabled, so there's no point in checking the option here.    	if( time( NULL ) >= auto_reconnect_at ) 	{    	    stat = Idle;    	    dial();    	}    	break;    case Idle:    case ModemError:    case OtherError:    default:	drain();    	break;    }}//**************************************************//       WvDialer Private Functions//**************************************************void WvDialer::load_options()/***************************/{    OptInfo opts[] = {    // string options:    	{ "Modem",           &options.modem,        NULL, "/dev/modem",     0 },    	{ "Init1",           &options.init1,        NULL, "ATZ",            0 },    	{ "Init2",           &options.init2,        NULL, "",               0 },    	{ "Init3",           &options.init3,        NULL, "",               0 },    	{ "Init4",           &options.init4,        NULL, "",               0 },    	{ "Init5",           &options.init5,        NULL, "",               0 },    	{ "Init6",           &options.init6,        NULL, "",               0 },    	{ "Init7",           &options.init7,        NULL, "",               0 },    	{ "Init8",           &options.init8,        NULL, "",               0 },    	{ "Init9",           &options.init9,        NULL, "",               0 },    	{ "Phone",           &options.phnum,        NULL, "",               0 },    	{ "Phone1",          &options.phnum1,       NULL, "",               0 },    	{ "Phone2",          &options.phnum2,       NULL, "",               0 },    	{ "Phone3",          &options.phnum3,       NULL, "",               0 },    	{ "Phone4",          &options.phnum4,       NULL, "",               0 },    	{ "Dial Prefix",     &options.dial_prefix,  NULL, "",               0 },    	{ "Area Code",       &options.areacode,     NULL, "",               0 },    	{ "Dial Command",    &options.dial_cmd,     NULL, "ATDT",           0 },    	{ "Username",        &options.login,        NULL, "",               0 },    	{ "Login Prompt",    &options.login_prompt, NULL, "",               0 },    	{ "Password",        &options.password,     NULL, "",               0 },    	{ "Password Prompt", &options.pass_prompt,  NULL, "",               0 },    	{ "PPPD Path",       &options.where_pppd,   NULL, "/usr/sbin/pppd", 0 },        { "PPPD Option",     &options.pppd_option,  NULL, "",		    0 },    	{ "Force Address",   &options.force_addr,   NULL, "",               0 },    	{ "Remote Name",     &options.remote,       NULL, "*",              0 },    	{ "Default Reply",   &options.default_reply,NULL, "ppp",	    0 },        { "Country",         &options.country,      NULL, "",		    0 },        { "Provider",        &options.provider,     NULL, "",		    0 },        { "Product",         &options.product,      NULL, "",		    0 },        { "Homepage",        &options.homepage,     NULL, "",		    0 },        { "DialMessage1",    &options.dialmessage1, NULL, "",		    0 },        { "DialMessage2",    &options.dialmessage2, NULL, "",		    0 },        { "DNS Test1",       &options.dnstest1,     NULL, "www.suse.de",    0 },        { "DNS Test2",       &options.dnstest2,     NULL, "www.suse.com",   0 },    // int/bool options    	{ "Baud",            NULL, &options.baud,          "", DEFAULT_BAUD },    	{ "Carrier Check",   NULL, &options.carrier_check, "", true         },    	{ "Stupid Mode",     NULL, &options.stupid_mode,   "", false        },    	{ "New PPPD",	     NULL, &options.new_pppd, 	   "", true         },    	{ "Auto Reconnect",  NULL, &options.auto_reconnect,"", true	    },        { "Dial Attempts",   NULL, &options.dial_attempts, "", 0            },    	{ "Abort on Busy",   NULL, &options.abort_on_busy, "", false	    },    	{ "Abort on No Dialtone", NULL, &options.abort_on_no_dialtone, "", true },        { "Compuserve",      NULL, &options.compuserve,    "", false        },        { "Tonline",         NULL, &options.tonline,       "", false        },        { "Auto DNS",        NULL, &options.auto_dns,      "", true         },        { "Check DNS",       NULL, &options.check_dns,     "", true         },        { "Check Def Route", NULL, &options.check_dfr,     "", true         },        { "Idle Seconds",    NULL, &options.idle_seconds,  "", 0            },        { "ISDN",            NULL, &options.isdn,          "", false        },        { "Ask Password",    NULL, &options.ask_password,  "", false        },    	{ NULL,		     NULL, NULL,                   "", 0            }    };    char *	d = "Dialer Defaults";    for( int i=0; opts[i].name != NULL; i++ )     {    	if( opts[i].str_member == NULL ) 	{    	    // it's an int/bool option.    	    *( opts[i].int_member ) =		cfg.fuzzy_getint( *sect_list, opts[i].name,		       cfg.getint( d, opts[i].name, opts[i].int_default ) );    	} 	else 	{    	    // it's a string option.    	    *( opts[i].str_member ) =     	    		cfg.fuzzy_get( *sect_list, opts[i].name,     	    		    cfg.get( d, opts[i].name, opts[i].str_default ) );    	}    }    // Support Init, as well as Init1, to make old WvDial people happy.    const char * newopt = cfg.fuzzy_get( *sect_list, "Init",	                        cfg.get( d, "Init", NULL ) );    if( newopt ) 	options.init1 = newopt;}bool WvDialer::init_modem()/*************************/{    int	received, count;        load_options();    if (!options.modem)     {	err( "Configuration does not specify a valid modem device.\n" );    	stat = ModemError;	return( false ); // if we get this error, we already have a problem.    }        for (count = 0; count < 3; count++)    {	// the buffer is empty.	offset = 0;    	del_modem();		// Open the modem...	if( chat_mode ) 	{	    int flags = fcntl( STDIN_FILENO, F_GETFL );	    if( ( flags & O_ACCMODE ) == O_RDWR ) 	    {		cloned = modem = new WvModemBase( STDIN_FILENO );	    } 	    else 	    {		// The following is needed for diald.		// Stdin is not opened for read/write.		::close( STDIN_FILENO );		if( getenv( "MODEM" ) == NULL ) 		{		    err( "stdin not read/write and $MODEM not set\n" );		    exit( 1 );		}		// Try to open device $MODEM.		flags &= !O_ACCMODE;		flags |= O_RDWR;		int tty = ::open( getenv( "MODEM" ), flags );		if( tty == -1 ) 		{		    err( "can't open %s: %m\n", getenv( "MODEM" ) );		    exit( 1 );		}		cloned = modem = new WvModemBase( tty );	    }	} 	else	{	    cloned = modem = new WvModem( options.modem, options.baud );	}	if( !modem->isok() ) 	{	    err( "Cannot open %s: %s\n", options.modem, modem->errstr() );	    continue;	}		log( "Initializing modem.\n" );		// make modem happy	modem->print( "\r\r\r\r\r" );	while( modem->select( 100, true, false ) )	    modem->drain();		// Send up to nine init strings, in order.	int	init_count;	for( init_count=1; init_count<=9; init_count++ ) 	{	    WvString *this_str;	    switch( init_count ) 	    {	    case 1:    this_str = &options.init1;	break;	    case 2:    this_str = &options.init2;	break;	    case 3:    this_str = &options.init3;	break;	    case 4:    this_str = &options.init4;	break;	    case 5:    this_str = &options.init5;	break;	    case 6:    this_str = &options.init6;	break;	    case 7:    this_str = &options.init7;	break;	    case 8:    this_str = &options.init8;	break;	    case 9:	    default:		this_str = &options.init9;	break;	    }	    if( !! *this_str ) 	    {		modem->print( "%s\r", *this_str );		log( "Sending: %s\n", *this_str );				received = wait_for_modem( init_responses, 5000, true );		switch( received ) 		{		case -1:		    modem->print( "ATQ0\r" );		    log( "Sending: ATQ0\n" );		    received = wait_for_modem( init_responses, 500, true );		    modem->print( "%s\r", *this_str );		    log( "Re-Sending: %s\n", *this_str );		    received = wait_for_modem( init_responses, 5000, true );		    switch( received ) 		    {			case -1:			    err( "Modem not responding.\n" );			    return( false );			case 1:			    err( "Bad init string.\n" );			    return( false );		    }		    goto end_outer;		case 1:		    err( "Bad init string.\n" );		    goto end_outer;		}	    }	}	// Everything worked fine.	log( "Modem initialized.\n" );	return( true );		// allows us to exit the internal loop      end_outer:	continue;    }        // we tried 3 times and it didn't work.    return( false );}void WvDialer::del_modem(){    assert(cloned == modem);        if (modem)    {	modem->hangup();	WVRELEASE(modem);	cloned = NULL;    }}WvModemBase *WvDialer::take_modem(){    WvModemBase *_modem;        if (!modem)	init_modem();        _modem = modem;    cloned = modem = NULL;        return _modem;}void WvDialer::give_modem(WvModemBase *_modem){    del_modem();    cloned = modem = _modem;}void WvDialer::async_dial()/*************************/{    int	received;    if( stat == PreDial2 )     {    	// Wait for three seconds and then go to PreDial1.    	continue_select(3000);    	stat = PreDial1;    	return;    }        if( stat == PreDial1 )     {	// Hit enter a few times.	for( int i=0; i<3; i++ ) 	{	    modem->write( "\r", 1 );	    continue_select(500);	    if (!isok() || !modem)		break;	}	stat = Dial;	return;    }	    if( stat == Dial )     {    	// Construct the dial string.  We use the dial command, prefix,	// area code, and phone number as specified in the config file.	WvString *this_str;        switch( phnum_count ) 	{              case 0:     		this_str = &options.phnum;		break;            case 1:     		this_str = &options.phnum1;		break;            case 2:     		this_str = &options.phnum2;     		break;            case 3:     		this_str = &options.phnum3;     		break;            case 4:            default:                this_str = &options.phnum4;     		break;        }	WvString s( "%s%s%s%s%s\r", options.dial_cmd,				 options.dial_prefix,				 !options.dial_prefix ? "" : ",",				 options.areacode,				 *this_str );	modem->print( s );	log( "Sending: %s\n", s );	log( "Waiting for carrier.\n" );	stat = WaitDial;    }    received = async_wait_for_modem( dial_responses, true );        switch( received )     {    case -1:	// nothing -- return control.	if( time( NULL ) - last_rx  >= 60 ) 	{	    log( WvLog::Warning, "Timed out while dialing.  Trying again.\n" );	    stat = PreDial1;	    connect_attempts++;	    dial_stat = 1;	    	    //if Attempts in wvdial.conf is 0..dont do anything	    if(options.dial_attempts != 0)	    {		if(check_attempts_exceeded(connect_attempts))		{		    hangup();		}	    }	    	}	return;    case 0:	// CONNECT	        /*        if( chat_mode ) 	 {	  if( options.ask_password ) 	 {	    err( "Error: dial on demand does not work with option Ask Password = 1\n" );	    exit( 1 );	  }	  	  if( getuid() != 0 ) {	    err( "Hint: if authentication does not work, start wvdial.dod once as user root\n" );	  }	  	  WvPapChap papchap;	  papchap.put_secret( options.login, options.password, options.remote );	  if( getuid() == 0 ) {	    if( papchap.isok_pap() == false ) {	      err("Warning: Could not modify %s: %s\n",PAP_SECRETS, strerror(errno));	    }	    if( papchap.isok_chap() == false ) {	      err("Warning: Could not modify %s: %s\n",CHAP_SECRETS, strerror(errno));	    }	  }	}        */	      	if( options.stupid_mode == true || options.tonline == true ) 	{	    if( chat_mode ) 	    {		log( "Carrier detected.  Chatmode finished.\n" );		exit( 0 );	    } 	    else 	    {		log( "Carrier detected.  Starting PPP immediately.\n" );

⌨️ 快捷键说明

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