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

📄 dcet3000.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
termination of the program.  Read timeouts from calling lread_ignore()return -1; you handle the execption here.Any necessary coding of phone numbers, switch settings or otherconfiguration necessary for this function to succeed should bedocumented at the top of the module.T3000-specific comments: S0=0        dont allow connect while dialing S63=0       pass BREAK signal to remote modem in sequence S64=0       abort dialing if characters sent by DTE S66=1       lock the interface speed--------------------------------------------------------------------------*/intDCE_dial(telno_str)char *telno_str;{char cmd[128];char phone[50];int s111_set = 0;int timeout;int result;int rrings = 0;long then;long now;char *cptr;char *dialout_default = "AT S0=0 S7=40 S63=0 S64=0 S66=1\r";#define MDVALID	 "0123456789FfKkMmNnRrSsUuWwXxVv*#,!/()-"#ifdef WHT#define RRING_MAX 3#else#define RRING_MAX 6#endif/* preliminary setup */	translate("=,-,",telno_str);	if(strspn(telno_str,MDVALID) != strlen(telno_str))	{		DEBUG(1,"phone number has invalid characters\n",0);		return(RC_FAIL | RCE_PHNO);	}	if(decode_phone_number(telno_str,phone,sizeof(phone)))	{		DEBUG(1,"phone number too long\n",0);		return(RC_FAIL | RCE_PHNO);	}/* walk through dialer codes, doing custom setup */	strcpy(cmd,"AT");	cptr = cmd + strlen(cmd);	if(dialer_codes['F' - 'A'])	{		DEBUG(5,"XON/XOFF FLOW CONTROL requested\n",0);		strcat(cmd,"S69=2");	}	if(dialer_codes['K' - 'A'])	{		DEBUG(5,"KERMIT requested\n",0);		strcat(cmd,"S111=10");		s111_set++;	}	if(dialer_codes['X' - 'A'])	{		DEBUG(5,"XMODEM requested\n",0);		strcat(cmd,"S111=20");		s111_set++;	}	if(dialer_codes['U' - 'A'])	{		DEBUG(5,"UUCP requested\n",0);		strcat(cmd,"S111=30");		s111_set++;	}	if(dialer_codes['V' - 'A'])	{		DEBUG(5,"V.32 requested\n",0);		if(hiCBAUD != B9600)		{			DEBUG(1,"V.32 baud rate not 9600\n",0);			return(RC_FAIL | RCE_SPEED);		}		if((dialer_codes['P' - 'A']) || s111_set)		{			DEBUG(1,"both PEP and V.32 requested\n",0);			return(RC_FAIL | RCE_ARGS);		}		strcat(cmd,"S50=6");	}	if((dialer_codes['P' - 'A']) || s111_set ||		((hiCBAUD >= B9600) && (!dialer_codes['V' - 'A'])))	{		if(hiCBAUD < B9600)		{			DEBUG(1,"baud rate not high enough for PEP\n",0);			return(RC_FAIL | RCE_SPEED);		}		if(dialer_codes['P' - 'A'])			DEBUG(5,"PEP requested\n",0);		else			DEBUG(5,"PEP inferred: speed >= 9600 and no V.32 requested\n",0);		dialer_codes['P' - 'A'] = 1;		strcat(cmd,"S50=255");	}	init_T3000();	DEBUG(2,"--> issuing default setup command\n",0);	lwrite(dialout_default);	if(lread(5) != rOk)	{		DEBUG(1,"default dialout setup failed\n",0);		return(RC_FAIL | RCE_NULL);	}/* issue the custom setup command */	if(*cptr)	{		DEBUG(2,"--> issuing custom setup cmd\n",0);		strcat(cmd,"\r");		lwrite(cmd);		if(lread(5) != rOk)		{			DEBUG(1,"custom modem setup failed\n",0);			return(RC_FAIL | RCE_NULL);		}	}/* * calculate a timeout for the connect * allow a minimum of 40 seconds, but if V.32 or PEP, 90 * also if long distance (North American calculation here) * make it 132 (S7 is calculated as timeout * .9) */	timeout = 40;	if((phone[0] == '1') && (phone[0] != '0'))		timeout = 132;	if((timeout < 90) && (dialer_codes['V' - 'A'] || dialer_codes['P' - 'A']))		timeout = 90;	for(cptr = phone; cptr = strchr(cptr,','); cptr++)		timeout += 2;	/* add extra time for pause characters */	DEBUG(4,"wait for connect = %d seconds\n",timeout);	if(Debug > 8)	{		lwrite("AT&V\r");		lread_ignore(40);	}/* indicate non-root should not see DTE->DCE traffic */	secure = 1;/* * build and issue the actual dialing command * if root, let him see number, otherwise just say "remote system" */	DEBUG(1,"--> dialing %s\n", (!ecu_calling & uid)		? "remote system" : telno_str);#ifdef WHT	if(!strncmp(*gargv,"ECU",3))		dialer_codes['S' - 'A'] = 1;#endif	sprintf(cmd,"ATM%dS7=%dDT%s\r",		((dialer_codes['S' - 'A']) && !(dialer_codes['N' - 'A'])) ? 1 : 0,		(timeout * 9) / 10, phone);	/* cmd string can only be 80 characters including "AT" */	if(strlen(cmd) > 80)	{		DEBUG(1,"phone number string too long\n",0);		cleanup(RC_FAIL | RCE_PHNO);	}	lwrite(cmd);/* indicate non-root can see DTE->DCE traffic */	secure = 0;/* wait for connect */WAIT_FOR_CONNECT:	time(&then);	result = lread(timeout);	if(!(result & rfConnect))	{		switch(result & rfMASK)		{		case rNoCarrier:			return(RC_FAIL | ((rrings > 2) ? RCE_ANSWER : RCE_NOTONE));		case rNoDialTone:			return(RC_FAIL | RCE_NOTONE);		case rBusy:			return(RC_FAIL | RCE_BUSY);		case rNoAnswer:			return(RC_FAIL | RCE_ANSWER);		case rRring:			if(rrings++ >= RRING_MAX)				return(RC_FAIL | RCE_ANSWER);		case rDialing:			time(&now);			if((timeout -= ((int)(then - now))) > 0)				goto WAIT_FOR_CONNECT;		case rError:		default:			return(RC_FAIL | RCE_NULL);		}	}	return(0);		/* succeeded */}	/* end of DCE_dial *//***********************************************************  You probably do not need to modify the code below here ***********************************************************//*+-------------------------------------------------------------------------	DCE_abort(sig) - dial attempt aborted sig =  0 if non-signal abort (read timeout, most likely)     != 0 if non-SIGALRM signal caught extern int dialing set  1 if dialing request was active,                    else 0 if hangup request was activeThis is a chance for the DCE-specific code to do anything itneeds to clean up after a failure.  Note that if a dialingcall fails, it is the responsibility of the higher-levelprogram calling the dialer to call it again with a hangup request, sothis function is usually a no-op.--------------------------------------------------------------------------*/voidDCE_abort(sig)int sig;{	DEBUG(10,"DCE_abort(%d);\n",sig);}	/* end of DCE_abort *//*+-------------------------------------------------------------------------	DCE_exit(exitcode) - "last chance for gas" in this incarnationThe independent portion of the dialer program calls this routine inlieu of exit() in every case except one (see DCE_argv_hook() below).Normally, this function just passes it's argument to exit(), butany necessary post-processing can be done.  The function must,however, eventually call exit(exitcode);--------------------------------------------------------------------------*/voidDCE_exit(exitcode)int exitcode;{	DEBUG(10,"DCE_exit(%d);\n",exitcode);	exit(exitcode);}	/* end of DCE_exit *//*+-------------------------------------------------------------------------	DCE_argv_hook(argc,argv,optind,unrecognized_switches)This hook gives DCE-specific code a chance to look over the entirecommand line, such as for -z Telebit processing.argc andf argv are the same values passed to main(),optind is the value of optind at the end of normal getopt processing.unrecognized_switches is the count of switches not handled by main().Specifically, -h and -x are standard switches.Normally, this function should just return RC_FAIL|RCE_ARGS if there areany unrecognized switches, otherwise zero.  If you keep your nose cleanthough, you can do anything you need to do here and exit the program.Note: only simple switches (with no argument) may be used with thisfacility if the functrion is to return,' since main()'s getopt() willstop processing switches if it runs into an unrecognized switch with anargument.If the function returns a non-zero value, then the value will be passedDIRECTLY to exit() with no further ado.  Thus, a non-zero value must beof the format expected by dialer program callers, with RC_FAIL set as aminimum.--------------------------------------------------------------------------*/intDCE_argv_hook(argc,argv,optind,unrecognized_switches)int argc;char **argv;int optind;int unrecognized_switches;{	if(unrecognized_switches)		return(RC_FAIL | RCE_ARGS);	return(0);}	/* end of DCE_argv_hook *//* vi: set tabstop=4 shiftwidth=4: */

⌨️ 快捷键说明

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