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

📄 commands.cc

📁 这是关于远程登陆TELNET 的源代码 已经测试过的。
💻 CC
📖 第 1 页 / 共 4 页
字号:
static int togbinary(int val) {    donebinarytoggle = 1;    if (val >= 0) {	binmode = val;    } else {	if (my_want_state_is_will(TELOPT_BINARY) &&				my_want_state_is_do(TELOPT_BINARY)) {	    binmode = 1;	} else if (my_want_state_is_wont(TELOPT_BINARY) &&				my_want_state_is_dont(TELOPT_BINARY)) {	    binmode = 0;	}	val = binmode ? 0 : 1;    }    if (val == 1) {	if (my_want_state_is_will(TELOPT_BINARY) &&					my_want_state_is_do(TELOPT_BINARY)) {	    printf("Already operating in binary mode with remote host.\n");	} else {	    printf("Negotiating binary mode with remote host.\n");	    tel_enter_binary(3);	}    } else {	if (my_want_state_is_wont(TELOPT_BINARY) &&					my_want_state_is_dont(TELOPT_BINARY)) {	    printf("Already in network ascii mode with remote host.\n");	} else {	    printf("Negotiating network ascii mode with remote host.\n");	    tel_leave_binary(3);	}    }    return 1;}static int togrbinary(int val) {    donebinarytoggle = 1;    if (val == -1)	val = my_want_state_is_do(TELOPT_BINARY) ? 0 : 1;    if (val == 1) {	if (my_want_state_is_do(TELOPT_BINARY)) {	    printf("Already receiving in binary mode.\n");	} 	else {	    printf("Negotiating binary mode on input.\n");	    tel_enter_binary(1);	}    }     else {	if (my_want_state_is_dont(TELOPT_BINARY)) {	    printf("Already receiving in network ascii mode.\n");	} else {	    printf("Negotiating network ascii mode on input.\n");	    tel_leave_binary(1);	}    }    return 1;}static int togxbinary(int val) {    donebinarytoggle = 1;    if (val == -1)	val = my_want_state_is_will(TELOPT_BINARY) ? 0 : 1;    if (val == 1) {	if (my_want_state_is_will(TELOPT_BINARY)) {	    printf("Already transmitting in binary mode.\n");	} 	else {	    printf("Negotiating binary mode on output.\n");	    tel_enter_binary(2);	}    }     else {	if (my_want_state_is_wont(TELOPT_BINARY)) {	    printf("Already transmitting in network ascii mode.\n");	} 	else {	    printf("Negotiating network ascii mode on output.\n");	    tel_leave_binary(2);	}    }    return 1;}static int netdata;		/* Print out network data flow */static int prettydump;	/* Print "netdata" output in user readable format */static int termdata;    /* Print out terminal data flow */static int togglehelp(int);struct togglelist {    const char *name;			/* name of toggle */    const char *help;			/* help message */    int (*handler)(int);	/* routine to do actual setting */    int *variable;    const char *actionexplanation;};static struct togglelist Togglelist[] = {    { "autoflush", "flushing of output when sending interrupt characters",      NULL, &autoflush,      "flush output when sending interrupt characters" },    { "autosynch", "automatic sending of interrupt characters in urgent mode",      NULL, &autosynch,      "send interrupt characters in urgent mode" },#if 0    { "autologin", "automatic sending of login and/or authentication info",      NULL, &autologin,      "send login name and/or authentication information" },    { "authdebug", "Toggle authentication debugging",      auth_togdebug, NULL,      "print authentication debugging information" },    { "autoencrypt", "automatic encryption of data stream",      EncryptAutoEnc, NULL,      "automatically encrypt output" },    { "autodecrypt", "automatic decryption of data stream",      EncryptAutoDec, NULL,      "automatically decrypt input" },    { "verbose_encrypt", "Toggle verbose encryption output",      EncryptVerbose, NULL,      "print verbose encryption output" },    { "encdebug", "Toggle encryption debugging",      EncryptDebug, NULL,      "print encryption debugging information" },#endif    { "skiprc", "don't read ~/.telnetrc file",      NULL, &skiprc,      "read ~/.telnetrc file" },    { "binary",      "sending and receiving of binary data",      togbinary, NULL,      NULL },    { "inbinary", "receiving of binary data",      togrbinary, NULL,      NULL },    { "outbinary", "sending of binary data",      togxbinary, 0,      NULL },    { "crlf", "sending carriage returns as telnet <CR><LF>",      togcrlf, &crlf,      NULL },    { "crmod", "mapping of received carriage returns",      NULL, &crmod,      "map carriage return on output" },    { "localchars", "local recognition of certain control characters",      lclchars, &localchars,      "recognize certain control characters" },    { " ", "", 0, 0, 0 },		/* empty line */#if defined(TN3270) && !defined(__linux__)    { "apitrace", "(debugging) toggle tracing of API transactions",      NULL, &apitrace,      "trace API transactions" },    { "cursesdata", "(debugging) toggle printing of hexadecimal curses data",      NULL, &cursesdata,      "print hexadecimal representation of curses data" },#endif	/* TN3270 and not linux */    { "debug", "debugging",      togdebug,	&debug,      "turn on socket level debugging" },    { "netdata", "printing of hexadecimal network data (debugging)",      NULL, &netdata,      "print hexadecimal representation of network traffic" },    { "prettydump","output of \"netdata\" to user readable format (debugging)",      NULL, &prettydump,      "print user readable output for \"netdata\"" },    { "options", "viewing of options processing (debugging)",      NULL, &showoptions,      "show option processing" },    { "termdata", "(debugging) toggle printing of hexadecimal terminal data",      NULL, &termdata,      "print hexadecimal representation of terminal traffic" },    { "?", NULL, togglehelp, 0, 0 },    { "help", NULL, togglehelp, 0, 0 },    { 0, 0, 0, 0, 0 }};static int togglehelp(int) {    struct togglelist *c;    for (c = Togglelist; c->name; c++) {	if (c->help) {	    if (*c->help)		printf("%-15s toggle %s\n", c->name, c->help);	    else		printf("\n");	}    }    printf("\n");    printf("%-15s %s\n", "?", "display help information");    return 0;}static void settogglehelp(int set) {    struct togglelist *c;    for (c = Togglelist; c->name; c++) {	if (c->help) {	    if (*c->help)		printf("%-15s %s %s\n", c->name, set ? "enable" : "disable",						c->help);	    else		printf("\n");	}    }}#define	GETTOGGLE(name) (struct togglelist *) \		genget(name, (char **) Togglelist, sizeof(struct togglelist))static int toggle(int argc, const char *argv[]) {    int retval = 1;    const char *name;    struct togglelist *c;    if (argc < 2) {	fprintf(stderr,	    "Need an argument to 'toggle' command.  'toggle ?' for help.\n");	return 0;    }    argc--;    argv++;    while (argc--) {	name = *argv++;	c = GETTOGGLE(name);	if (c == AMBIGUOUS) {	    fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\n",					name);	    return 0;	} 	else if (c == 0) {	    fprintf(stderr, "'%s': unknown argument ('toggle ?' for help).\n",					name);	    return 0;	} 	else {	    if (c->variable) {		*c->variable = !*c->variable;		/* invert it */		if (c->actionexplanation) {		    printf("%s %s.\n", *c->variable? "Will" : "Won't",							c->actionexplanation);		}	    }	    if (c->handler) {		retval &= (*c->handler)(-1);	    }	}    }    return retval;}/* * The following perform the "set" command. */struct setlist {    const char *name;				/* name */    const char *help;				/* help information */    void (*handler)(const char *);    cc_t *charp;			/* where it is located at */};static struct setlist Setlist[] = {#ifdef	KLUDGELINEMODE    { "echo", 	"character to toggle local echoing on/off", 0, &echoc },#endif    { "escape",	"character to escape back to telnet command mode", 0, &escapechar },    { "rlogin", "rlogin escape character", 0, &rlogin },    { "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile},    { " ", "", 0, 0 },    { " ", "The following need 'localchars' to be toggled true", 0, 0 },    { "flushoutput", "character to cause an Abort Output", 0, termFlushCharp },    { "interrupt", "character to cause an Interrupt Process", 0, termIntCharp },    { "quit",	"character to cause an Abort process", 0, termQuitCharp },    { "eof",	"character to cause an EOF ", 0, termEofCharp },    { " ", "", 0, 0 },    { " ", "The following are for local editing in linemode", 0, 0 },    { "erase",	"character to use to erase a character", 0, termEraseCharp },    { "kill",	"character to use to erase a line", 0, termKillCharp },    { "lnext",	"character to use for literal next", 0, termLiteralNextCharp },    { "susp",	"character to cause a Suspend Process", 0, termSuspCharp },    { "reprint", "character to use for line reprint", 0, termRprntCharp },    { "worderase", "character to use to erase a word", 0, termWerasCharp },    { "start",	"character to use for XON", 0, termStartCharp },    { "stop",	"character to use for XOFF", 0, termStopCharp },    { "forw1",	"alternate end of line character", 0, termForw1Charp },    { "forw2",	"alternate end of line character", 0, termForw2Charp },    { "ayt",	"alternate AYT character", 0, termAytCharp },    { 0, 0, 0, 0 }};#if	defined(CRAY) && !defined(__STDC__)/* Work around compiler bug in pcc 4.1.5 */    void_setlist_init(){#ifndef	KLUDGELINEMODE#define	N 5#else#define	N 6#endif	Setlist[N+0].charp = &termFlushChar;	Setlist[N+1].charp = &termIntChar;	Setlist[N+2].charp = &termQuitChar;	Setlist[N+3].charp = &termEofChar;	Setlist[N+6].charp = &termEraseChar;	Setlist[N+7].charp = &termKillChar;	Setlist[N+8].charp = &termLiteralNextChar;	Setlist[N+9].charp = &termSuspChar;	Setlist[N+10].charp = &termRprntChar;	Setlist[N+11].charp = &termWerasChar;	Setlist[N+12].charp = &termStartChar;	Setlist[N+13].charp = &termStopChar;	Setlist[N+14].charp = &termForw1Char;	Setlist[N+15].charp = &termForw2Char;	Setlist[N+16].charp = &termAytChar;#undef	N}#endif	/* defined(CRAY) && !defined(__STDC__) */static struct setlist *getset(const char *name){    return (struct setlist *)		genget(name, (char **) Setlist, sizeof(struct setlist));}void set_escape_char(char *s) {    if (rlogin != _POSIX_VDISABLE) {	rlogin = (s && *s) ? special(s) : _POSIX_VDISABLE;	printf("Telnet rlogin escape character is '%s'.\n",	       control(rlogin));    }     else {	escapechar = (s && *s) ? special(s) : _POSIX_VDISABLE;	printf("Telnet escape character is '%s'.\n", control(escapechar));    }}static int setcmd(int argc, const char *argv[]) {    int value;    struct setlist *ct;    struct togglelist *c;    if (argc < 2 || argc > 3) {	printf("Format is 'set Name Value'\n'set ?' for help.\n");	return 0;    }    if ((argc == 2) && (isprefix(argv[1], "?") || isprefix(argv[1], "help"))) {	for (ct = Setlist; ct->name; ct++)	    printf("%-15s %s\n", ct->name, ct->help);	printf("\n");	settogglehelp(1);	printf("%-15s %s\n", "?", "display help information");	return 0;    }    ct = getset(argv[1]);    if (ct == 0) {	c = GETTOGGLE(argv[1]);	if (c == 0) {	    fprintf(stderr, "'%s': unknown argument ('set ?' for help).\n",			argv[1]);	    return 0;	} 	else if (c == AMBIGUOUS) {	    fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",			argv[1]);	    return 0;	}	if (c->variable) {	    if ((argc == 2) || (strcmp("on", argv[2]) == 0))		*c->variable = 1;	    else if (strcmp("off", argv[2]) == 0)		*c->variable = 0;	    else {		printf("Format is 'set togglename [on|off]'\n'set ?' for help.\n");		return 0;	    }	    if (c->actionexplanation) {		printf("%s %s.\n", *c->variable? "Will" : "Won't",							c->actionexplanation);	    }	}	if (c->handler)	    (*c->handler)(1);    }     else if (argc != 3) {	printf("Format is 'set Name Value'\n'set ?' for help.\n");	return 0;    }     else if (ct == AMBIGUOUS) {	fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",			argv[1]);	return 0;    }     else if (ct->handler) {	(*ct->handler)(argv[2]);	printf("%s set to \"%s\".\n", ct->name, (char *)ct->charp);    }     else {	if (strcmp("off", argv[2])) {	    value = special(argv[2]);	} else {	    value = _POSIX_VDISABLE;	}	*(ct->charp) = (cc_t)value;	printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));    }    slc_check();    return 1;}static int unsetcmd(int argc, const char *argv[]) {    struct setlist *ct;    struct togglelist *c;    const char *name;    if (argc < 2) {	fprintf(stderr,	    "Need an argument to 'unset' command.  'unset ?' for help.\n");	return 0;    }    if (isprefix(argv[1], "?") || isprefix(argv[1], "help")) {	for (ct = Setlist; ct->name; ct++)	    printf("%-15s %s\n", ct->name, ct->help);	printf("\n");	settogglehelp(0);	printf("%-15s %s\n", "?", "display help information");	return 0;    }    argc--;    argv++;    while (argc--) {	name = *argv++;	ct = getset(name);	if (ct == 0) {	    c = GETTOGGLE(name);	    if (c == 0) {		fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\n",			name);		return 0;	    } 	    else if (c == AMBIGUOUS) {		fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",			name);		return 0;	    }	    if (c->variable) {		*c->variable = 0;		if (c->actionexplanation) {		    printf("%s %s.\n", *c->variable? "Will" : "Won't",							c->actionexplanation);		}	    }	    if (c->handler)		(*c->handler)(0);	} 	else if (ct == AMBIGUOUS) {	    fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",			name);	    return 0;	} 	else if (ct->handler) {	    (*ct->handler)(0);	    printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);	} 	else {	    *(ct->charp) = _POSIX_VDISABLE;	    printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));	}    }    return 1;}/* * The following are the data structures and routines for the * 'mode' command. */#ifdef	KLUDGELINEMODEextern int kludgelinemode;static int dokludgemode(int) {    kludgelinemode = 1;    send_wont(TELOPT_LINEMODE, 1);    send_dont(TELOPT_SGA, 1);    send_dont(TELOPT_ECHO, 1);    return 0;}#endifstatic int dolinemode(int) {#ifdef	KLUDGELINEMODE    if (kludgelinemode)	send_dont(TELOPT_SGA, 1);#endif    send_will(TELOPT_LINEMODE, 1);    send_dont(TELOPT_ECHO, 1);    return 1;}static int docharmode(int) {#ifdef	KLUDGELINEMODE    if (kludgelinemode)	send_do(TELOPT_SGA, 1);    else#endif    send_wont(TELOPT_LINEMODE, 1);    send_do(TELOPT_ECHO, 1);    return 1;}static int dolmmode(int bit, int on) {    unsigned char c;    extern int linemode;    if (my_want_state_is_wont(TELOPT_LINEMODE)) {	printf("?Need to have LINEMODE option enabled first.\n");	printf("'mode ?' for help.\n");	return 0;    }    if (on)	c = (linemode | bit);    else	c = (linemode & ~bit);    lm_mode(&c, 1, 1);    return 1;}int setmode(int bit) {    return dolmmode(bit, 1);}int clearmode(int bit) {    return dolmmode(bit, 0);}struct modelist {	const char	*name;		/* command name */	const char	*help;		/* help string */

⌨️ 快捷键说明

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