Annotation of src/usr.bin/telnet/main.c, Revision 1.25
1.25 ! guenther 1: /* $OpenBSD: main.c,v 1.24 2014/07/20 05:22:02 guenther Exp $ */
1.2 niklas 2: /* $NetBSD: main.c,v 1.5 1996/02/28 21:04:05 thorpej Exp $ */
3:
1.1 deraadt 4: /*
1.2 niklas 5: * Copyright (c) 1988, 1990, 1993
6: * The Regents of the University of California. All rights reserved.
1.1 deraadt 7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
1.14 millert 16: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: */
32:
1.5 art 33: #include "telnet_locl.h"
1.1 deraadt 34:
1.25 ! guenther 35: #include <unistd.h>
1.1 deraadt 36:
1.15 otto 37: int family = AF_UNSPEC;
1.22 sthen 38: int rtableid = -1;
1.15 otto 39:
1.1 deraadt 40: /*
41: * Initialize variables.
42: */
43: void
44: tninit()
45: {
46: init_terminal();
47:
48: init_network();
1.2 niklas 49:
1.1 deraadt 50: init_telnet();
51:
52: init_sys();
53: }
54:
55: void
56: usage()
57: {
1.16 jmc 58: extern char *__progname;
59:
60: (void)fprintf(stderr,
1.23 guenther 61: "usage: %s [-4678acDdEKLr] [-b hostalias] [-e escapechar] "
62: "[-l user]\n"
63: "\t[-n tracefile] [-V rtable] [host [port]]\n",
1.16 jmc 64: __progname);
65:
1.1 deraadt 66: exit(1);
67: }
68:
69: /*
70: * main. Parse arguments, invoke the protocol or command parser.
71: */
72:
1.7 art 73: int
1.1 deraadt 74: main(argc, argv)
75: int argc;
76: char *argv[];
77: {
78: int ch;
1.5 art 79: char *user, *alias;
1.17 claudio 80: const char *errstr;
1.11 hin 81:
1.1 deraadt 82: tninit(); /* Clear out things */
83:
84: TerminalSaveState();
85:
1.5 art 86: if ((prompt = strrchr(argv[0], '/')))
1.1 deraadt 87: ++prompt;
88: else
89: prompt = argv[0];
90:
1.3 niklas 91: user = alias = NULL;
1.1 deraadt 92:
93: rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
1.5 art 94:
1.1 deraadt 95: autologin = -1;
96:
1.23 guenther 97: while ((ch = getopt(argc, argv, "4678ab:cDdEe:KLl:n:rV:"))
1.15 otto 98: != -1) {
1.1 deraadt 99: switch(ch) {
1.15 otto 100: case '4':
101: family = AF_INET;
102: break;
103: case '6':
104: family = AF_INET6;
105: break;
1.23 guenther 106: case '7':
107: eight = 0;
108: break;
1.1 deraadt 109: case '8':
110: eight = 3; /* binary output and input */
111: break;
1.23 guenther 112: case 'a':
113: autologin = 1;
114: break;
115: case 'b':
116: alias = optarg;
117: break;
118: case 'c':
119: skiprc = 1;
1.5 art 120: break;
121: case 'D': {
122: /* sometimes we don't want a mangled display */
123: char *p;
124: if((p = getenv("DISPLAY")))
125: env_define("DISPLAY", (unsigned char*)p);
126: break;
127: }
1.23 guenther 128: case 'd':
129: debug = 1;
130: break;
1.1 deraadt 131: case 'E':
132: rlogin = escape = _POSIX_VDISABLE;
133: break;
1.23 guenther 134: case 'e':
135: set_escape_char(optarg);
136: break;
1.1 deraadt 137: case 'K':
138: autologin = 0;
139: break;
140: case 'L':
141: eight |= 2; /* binary output only */
142: break;
143: case 'l':
1.6 art 144: autologin = -1;
1.1 deraadt 145: user = optarg;
146: break;
147: case 'n':
1.23 guenther 148: SetNetTrace(optarg);
1.1 deraadt 149: break;
150: case 'r':
151: rlogin = '~';
152: break;
1.17 claudio 153: case 'V':
1.22 sthen 154: rtableid = (int)strtonum(optarg, 0,
1.17 claudio 155: RT_TABLEID_MAX, &errstr);
156: if (errstr) {
1.20 guenther 157: fprintf(stderr, "%s: Warning: "
158: "-V ignored, rtable %s: %s\n",
1.17 claudio 159: prompt, errstr, optarg);
160: }
1.1 deraadt 161: break;
162: case '?':
163: default:
164: usage();
165: /* NOTREACHED */
166: }
167: }
1.5 art 168:
1.1 deraadt 169: if (autologin == -1)
170: autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
171:
172: argc -= optind;
173: argv += optind;
174:
175: if (argc) {
176: char *args[7], **argp = args;
177:
178: if (argc > 2)
179: usage();
180: *argp++ = prompt;
181: if (user) {
182: *argp++ = "-l";
183: *argp++ = user;
1.3 niklas 184: }
185: if (alias) {
186: *argp++ = "-b";
187: *argp++ = alias;
1.1 deraadt 188: }
189: *argp++ = argv[0]; /* host */
190: if (argc > 1)
191: *argp++ = argv[1]; /* port */
192: *argp = 0;
193:
194: if (setjmp(toplevel) != 0)
195: Exit(0);
196: if (tn(argp - args, args) == 1)
197: return (0);
198: else
199: return (1);
200: }
201: (void)setjmp(toplevel);
202: for (;;) {
1.23 guenther 203: command(1, 0, 0);
1.1 deraadt 204: }
1.7 art 205: return 0;
1.1 deraadt 206: }