-int connected;
-int net;
-int showoptions = 0;
-int options;
-int debug = 0;
-int crmod = 0;
-char *prompt;
-char escape = CTRL(]);
-
-char line[200];
-int margc;
-char *margv[20];
-
-jmp_buf toplevel;
-jmp_buf peerdied;
-
-extern int errno;
-
-int tn(), quit(), suspend(), bye(), help();
-int setescape(), status(), toggle(), setoptions();
-int setcrmod(), setdebug();
-
-#define HELPINDENT (sizeof ("connect"))
-
-struct cmd {
- char *name; /* command name */
- char *help; /* help string */
- int (*handler)(); /* routine which executes command */
-};
-
-char openhelp[] = "connect to a site";
-char closehelp[] = "close current connection";
-char quithelp[] = "exit telnet";
-char zhelp[] = "suspend telnet";
-char debughelp[] = "toggle debugging";
-char escapehelp[] = "set escape character";
-char statushelp[] = "print status information";
-char helphelp[] = "print help information";
-char optionshelp[] = "toggle viewing of options processing";
-char crmodhelp[] = "toggle mapping of received carriage returns";
-
-struct cmd cmdtab[] = {
- { "open", openhelp, tn },
- { "close", closehelp, bye },
- { "quit", quithelp, quit },
- { "z", zhelp, suspend },
- { "escape", escapehelp, setescape },
- { "status", statushelp, status },
- { "options", optionshelp, setoptions },
- { "crmod", crmodhelp, setcrmod },
- { "debug", debughelp, setdebug },
- { "?", helphelp, help },
- 0
-};
-
-struct sockaddr_in sin;
-
-int intr(), deadpeer();
-char *control();
-struct cmd *getcmd();
-struct servent *sp;
-
-struct tchars otc;
-struct ltchars oltc;
-struct sgttyb ottyb;
-
-main(argc, argv)
- int argc;
- char *argv[];
-{
- sp = getservbyname("telnet", "tcp");
- if (sp == 0) {
- fprintf(stderr, "telnet: tcp/telnet: unknown service\n");
- exit(1);
- }
- ioctl(0, TIOCGETP, (char *)&ottyb);
- ioctl(0, TIOCGETC, (char *)&otc);
- ioctl(0, TIOCGLTC, (char *)&oltc);
- setbuf(stdin, 0);
- setbuf(stdout, 0);
- prompt = argv[0];
- if (argc > 1 && !strcmp(argv[1], "-d"))
- options = SO_DEBUG, argv++, argc--;
- if (argc != 1) {
- if (setjmp(toplevel) != 0)
- exit(0);
- tn(argc, argv);
- }
- setjmp(toplevel);
- for (;;)
- command(1);
-}
-
-char *hostname;
-char hnamebuf[32];
-
-tn(argc, argv)
- int argc;
- char *argv[];
-{
- register int c;
- register struct hostent *host;
-
- if (connected) {
- printf("?Already connected to %s\n", hostname);
- return;
- }
- if (argc < 2) {
- strcpy(line, "Connect ");
- printf("(to) ");
- gets(&line[strlen(line)]);
- makeargv();
- argc = margc;
- argv = margv;
- }
- if (argc > 3) {
- printf("usage: %s host-name [port]\n", argv[0]);
- return;
- }
- host = gethostbyname(argv[1]);
- if (host) {
- sin.sin_family = host->h_addrtype;
- bcopy(host->h_addr, (caddr_t)&sin.sin_addr, host->h_length);
- hostname = host->h_name;
- } else {
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = inet_addr(argv[1]);
- if (sin.sin_addr.s_addr == -1) {
- printf("%s: unknown host\n", argv[1]);
- return;
- }
- strcpy(hnamebuf, argv[1]);
- hostname = hnamebuf;
- }
- sin.sin_port = sp->s_port;
- if (argc == 3) {
- sin.sin_port = atoi(argv[2]);
- if (sin.sin_port < 0) {
- printf("%s: bad port number\n", argv[2]);
- return;
- }
- sin.sin_port = htons(sin.sin_port);
- }
- net = socket(AF_INET, SOCK_STREAM, 0, 0);
- if (net < 0) {
- perror("telnet: socket");
- return;
- }
- if (debug && setsockopt(net, SOL_SOCKET, SO_DEBUG, 0, 0) < 0)
- perror("setsockopt (SO_DEBUG)");
- signal(SIGINT, intr);
- signal(SIGPIPE, deadpeer);
- printf("Trying...\n");
- if (connect(net, (caddr_t)&sin, sizeof (sin), 0) < 0) {
- perror("telnet: connect");
- signal(SIGINT, SIG_DFL);
- return;
- }
- connected++;
- call(status, "status", 0);
- if (setjmp(peerdied) == 0)
- telnet(net);
- fprintf(stderr, "Connection closed by foreign host.\n");
- exit(1);
-}
+int
+ connected,
+ showoptions,
+ In3270, /* Are we in 3270 mode? */
+ ISend, /* trying to send network data in */
+ debug = 0,
+ crmod,
+ netdata, /* Print out network data flow */
+ crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
+#if defined(TN3270)
+ noasynchtty = 0,/* User specified "-noasynch" on command line */
+ noasynchnet = 0,/* User specified "-noasynch" on command line */
+ askedSGA = 0, /* We have talked about suppress go ahead */
+#endif /* defined(TN3270) */
+ telnetport,
+ SYNCHing, /* we are in TELNET SYNCH mode */
+ flushout, /* flush output */
+ autoflush = 0, /* flush output when interrupting? */
+ autosynch, /* send interrupt characters with SYNCH? */
+ localchars, /* we recognize interrupt/quit */
+ donelclchars, /* the user has set "localchars" */
+ donebinarytoggle, /* the user has put us in binary */
+ dontlecho, /* do we suppress local echoing right now? */
+ globalmode;
+
+#define CONTROL(x) ((x)&0x1f) /* CTRL(x) is not portable */
+
+char
+ *prompt = 0,
+ escape,
+ echoc;