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

📄 commands.c

📁 经典的unix下telnet的c代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	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.\r\n");	} else {	    printf("Negotiating binary mode on input.\r\n");	    tel_enter_binary(1);	}    } else {	if (my_want_state_is_dont(TELOPT_BINARY)) {	    printf("Already receiving in network ascii mode.\r\n");	} else {	    printf("Negotiating network ascii mode on input.\r\n");	    tel_leave_binary(1);	}    }    return 1;}    static inttogxbinary(val)    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.\r\n");	} else {	    printf("Negotiating binary mode on output.\r\n");	    tel_enter_binary(2);	}    } else {	if (my_want_state_is_wont(TELOPT_BINARY)) {	    printf("Already transmitting in network ascii mode.\r\n");	} else {	    printf("Negotiating network ascii mode on output.\r\n");	    tel_leave_binary(2);	}    }    return 1;}static int togglehelp(void);#if	defined(AUTHENTICATION)extern int auth_togdebug(int);#endif#if    defined(ENCRYPTION)extern int EncryptAutoEnc(int);extern int EncryptAutoDec(int);extern int EncryptDebug(int);extern int EncryptVerbose(int);#endifstruct togglelist {    char	*name;		/* name of toggle */    char	*help;		/* help message */    int		(*handler)();	/* routine to do actual setting */    int		*variable;    char	*actionexplanation;    int		needconnect;	/* Need to be connected */};static struct togglelist Togglelist[] = {    { "autoflush",	"flushing of output when sending interrupt characters",	    0,		&autoflush,		    "flush output when sending interrupt characters" },    { "autosynch",	"automatic sending of interrupt characters in urgent mode",	    0,		&autosynch,		    "send interrupt characters in urgent mode" },#if	defined(AUTHENTICATION)    { "autologin",	"automatic sending of login and/or authentication info",	    0,		&autologin,		    "send login name and/or authentication information" },    { "authdebug",	"Toggle authentication debugging",	    auth_togdebug,		0,		     "print authentication debugging information" },#endif#if    defined(ENCRYPTION)    { "autoencrypt",       "automatic encryption of data stream",           EncryptAutoEnc,               0,                   "automatically encrypt output" },    { "autodecrypt",       "automatic decryption of data stream",           EncryptAutoDec,               0,                   "automatically decrypt input" },    { "verbose_encrypt",       "Toggle verbose encryption output",           EncryptVerbose,               0,                   "print verbose encryption output" },    { "encdebug",       "Toggle encryption debugging",           EncryptDebug,               0,                   "print encryption debugging information" },#endif    { "skiprc",	"don't read ~/.telnetrc file",	    0,		&skiprc,		    "skip reading of ~/.telnetrc file" },    { "binary",	"sending and receiving of binary data",	    togbinary,		0,		    0 },    { "inbinary",	"receiving of binary data",	    togrbinary,		0,		    0 },    { "outbinary",	"sending of binary data",	    togxbinary,		0,		    0 },    { "crlf",	"sending carriage returns as telnet <CR><LF>",	    togcrlf,		&crlf,		    0 },    { "crmod",	"mapping of received carriage returns",	    0,		&crmod,		    "map carriage return on output" },    { "localchars",	"local recognition of certain control characters",	    lclchars,		&localchars,		    "recognize certain control characters" },    { " ", "", 0, 0 },		/* empty line */#if	defined(unix) && defined(TN3270)    { "apitrace",	"(debugging) toggle tracing of API transactions",	    0,		&apitrace,		    "trace API transactions", 0 },    { "cursesdata",	"(debugging) toggle printing of hexadecimal curses data",	    0,		&cursesdata,		    "print hexadecimal representation of curses data", 0 },#endif	/* defined(unix) && defined(TN3270) */    { "debug",	"debugging",	    togdebug,		&debug,		    "turn on socket level debugging" },    { "netdata",	"printing of hexadecimal network data (debugging)",	    0,		&netdata,		    "print hexadecimal representation of network traffic" },    { "prettydump",	"output of \"netdata\" to user readable format (debugging)",	    0,		&prettydump,		    "print user readable output for \"netdata\"" },    { "options",	"viewing of options processing (debugging)",	    0,		&showoptions,		    "show option processing" },#if	defined(unix)    { "termdata",	"(debugging) toggle printing of hexadecimal terminal data",	    0,		&termdata,		    "print hexadecimal representation of terminal traffic" },#endif	/* defined(unix) */    { "?",	0,	    togglehelp },    { "help",	0,	    togglehelp },    { 0 }};    static inttogglehelp(){    struct togglelist *c;    for (c = Togglelist; c->name; c++) {	if (c->help) {	    if (*c->help)		printf("%-15s toggle %s\r\n", c->name, c->help);	    else		printf("\r\n");	}    }    printf("\r\n");    printf("%-15s %s\r\n", "?", "display help information");    return 0;}    static voidsettogglehelp(set)    int set;{    struct togglelist *c;    for (c = Togglelist; c->name; c++) {	if (c->help) {	    if (*c->help)		printf("%-15s %s %s\r\n", c->name, set ? "enable" : "disable",						c->help);	    else		printf("\r\n");	}    }}#define	GETTOGGLE(name) (struct togglelist *) \		genget(name, (char **) Togglelist, sizeof(struct togglelist))    static inttoggle(argc, argv)    int  argc;    char *argv[];{    int retval = 1;    char *name;    struct togglelist *c;    if (argc < 2) {	fprintf(stderr,	    "Need an argument to 'toggle' command.  'toggle ?' for help.\r\n");	return 0;    }    argc--;    argv++;    while (argc--) {	name = *argv++;	c = GETTOGGLE(name);	if (Ambiguous(c)) {	    fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\r\n",					name);	    return 0;	} else if (c == 0) {	    fprintf(stderr, "'%s': unknown argument ('toggle ?' for help).\r\n",					name);	    return 0;	} else if (!connected && c->needconnect) {	    printf("?Need to be connected first.\r\n");	    printf("'send ?' for help\r\n");	    return 0;	} else {	    if (c->variable) {		*c->variable = !*c->variable;		/* invert it */		if (c->actionexplanation) {		    printf("%s %s.\r\n", *c->variable? "Will" : "Won't",							c->actionexplanation);		}	    }	    if (c->handler) {		retval &= (*c->handler)(-1);	    }	}    }    return retval;}/* * The following perform the "set" command. */#ifdef	USE_TERMIOstruct termios new_tc = { 0 };#endifstruct setlist {    char *name;				/* name */    char *help;				/* help information */    void (*handler)();    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, &escape },    { "rlogin", "rlogin escape character", 0, &rlogin },    { "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile},    { " ", "" },    { " ", "The following need 'localchars' to be toggled true", 0, 0 },    { "flushoutput", "character to cause an Abort Output", 0, &termFlushChar },    { "interrupt", "character to cause an Interrupt Process", 0, &termIntChar },    { "quit",	"character to cause an Abort process", 0, &termQuitChar },    { "eof",	"character to cause an EOF ", 0, &termEofChar },    { " ", "" },    { " ", "The following are for local editing in linemode", 0, 0 },    { "erase",	"character to use to erase a character", 0, &termEraseChar },    { "kill",	"character to use to erase a line", 0, &termKillChar },    { "lnext",	"character to use for literal next", 0, &termLiteralNextChar },    { "susp",	"character to cause a Suspend Process", 0, &termSuspChar },    { "reprint", "character to use for line reprint", 0, &termRprntChar },    { "worderase", "character to use to erase a word", 0, &termWerasChar },    { "start",	"character to use for XON", 0, &termStartChar },    { "stop",	"character to use for XOFF", 0, &termStopChar },    { "forw1",	"alternate end of line character", 0, &termForw1Char },    { "forw2",	"alternate end of line character", 0, &termForw2Char },    { "ayt",	"alternate AYT character", 0, &termAytChar },    { 0 }};    static struct setlist *getset(name)    char *name;{    return (struct setlist *)		genget(name, (char **) Setlist, sizeof(struct setlist));}    voidset_escape_char(s)    char *s;{	if (rlogin != _POSIX_VDISABLE) {		rlogin = (s && *s) ? special(s) : _POSIX_VDISABLE;		printf("Telnet rlogin escape character is '%s'.\r\n",					control(rlogin));	} else {		escape = (s && *s) ? special(s) : _POSIX_VDISABLE;		printf("Telnet escape character is '%s'.\r\n", control(escape));	}}    static intsetcmd(argc, argv)    int  argc;    char *argv[];{    int value;    struct setlist *ct;    struct togglelist *c;    if (argc < 2 || argc > 3) {	printf("Format is 'set Name Value'\r\n'set ?' for help.\r\n");	return 0;    }    if ((argc == 2) && (isprefix(argv[1], "?") || isprefix(argv[1], "help"))) {	for (ct = Setlist; ct->name; ct++)	    printf("%-15s %s\r\n", ct->name, ct->help);	printf("\r\n");	settogglehelp(1);	printf("%-15s %s\r\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).\r\n",			argv[1]);	    return 0;	} else if (Ambiguous(c)) {	    fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\r\n",			argv[1]);	    return 0;	} else if (!connected && c->needconnect) {	    printf("?Need to be connected first.\r\n");	    printf("'send ?' for help\r\n");	    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]'\r\n'set ?' for help.\r\n");		return 0;	    }	    if (c->actionexplanation) {		printf("%s %s.\r\n", *c->variable? "Will" : "Won't",							c->actionexplanation);	    }	}	if (c->handler)	    (*c->handler)(1);    } else if (argc != 3) {	printf("Format is 'set Name Value'\r\n'set ?' for help.\r\n");	return 0;    } else if (Ambiguous(ct)) {	fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\r\n",			argv[1]);	return 0;    } else if (ct->handler) {	(*ct->handler)(argv[2]);	printf("%s set to \"%s\".\r\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'.\r\n", ct->name, control(*(ct->charp)));    }    slc_check();    return 1;}    static intunsetcmd(argc, argv)    int  argc;    char *argv[];{    struct setlist *ct;    struct togglelist *c;    char *name;    if (argc < 2) {	fprintf(stderr,	    "Need an argument to 'unset' command.  'unset ?' for help.\r\n");	return 0;    }    if (isprefix(argv[1], "?") || isprefix(argv[1], "help")) {	for (ct = Setlist; ct->name; ct++)	    printf("%-15s %s\r\n", ct->name, ct->help);	printf("\r\n");	settogglehelp(0);	printf("%-15s %s\r\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).\r\n",			name);		return 0;	    } else if (Ambiguous(c)) {		fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\r\n",			name);		return 0;	    }	    if (c->variable) {		*c->variable = 0;		if (c->actionexplanation) {		    printf("%s %s.\r\n", *c->variable? "Will" : "Won't",							c->actionexplanation);		}	    }	    if (c->handler)		(*c->handler)(0);	} else if (Ambiguous(ct)) {	    fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\r\n",			name);	    return 0;	} else if (ct->handler) {	    (*ct->handler)(0);	    printf("%s reset to \"%s\".\r\n", ct->name, (char *)ct->charp);	} else {	    *(ct->charp) = _POSIX_VDISABLE;	    printf("%s character is '%s'.\r\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 intdokludgemode(){    kludgelinemode = 1;    send_wont(TELOPT_LINEMODE, 1);    send_dont(TELOPT_SGA, 1);    send_dont(TELOPT_ECHO, 1);    return 1;}#endif    static intdolinemode(){#ifdef	KLUDGELINEMODE    if (kludgelinemode)	send_dont(TELOPT_SGA, 1);#endif    send_will(TELOPT_LINEMODE, 1);    send_dont(TELOPT_ECHO, 1);    return 1;}    static intdocharmode(){#ifdef	KLUDGELINEMODE    if (kludgelinemode)	send_do(TELOPT_SGA, 1);    else#endif    send_wont(TELOPT_LINEMODE, 1);    send_do(TELOPT_ECHO, 1);    return 1;}    static intdolmmode(bit, on)    int bit, on;{    unsigned char c;    extern int linemode;    if (my_want_state_is_wont(TELOPT_LINEMODE)) {	printf("?Need to have LINEMODE option enabled first.\r\n");	printf("'mode ?' for help.\r\n");	return 0;    }    if (on)	c = (linemode | bit);    else	c = (linemode & ~bit);    lm_mode(&c, 1, 1);    return 1;

⌨️ 快捷键说明

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