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

📄 gendial.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	cleanup(code) - close device and exit--------------------------------------------------------------------------*/voidcleanup(code)int code;{	if(code & RC_FAIL)	{	/* if we failed, drop DTR (in dial_abort) */		DialerExitCode = code;		dial_abort(0);	}	else 		myexit(code);}	/* end of cleanup *//*+-------------------------------------------------------------------------	SIGALRM_alert(sig) - catch alarm call and do longjmp--------------------------------------------------------------------------*/SIGTYPESIGALRM_alert(sig)int sig;{	longjmp(SIGALRM_alert_jmpbuf,1);}	/* end of SIGALRM_alert *//*+-------------------------------------------------------------------------	ltd_report()--------------------------------------------------------------------------*/#if defined(LTD_DEBUG_LEVEL)voidltd_report(){struct ltd *l = ltds;long msec;int col = 0;	if(!ltd_count)	{		fputs("DCE was completely silent\n",stderr);		return;	}	fprintf(stderr,"Arrival Report for %d characters (in msec)\n",ltd_count);	while(ltd_count--)	{		msec =  ((l->timeb.time - ltd_initial_timeb.time) * 1000L) +			(l->timeb.millitm - ltd_initial_timeb.millitm);		fprintf(stderr,"%6ld %-3.3s ",msec,make_printable(l->rdchar));		l++;		if(++col > 6)		{			col = 0;			fputs("\n",stderr);		}	}	if(col)		fputs("\n",stderr);	ltd_count = 0;}	/* end of ltd_report */#endif /* LTD_DEBUG_LEVEL *//*+-------------------------------------------------------------------------	_lread(rtime,error_ok)  Common code for lread() and lread_ignore()  Returns DCE_RESULT->code from matching DCE_RESULT->result  or if no match is found and the first digit of the modem  response is numeric, the the numeric value is returned ored  with 0x4000.  If error_ok is true and a timeout occurs, -1 is returned.  If error_ok is false and a timeout occurs,     cleanup(RC_FAIL | RCE_TIMOUT | DialerExitCode);     is called, which results in dial_abort(0) thus DCE_abort(0)     being called.--------------------------------------------------------------------------*/int_lread(rtime,error_ok)int rtime;int error_ok;{int itmp;char rdchar;DCE_RESULT *mr;char buf[MAXLINE];char *bp;char *cptr;#if defined(LTD_DEBUG_LEVEL)	ltd_count = 0;	if(Debug >= LTD_DEBUG_LEVEL)		ftime(&ltd_initial_timeb);#endif /* LTD_DEBUG_LEVEL */	if(error_ok)	{		signal(SIGALRM,SIGALRM_alert);		if(setjmp(SIGALRM_alert_jmpbuf) != 0)		{			DEBUG(6,">>-%s\n","TIMEOUT");#if defined(LTD_DEBUG_LEVEL)			if(Debug >= LTD_DEBUG_LEVEL)				ltd_report();#endif /* LTD_DEBUG_LEVEL */			return(-1);		}	}	else	{		signal(SIGALRM,SIGALRM_alert);		if(setjmp(SIGALRM_alert_jmpbuf) != 0)		{			DEBUG(6,">>-%s\n","TIMEOUT (FATAL)");#if defined(LTD_DEBUG_LEVEL)			if(Debug >= LTD_DEBUG_LEVEL)				ltd_report();#endif /* LTD_DEBUG_LEVEL */			cleanup(RC_FAIL | RCE_TIMOUT | DialerExitCode);		}	}	bp = buf;	alarm(rtime);	DEBUG(6,"DCE returned %s","<<");	while((itmp = read(dce_fd,&rdchar,1)) == 1)	{		alarm(rtime);	/* allow rtime secs after each character */		if(bp >= (buf + MAXLINE))		{			alarm(0);			DEBUG(6,"\n>>-FAIL (%s)\n","BUFFER OVERFLOW");			myexit(RC_FAIL | RCE_NULL);		}		*bp++ = (rdchar &= 0x7F);		*bp = 0;#if defined(LTD_DEBUG_LEVEL)		if(Debug >= LTD_DEBUG_LEVEL)		{			ltds[ltd_count].rdchar = rdchar;			ftime(&ltds[ltd_count++].timeb);		}#endif /* LTD_DEBUG_LEVEL */		DEBUG(6,"%s",make_printable(rdchar));		if(rdchar == 0x0A)			DEBUG(6,"\n",0);		if(rdchar == '\r')		{			cptr = buf;			if(*cptr == 0x0A)				cptr++;			for(mr = DCE_results; mr->result; ++mr)			{				if(instr(buf,mr->result))				{					alarm(0);					DEBUG(6,">>-%s\n","SUCCESS");					if(strcmp(mr->result,"OK"))  /* not so modem independent */						DEBUG(6,"got %s\n",mr->result);					else						DEBUG(8,"got %s\n",mr->result);					last_result = mr;					return(mr->code);				}			}			if(isdigit(*cptr))			{				alarm(0);				itmp = atoi(cptr);				DEBUG(6,">>-SUCCESS (NUMERIC RESULT %d)\n",itmp);				return(rfNumeric | itmp);			}			bp = buf;		}	}	alarm(0);	if(Debug >= 6)	{		ff(se,">>-FAIL (%s %d)",			(itmp < 0) ? "READ ERRNO" : "READ LENGTH",			(itmp < 0) ? errno : 0);	}	DEBUG(4," incomplete or no response\n",0);	return(-1);}	/* end of _lread *//*+-------------------------------------------------------------------------	lread_ignore(rtime)  Reads from the ACU until it finds a valid response (found in  DCE_results), a numeric result code (e.g., S-register value), or times  out after rtime seconds.  The numeric response feature is designed  for Hayes-style DCEs and may not be useful for other DCE types  Returns: DCE_RESULT code, numeric result + 128, or -1 on timeout or error--------------------------------------------------------------------------*/intlread_ignore(rtime)int rtime;{	return(_lread(rtime,1));}	/* end of lread_ignore *//*+-------------------------------------------------------------------------	lread(rtime)  Same as lread_ignore, but does not return on timeout or error--------------------------------------------------------------------------*/intlread(rtime)int rtime;{int rtn = _lread(rtime,0);	if(rtn < 0)		myexit(RC_FAIL | RCE_TIMOUT);	return(rtn);}	/* end of lread *//*+-------------------------------------------------------------------------	lflush() - flushes input clists for DCE--------------------------------------------------------------------------*/voidlflush(){	ioctl(dce_fd,TCFLSH,0);}	/* end of lflush *//*+-----------------------------------------------------------------------	_lputc(lchar) -- write char to comm line------------------------------------------------------------------------*/void_lputc(lchar)char lchar;{	write(dce_fd,&lchar,1);	DEBUG(6,"%s",make_printable(lchar));}	/* end of _lputc *//*+-----------------------------------------------------------------------	_lputc_paced(pace_msec,lchar) -- write char to comm line with pacing------------------------------------------------------------------------*/void_lputc_paced(pace_msec,lchar)register long pace_msec;register char lchar;{	_lputc(lchar);	if(pace_msec)		Nap(pace_msec);}	/* end of _lputc_paced *//*+-----------------------------------------------------------------------	_lputs(string) -- write string to comm line------------------------------------------------------------------------*/void_lputs(string)register char *string;{	while(*string)		_lputc(*string++);}/*+-----------------------------------------------------------------------	_lputs_paced(pace_msec,string) -- write string to comm line  with time between each character ------------------------------------------------------------------------*/void_lputs_paced(pace_msec,string)register long pace_msec;register char *string;{	while(*string)		_lputc_paced(pace_msec,*string++);}	/* end of _lputs_paced *//*+-------------------------------------------------------------------------	lwrite(str) - output string to dce_name  Returns:	0 on completion, -1 on write errors.--------------------------------------------------------------------------*/voidlwrite(str)register char *str;{	Nap(200L);	DEBUG(6,"Sent DCE %s","<<");	_lputs_paced(DCE_write_pace_msec,str);	DEBUG(6,">>-%s\n","SUCCESS");	ioctl(dce_fd,TCSETAW,&dce_termio);	/* wait for I/O to drain */}	/* end of lwrite *//*+-------------------------------------------------------------------------	lbreak()--------------------------------------------------------------------------*/voidlbreak(){	DEBUG(6,"Sent BREAK to DCE %s","<<");	ioctl(dce_fd,TCSBRK,(char *)1);	DEBUG(6,">>-%s\n","SUCCESS");}	/* end of lbreak *//*+-------------------------------------------------------------------------	lflash_DTR() - flash DTRDTR is lowered and raised again.  The timing can be modified on aper-DCE basis.On SunOS and SVR4, an open/close of the line is required to get DTR backup. SVR3 does not seem to need this (ISC asy, SCO sio, Uwe Doering's FAS)but we do it anyway--------------------------------------------------------------------------*/voidlflash_DTR(){#undef NEED_REOPEN#if defined(sun) || defined(SVR4)#define NEED_REOPEN	int tempfd;#endif	struct termio b0t;	b0t = dce_termio;	b0t.c_cflag &= ~CBAUD;	ioctl(dce_fd,TCSETA,(char *)&b0t);		/* drop DTR */	DEBUG(6,"setting DTR low ... ","");#ifdef NEED_REOPEN	if ((tempfd = open(dce_name,O_NDELAY | O_RDWR,0777)) != -1)		close(tempfd);#else	Nap((DCE_DTR_low_msec) ? DCE_DTR_low_msec : 300L);#endif	ioctl(dce_fd,TCSETA,(char *)&dce_termio);	/* raise DTR */	DEBUG(6,"back to high","");	Nap((DCE_DTR_high_msec) ? DCE_DTR_high_msec : 300L);	DEBUG(6,"\n","");#undef NEED_REOPEN}	/* end of lflash_DTR *//*+-------------------------------------------------------------------------	call_ungetty(call_type)type: 'a' - acquire dce_name      't' - test to see if dce_name should be returned      'r' - return dce_nameThis function is a no-op in HDB UUCP versions--------------------------------------------------------------------------*/call_ungetty(call_type)char call_type;{#if defined(HDB_UUCP)	switch(call_type)	{		case 'a': return(UG_NOTENAB);		/* simulate complete success */		case 't': return(UG_RESTART);		/* simulate need for re-setup */		case 'r': return(0);				/* simulate complete success */	}	return(0);#else /* HDB_UUCP */int itmp;int pid;unsigned int wait_status;static char *ungetty = "/usr/lib/uucp/ungetty";	if((pid = fork()) == 0)	{		if(Debug >= 5)			ff(se,"%s: %s %s called\n",*gargv,ungetty,dce_name);		switch(call_type)		{			case 'a':				execl(ungetty,"ungetty",dce_name + 5,(char *)0);				break;			case 't':				execl(ungetty,"ungetty","-t",dce_name + 5,(char *)0);				break;			case 'r':				execl(ungetty,"ungetty","-r",dce_name + 5,(char *)0);				break;		}		ff(se,"%s exec error %d (%s)\n",ungetty,errno,sys_errlist[errno]);		_exit(-1);	}	while(((itmp = wait(&wait_status)) != pid) && itmp != -1)		;	if(Debug >= 6)

⌨️ 快捷键说明

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