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

📄 termstat.c

📁 linux下telnet服务端的源码实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	/*	 * Some things should be deferred until after the pty state has	 * been set by the local process.  Do those things that have been	 * deferred now.  This only happens once.	 */	if (_terminit == 0) {		_terminit = 1;		defer_terminit();	}	netflush();	set_termbuf();	return;}  /* end of localstat *//* * flowstat * * Check for changes to flow control */voidflowstat(){	if (his_state_is_will(TELOPT_LFLOW)) {		if (tty_flowmode() != flowmode) {			flowmode = tty_flowmode();			net_output_data ("%c%c%c%c%c%c",					IAC, SB, TELOPT_LFLOW,					flowmode ? LFLOW_ON : LFLOW_OFF,					IAC, SE);		}		if (tty_restartany() != restartany) {			restartany = tty_restartany();			net_output_data ("%c%c%c%c%c%c",					IAC, SB, TELOPT_LFLOW,					restartany ? LFLOW_RESTART_ANY						   : LFLOW_RESTART_XON,					IAC, SE);		}	}}/* * clientstat * * Process linemode related requests from the client. * Client can request a change to only one of linemode, editmode or slc's * at a time, and if using kludge linemode, then only linemode may be * affected. */voidclientstat(register int code, register int parm1, register int parm2){	void netflush();	/*	 * Get a copy of terminal characteristics.	 */	init_termbuf();	/*	 * Process request from client. code tells what it is.	 */	switch (code) {	case TELOPT_LINEMODE:		/*		 * Don't do anything unless client is asking us to change		 * modes.		 */		uselinemode = (parm1 == WILL);		if (uselinemode != linemode) {			/*			 * If using kludge linemode, make sure that			 * we can do what the client asks.			 * We can not turn off linemode if alwayslinemode			 * and the ICANON bit is set.			 */			if (lmodetype == KLUDGE_LINEMODE) {				if (alwayslinemode && tty_isediting()) {					uselinemode = 1;				}			}			/*			 * Quit now if we can't do it.			 */			if (uselinemode == linemode)				return;			/*			 * If using real linemode and linemode is being			 * turned on, send along the edit mode mask.			 */			if (lmodetype == REAL_LINEMODE && uselinemode)			if (uselinemode)			{				useeditmode = 0;				if (tty_isediting())					useeditmode |= MODE_EDIT;				if (tty_istrapsig())					useeditmode |= MODE_TRAPSIG;				if (tty_issofttab())					useeditmode |= MODE_SOFT_TAB;				if (tty_islitecho())					useeditmode |= MODE_LIT_ECHO;				net_output_data ("%c%c%c%c%c%c%c", IAC,					SB, TELOPT_LINEMODE, LM_MODE,							useeditmode, IAC, SE);				editmode = useeditmode;			}			tty_setlinemode(uselinemode);			linemode = uselinemode;			if (!linemode)				send_will(TELOPT_ECHO, 1);		}		break;	case LM_MODE:	    {		register int ack, changed;		/*		 * Client has sent along a mode mask.  If it agrees with		 * what we are currently doing, ignore it; if not, it could		 * be viewed as a request to change.  Note that the server		 * will change to the modes in an ack if it is different from		 * what we currently have, but we will not ack the ack.		 */		 useeditmode &= MODE_MASK;		 ack = (useeditmode & MODE_ACK);		 useeditmode &= ~MODE_ACK;		 if (changed = (useeditmode ^ editmode)) {			/*			 * This check is for a timing problem.  If the			 * state of the tty has changed (due to the user			 * application) we need to process that info			 * before we write in the state contained in the			 * ack!!!  This gets out the new MODE request,			 * and when the ack to that command comes back			 * we'll set it and be in the right mode.			 */			if (ack)				localstat();			if (changed & MODE_EDIT)				tty_setedit(useeditmode & MODE_EDIT);			if (changed & MODE_TRAPSIG)				tty_setsig(useeditmode & MODE_TRAPSIG);			if (changed & MODE_SOFT_TAB)				tty_setsofttab(useeditmode & MODE_SOFT_TAB);			if (changed & MODE_LIT_ECHO)				tty_setlitecho(useeditmode & MODE_LIT_ECHO);			set_termbuf(); 			if (!ack) { 				net_output_data ("%c%c%c%c%c%c%c", IAC,					SB, TELOPT_LINEMODE, LM_MODE, 					useeditmode|MODE_ACK, 					IAC, SE); 			}			editmode = useeditmode;		}		break;	    }  /* end of case LM_MODE */	case TELOPT_NAWS:#ifdef	TIOCSWINSZ	    {		struct winsize ws;		def_col = parm1;		def_row = parm2;		/*		 * Defer changing window size until after terminal is		 * initialized.		 */		if (terminit() == 0)			return;		/*		 * Change window size as requested by client.		 */		ws.ws_col = parm1;		ws.ws_row = parm2;		(void) ioctl(pty, TIOCSWINSZ, (char *)&ws);	    }#endif	/* TIOCSWINSZ */		break;	case TELOPT_TSPEED:	    {		def_tspeed = parm1;		def_rspeed = parm2;		/*		 * Defer changing the terminal speed.		 */		if (terminit() == 0)			return;		/*		 * Change terminal speed as requested by client.		 * We set the receive speed first, so that if we can't		 * store seperate receive and transmit speeds, the transmit		 * speed will take precedence.		 */		tty_rspeed(parm2);		tty_tspeed(parm1);		set_termbuf();		break;	    }  /* end of case TELOPT_TSPEED */	default:		/* What? */		break;	}  /* end of switch */#if	defined(CRAY2) && defined(UNICOS5)	/*	 * Just in case of the likely event that we changed the pty state.	 */	rcv_ioctl();#endif	/* defined(CRAY2) && defined(UNICOS5) */	netflush();}  /* end of clientstat */#if	defined(CRAY2) && defined(UNICOS5)voidtermstat(){	needtermstat = 1;}void_termstat(){	needtermstat = 0;	init_termbuf();	localstat();	rcv_ioctl();}#endif	/* defined(CRAY2) && defined(UNICOS5) *//* * defer_terminit * * Some things should not be done until after the login process has started * and all the pty modes are set to what they are supposed to be.  This * function is called when the pty state has been processed for the first time. * It calls other functions that do things that were deferred in each module. */voiddefer_terminit(){	/*	 * local stuff that got deferred.	 */	if (def_tspeed != -1) {		clientstat(TELOPT_TSPEED, def_tspeed, def_rspeed);		def_tspeed = def_rspeed = 0;	}#ifdef	TIOCSWINSZ	if (def_col || def_row) {		struct winsize ws;		memset((char *)&ws, 0, sizeof(ws));		ws.ws_col = def_col;		ws.ws_row = def_row;		(void) ioctl(pty, TIOCSWINSZ, (char *)&ws);	}#endif	/*	 * The only other module that currently defers anything.	 */	deferslc();}  /* end of defer_terminit *//* * terminit * * Returns true if the pty state has been processed yet. */intterminit(){	return(_terminit);}  /* end of terminit */

⌨️ 快捷键说明

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