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

📄 gendial.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* CHK=0xC086 */char *revision = "1.31";/*+-------------------------------------------------------------------------	gendial.c - SCO UUCP dialer program device independent portion	wht@n4hgf.Mt-Park.GA.US  Configuration symbols:	HDB_UUCP		defined if HDB UUCP used on system, else old Version 2   Defined functions:	RCE_text(value)	SIGALRM_alert(sig)	_lputc(lchar)	_lputc_paced(pace_msec,lchar)	_lputs(string)	_lputs_paced(pace_msec,string)	_lread(rtime,error_ok)	call_ungetty(call_type)	cleanup(code)	decode_phone_number(userphno,result,resultlen)	dial_abort(sig)	display_termio(ttt,text)	get_uucp_uid()	instr(s1,s2)	lbreak()	lflash_DTR()	lflush()	lread(rtime)	lread_ignore(rtime)	ltd_report()	lwrite(str)	main(argc,argv)	make_printable(ch)	myexit(code)	open_dce()	rdchk(fd)	translate(ttab,str)  Usage:	dial ttyname telnumber speed 			dial -h ttyname speed  ttyname may be of style "ttyxx" or "/dev/ttyxx" (this is not standard)  Returns:		0x80	bit = 1 if connection failed		0x10	bit = 1 if line is also used for dialin #if !defined(OLDUUCP)		0x0f	if msb=1: error code				if msb=0: connected baud rate (0=same as dialed baud)                Note: this dialer always returns 0 in the low nibble                since cu and uucp expect it  Note: getty calls the dialer with -h whenever it starts up on a line  enabled in /etc/ttys and listed in Devices with this dialer.  Error codes are split into two categories:    1) (codes 0-11) Local problems are defined as tty port, or DCE    problems: problems that can be worked around by using a different    device.    2) (codes 12-15) Remote problems are phone busy, no answer, etc.:    attempt to connect to this remote system should be stopped.  Note: This dialer can be used both for the old "Version 2"   new HoneyDanBer UUCP.  In HDB, uugetty is used and ungetty is not  necessary. Define HDB_UUCP for HDB UUCP.  Note: This version of the dialer will NOT display the telephone number  on the console unless the actual uid is root or ECU is calling as  detected by a parse of argv[0].  Now, if uucico would just suppress  username and password information it emits to debug (some do).  See below for a description of lread() timing debug.--------------------------------------------------------------------------*//*+:EDITS:*//*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 *//*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA *//*:08-16-1992-03:08-wht@n4hgf-head off another POSIX plot *//*:08-10-1992-04:01-wht@n4hgf-use init_Nap *//*:07-17-1992-18:28-wht@n4hgf-remove Nap() and use common ../nap.o *//*:05-11-1992-17:54-wht@gyro-no naps in lflash_DTR on sun *//*:05-11-1992-16:43-wht@gyro-fix WORKING_SELECT nap once and for all *//*:03-30-1992-14:18-root@n4hgf-add lbreak *//*:03-29-1992-12:30-cma-removed sigint reference in nap *//*:02-02-1992-19:37-root@n4hgf-add ltd *//*:02-02-1992-17:45-root@n4hgf-_lread: allow rtime secs after each character *//*:01-26-1992-15:31-wht@n4hgf-gendial 1.2 for ecu 3.20- better hangup *//*:08-13-1991-14:36-wht@n4hgf-perror on dce open error *//*:07-25-1991-12:58-wht@n4hgf-ECU release 3.10 *//*:05-01-1991-21:28-wht@n4hgf-add dial timing *//*:03-12-1991-19:11-wht@n4hgf-if ecu dialing, show complete call progress *//*:07-19-1990-17:14-root@n4hgf-modify lread fata timeout handler *//*:05-26-1990-02:15-wht@n4hgf-creation */#include "dialer.h"/* * lread() timing debug * * if LTD_DEBUG_LEVEL is defined, it should be set to the DEBUG level * at which a DCE result arrival report should be printed in the event * of a DCE timeout.  This normally would be set at 6, the debugging * level for the timeout report itself.  Sample output: * * Arrival Report for 16 characters (in msec) *      0 A    19624 ^M   19624 ^J   19624 C    19624 O    19624 N    19624 N *  19624 E    19624 C    19624 T    19872      19872 F    19872 A    19872 S *  19888 T    19888 ^M * * comment out the following line for no LTD. */#define LTD_DEBUG_LEVEL 6#if defined(LTD_DEBUG_LEVEL)struct ltd {	unsigned char rdchar;	struct timeb timeb;};struct ltd ltds[MAXLINE];int ltd_count = 0;struct timeb ltd_initial_timeb;#endif /* LTD_DEBUG_LEVEL */#undef NULL	/* some stdio and param.h define these differently */#include <sys/param.h>#ifndef NULL		/* fake usual sys/param.h value */#define NULL 0#endiflong Nap();/* must be defined by device dependent module */extern long DCE_DTR_low_msec;		/* msecs DTR must be low to be recognized */extern long DCE_DTR_high_msec;		/* msecs for DCE to recover */extern long DCE_write_pace_msec;	/* msecs between chars written to DCE */extern DCE_RESULT DCE_results[];	/* DCE result codes */extern char *DCE_name;				/* name of DCE */extern char *DCE_revision;			/* DCE-dependent code revision */extern short DCE_hangup_CBAUD;		/* BXXX DCE hangup baud rate or zero *//* globals available to device dependent module */int gargc;					/* global copy of main's argv */char **gargv;				/* global copy of main's argv */char *dce_name;				/* full pathname of ACU device */char *telno = (char *)0;	/* phone number if dial type request */struct termio dce_termio;	/* last termio for device */int Debug = DBG;			/* set per -x flag */int dialing = 0;			/* set while dialing in progress */int dce_fd = -1;				/* file descriptor for dce_name */int DialerExitCode = RC_FAIL; /* return code */int status = 0;				/* set on errors */int hangup_flag = 0;		/* set when DCE being hung up */int hiCBAUD;				/* highest permissible baud rate */int loCBAUD;				/* lowest permissible baud rate */struct passwd *passwd;int uid;					/* user id of executor */int uid_uucp;				/* user id of uucp */int secure = 0;				/* non-zero to suppress display of secure							 * DCE traffic							 */int ecu_calling = 0;		/* true if ecu is dialing */int sigint = 0;			/* dummy for nap.c */unsigned char dialer_codes[26];	/* A-Z embedded phone number codes */jmp_buf	SIGALRM_alert_jmpbuf;DCE_RESULT *last_result;/*+-------------------------------------------------------------------------	get_uucp_uid()--------------------------------------------------------------------------*/intget_uucp_uid(){	passwd = getpwnam("uucp");	endpwent();	if(passwd)		return(passwd->pw_uid);	else		return(-1);}	/* end of get_uucp_uid *//*+-------------------------------------------------------------------------	instr(s1,s2)  find s2 in s1; returns 1 if found, 0 if not found--------------------------------------------------------------------------*/instr(s1,s2)register char *s1;char *s2;{	register len = strlen(s2);	while(s1 = strchr(s1,*s2))	{		if(!strncmp(s2,s1,len))			return(1);		s1++;	}	return(0);}	/* end of instr *//*+-------------------------------------------------------------------------	translate(ttab,str)  translate the pairs of characters present in the first string  whenever the first of the pair appears in the second string  (this routine from standard SCO dialer code)--------------------------------------------------------------------------*/voidtranslate(ttab,str)register char *ttab;char *str;{	register char *cptr;	while(*ttab && *(ttab + 1))	{		for(cptr = str; *cptr; cptr++)		{			if(*ttab == *cptr)				*cptr = *(ttab + 1);		}		ttab += 2;	}}	/* end of translate *//*+-------------------------------------------------------------------------	decode_phone_number(userphno,result,resultlen)decode user flags in phone number, returning phone number inresult, character flags in global dialer_codes[], 'A' or 'a'results in dialer_codes[0] being 1, etc.  Only letter codes areextracted.For example, if userphno contains "123,D45f", result returned"123,45" and only elements 3 and 5 of dialer_codes set to 1Function returns 0 if successful, -1 if result buffer too small--------------------------------------------------------------------------*/intdecode_phone_number(userphno,result,resultlen)register char *userphno;register char *result;int resultlen;{register itmp;	for(itmp = 0; itmp < sizeof(dialer_codes); itmp++)		dialer_codes[itmp] = 0;	if(!resultlen)		return(-1);	resultlen--;	/* leave room for null */	while(*userphno)	{		if(isalpha(*userphno))			dialer_codes[*userphno - ((isupper(*userphno)) ? 'A' : 'a')] = 1;		else		{			if(!resultlen--)				return(-1);			*result++ = *userphno;		}		userphno++;	}	*result = 0;	return(0);}	/* end of decode_phone_number *//*+-------------------------------------------------------------------------	make_printable(ch) - make a character "printable"--------------------------------------------------------------------------*/char *make_printable(ch)unsigned char ch;{static char buffer[10];char *cptr;#define	to_print(x)	((x)<' '?((x)+'@'):'?')	cptr = buffer;	/* if not root or uucp and info needs securing */	if(!ecu_calling && uid && (uid != uid_uucp) && secure)	{		*cptr++ = '?';	/* hide it */		*cptr = 0;		return(buffer);	}	if(iscntrl(ch) || !isprint(ch))	{		if(!isascii(ch))		{			/* Top bit is set */			*cptr++ = 'M';			*cptr++ = '-';			ch = toascii(ch);			/* Strip it */		}		if(iscntrl(ch))		{			*cptr++ = '^';			ch = to_print(ch);			/* Make it printable */		}	}	*cptr++ = ch;	*cptr = 0;	return(buffer);}	/* end of make_printable *//*+-------------------------------------------------------------------------	RCE_text(value)--------------------------------------------------------------------------*/char *RCE_text(value)int value;{static char errant[32];	switch(value & 0x0F)	{		case RCE_NULL: return("unknown or unclassified error");		case RCE_INUSE: return("line in use");		case RCE_SIG: return("killed with signal");		case RCE_ARGS: return("invalid arguments");		case RCE_PHNO: return("invalid phone number");		case RCE_SPEED: return("invalid line speed or bad connect speed");		case RCE_OPEN: return("cannot open line");		case RCE_IOCTL: return("ioctl error");		case RCE_TIMOUT: return("timeout");		case RCE_NOTONE: return("NO DIAL TONE");		case RCE_HANGUP: return("hangup failed\n");		case RCE_NORESP: return("DCE didn't respond.\n");		case RCE_BUSY: return("BUSY");		case RCE_NOCARR: return("NO CARRIER");		case RCE_ANSWER: return("NO ANSWER");	}	sprintf(errant,"code 0x%04x",value);	return(errant);}	/* end of RCE_text *//*+-------------------------------------------------------------------------	myexit(code) - all threads exit() thru here--------------------------------------------------------------------------*/voidmyexit(code)int code;{	alarm(0);	if(dialing)	{		if(code & RC_FAIL)		{			DEBUG(1,"dial failed: %s\n",RCE_text(code));		}		else		{			DEBUG(1,"dial succeeded\n",0);		}	}	DCE_exit(code);	/* should not return */	exit(code);		/* in case it does */}	/* end of myexit *//*+-------------------------------------------------------------------------	dial_abort(sig)--------------------------------------------------------------------------*/SIGTYPEdial_abort(sig)int sig;{	if(sig)	{		DEBUG(1,"\ndialer received signal %d\n\n",sig);	}	else	{		DEBUG(1,"\ndialer aborted, fail status=0x%02x\n",DialerExitCode);	}	DCE_abort(sig);	if(dce_fd != -1)	{		ioctl(dce_fd,TCGETA,&dce_termio);		dce_termio.c_cflag |= HUPCL;		/* make sure DCE hangs up */		ioctl(dce_fd,TCSETA,&dce_termio);		close(dce_fd);	}	if(sig)		DialerExitCode |= (RC_FAIL | RCE_SIG);	myexit(DialerExitCode);}	/* end of dial_abort *//*+-------------------------------------------------------------------------

⌨️ 快捷键说明

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