will_termtype.c

来自「tcp/ip原理的第三卷」· C语言 代码 · 共 47 行

C
47
字号
/* will_termtype.c - will_termtype */

#include <sys/types.h>

#include <stdio.h>

#include "telnet.h"

char	*getenv();

char		termtype;	/* non-zero if received "DO TERMTYPE"	*/
char		*term;		/* terminal name			*/
extern u_char	option_cmd;

/*------------------------------------------------------------------------
 * will_termtype - handle TELNET DO/DON'T TERMINAL-TYPE option
 *------------------------------------------------------------------------
 */
int
will_termtype(rfp, tfp, c)
FILE	*rfp, *tfp;
int	c;
{
	if (termtype) {
		if (option_cmd == TCDO)
			return 0;
	} else if (option_cmd == TCDONT)
		return 0;
	termtype = !termtype;
	if (termtype)
		if (!term && !(term = getenv("TERM")))
			termtype = !termtype;	/* can't do it... */
	(void) putc(TCIAC, rfp);
	if (termtype)
		(void) putc(TCWILL, rfp);
	else
		(void) putc(TCWONT, rfp);
	(void) putc((char)c, rfp);
	if (termtype) {	/* set up binary data path; send WILL, DO */
		option_cmd = TCWILL;
		(void) do_txbinary(rfp, tfp, TOTXBINARY);
		option_cmd = TCDO;
		(void) will_txbinary(rfp, tfp, TOTXBINARY);
	}
	return 0;
}

⌨️ 快捷键说明

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