Debian Codegraph @

telnet/externs.h

raw
1 /*
2 Copyright (C) 1995-2026 Free Software Foundation, Inc.
3
4 This file is part of GNU Inetutils.
5
6 GNU Inetutils is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or (at
9 your option) any later version.
10
11 GNU Inetutils is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see `http://www.gnu.org/licenses/'. */
18
19 /*
20 * Copyright (c) 1988, 1990, 1993
21 * The Regents of the University of California. All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. Neither the name of the University nor the names of its contributors
32 * may be used to endorse or promote products derived from this software
33 * without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 */
47
48 #include <unistd.h>
49
50 #ifndef BSD
51 # define BSD 43
52 #endif
53
54
55 #define USE_TERMIO
56
57 /*
58 * ucb stdio.h defines BSD as something weird
59 */
60 #if defined sun && defined __svr4__
61 # define BSD 43
62 #endif
63
64 #ifndef USE_TERMIO
65 # if BSD > 43 || defined SYSV_TERMIO
66 # define USE_TERMIO
67 # endif
68 #endif
69
70 #include <stdio.h>
71 #include <setjmp.h>
72 #if defined CRAY && !defined NO_BSD_SETJMP
73 # include <bsdsetjmp.h>
74 #endif
75 #include <sys/ioctl.h>
76 #ifdef HAVE_SYS_FILIO_H
77 # include <sys/filio.h>
78 #endif
79 #include <errno.h>
80 #ifdef USE_TERMIO
81 # ifndef VINTR
82 # ifdef SYSV_TERMIO
83 # include <termio.h>
84 # else
85 # include <termios.h>
86 # endif
87 # endif
88 #endif
89 #if defined NO_CC_T || !defined USE_TERMIO
90 # if !defined USE_TERMIO
91 typedef char cc_t;
92 # else
93 typedef unsigned char cc_t;
94 # endif
95 #endif
96
97 #if defined USE_TERMIO && !defined SYSV_TERMIO
98 # define termio termios
99 #endif
100
101 #ifndef NO_STRING_H
102 # include <string.h>
103 #else
104 # include <strings.h>
105 #endif
106
107 #ifndef _POSIX_VDISABLE
108 # ifdef sun
109 # include <sys/param.h> /* pick up VDISABLE definition, maybe */
110 # endif
111 # ifdef VDISABLE
112 # define _POSIX_VDISABLE VDISABLE
113 # else
114 # define _POSIX_VDISABLE ((cc_t)'\377')
115 # endif
116 #endif
117
118 #define SUBBUFSIZE 256
119
120 extern int autologin, /* Autologin enabled */
121 skiprc, /* Don't process the ~/.telnetrc file */
122 eight, /* use eight bit mode (binary in and/or out */
123 flushout, /* flush output */
124 connected, /* Are we connected to the other side? */
125 globalmode, /* Mode tty should be in */
126 telnetport, /* Are we connected to the telnet port? */
127 localflow, /* Flow control handled locally */
128 restartany, /* If flow control, restart output on any character */
129 localchars, /* we recognize interrupt/quit */
130 donelclchars, /* the user has set "localchars" */
131 showoptions, net, /* Network file descriptor */
132 tin, /* Terminal input file descriptor */
133 tout, /* Terminal output file descriptor */
134 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
135 autoflush, /* flush output when interrupting? */
136 autosynch, /* send interrupt characters with SYNCH? */
137 SYNCHing, /* Is the stream in telnet SYNCH mode? */
138 donebinarytoggle, /* the user has put us in binary */
139 dontlecho, /* do we suppress local echoing right now? */
140 crmod, netdata, /* Print out network data flow */
141 prettydump, /* Print "netdata" output in user readable format */
142 termdata, /* Print out terminal data flow */
143 debug; /* Debug level */
144
145 extern cc_t escape; /* Escape to command mode */
146 extern cc_t rlogin; /* Rlogin mode escape character */
147 #ifdef KLUDGELINEMODE
148 extern cc_t echoc; /* Toggle local echoing */
149 #endif
150
151 extern char *prompt; /* Prompt for command. */
152
153 extern char doopt[], dont[], will[], wont[], options[], /* All the little options */
154 *hostname; /* Who are we connected to? */
155 #ifdef ENCRYPTION
156 extern void (*encrypt_output) (unsigned char *, int);
157 extern int (*decrypt_input) (int);
158 #endif /* ENCRYPTION */
159
160 /*
161 * We keep track of each side of the option negotiation.
162 */
163
164 #define MY_STATE_WILL 0x01
165 #define MY_WANT_STATE_WILL 0x02
166 #define MY_STATE_DO 0x04
167 #define MY_WANT_STATE_DO 0x08
168
169 /*
170 * Macros to check the current state of things
171 */
172
173 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
174 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
175 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
176 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
177
178 #define my_state_is_dont(opt) (!my_state_is_do(opt))
179 #define my_state_is_wont(opt) (!my_state_is_will(opt))
180 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
181 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
182
183 #define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;}
184 #define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;}
185 #define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;}
186 #define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;}
187
188 #define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;}
189 #define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;}
190 #define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;}
191 #define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;}
192
193 /*
194 * Make everything symmetrical
195 */
196
197 #define HIS_STATE_WILL MY_STATE_DO
198 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
199 #define HIS_STATE_DO MY_STATE_WILL
200 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
201
202 #define his_state_is_do my_state_is_will
203 #define his_state_is_will my_state_is_do
204 #define his_want_state_is_do my_want_state_is_will
205 #define his_want_state_is_will my_want_state_is_do
206
207 #define his_state_is_dont my_state_is_wont
208 #define his_state_is_wont my_state_is_dont
209 #define his_want_state_is_dont my_want_state_is_wont
210 #define his_want_state_is_wont my_want_state_is_dont
211
212 #define set_his_state_do set_my_state_will
213 #define set_his_state_will set_my_state_do
214 #define set_his_want_state_do set_my_want_state_will
215 #define set_his_want_state_will set_my_want_state_do
216
217 #define set_his_state_dont set_my_state_wont
218 #define set_his_state_wont set_my_state_dont
219 #define set_his_want_state_dont set_my_want_state_wont
220 #define set_his_want_state_wont set_my_want_state_dont
221
222
223 extern FILE *NetTrace; /* Where debugging output goes */
224 extern unsigned char NetTraceFile[]; /* Name of file where debugging output goes */
225
226 /* utilities.c */
227 void SetNetTrace (const char *); /* Function to change where debugging goes */
228
229 extern jmp_buf peerdied, toplevel; /* For error conditions. */
230
231 extern void
232 command (int, char *, int),
233 Dump (char, unsigned char *, int),
234 printoption (char *, int, int),
235 printsub (char, unsigned char *, int),
236 sendnaws (void),
237 setconnmode (int),
238 setcommandmode (void),
239 setneturg (void),
240 sys_telnet_init (void),
241 telnet (char *),
242 tel_enter_binary (int),
243 tel_leave_binary (int),
244 TerminalFlushOutput (void),
245 TerminalNewMode (int),
246 TerminalRestoreState (void),
247 TerminalSaveState (void),
248 tninit (void), upcase (char *), willoption (int), wontoption (int);
249
250 extern int TerminalWindowSize (long *rows, long *cols);
251 extern void TerminalSpeeds (long *ispeed, long *ospeed);
252 extern void TerminalDefaultChars (void);
253 extern int TerminalSpecialChars (int c);
254 extern int TerminalAutoFlush (void);
255 extern int TerminalWrite (char *buf, int n);
256
257 extern int telrcv (void);
258 extern int getconnmode (void);
259 extern void optionstatus (void);
260 extern int NetClose (int);
261 extern void Exit (int);
262 extern void ExitString (char *, int);
263 extern int netflush (void);
264 extern int opt_welldefined (char *);
265 extern int stilloob (void);
266 extern int process_rings (int, int, int, int, int, int);
267
268 extern void init_terminal (void);
269 extern void init_network (void);
270 extern void init_telnet (void);
271 extern void init_sys (void);
272
273 extern void set_escape_char (char *);
274 extern int tn (int argc, char **argv);
275
276 extern void
277 send_do (int, int),
278 send_dont (int, int), send_will (int, int), send_wont (int, int);
279
280 extern void sendabort (void);
281 extern void sendeof (void);
282 extern void sendsusp (void);
283 extern int ttyflush (int);
284 extern int rlogin_susp (void);
285 extern void env_init (void);
286
287 /* FIXME: Not needed */
288 int SetSockOpt (int fd, int level, int option, int yesno);
289
290 /* commands.c */
291 struct env_lst *env_define (const char *, char *);
292 struct env_lst *env_undefine (const char *, char *);
293 struct env_lst *env_export (const char *, char *);
294 struct env_lst *env_unexport (const char *, char *);
295 struct env_lst *env_send (const char *, char *);
296 struct env_lst *env_list (const char *, char *);
297 #if defined OLD_ENVIRON && defined ENV_HACK
298 struct env_lst *env_varval (const char *, char *),
299 #endif
300 int quit (int, char *[]);
301
302 extern void
303 lm_will (unsigned char *, int),
304 lm_wont (unsigned char *, int),
305 lm_do (unsigned char *, int),
306 lm_dont (unsigned char *, int), lm_mode (unsigned char *, int, int);
307
308 /* telnet.c */
309 void slc_init (void);
310 void slcstate (void);
311 void slc_mode_export (int);
312 void slc_mode_import (int);
313 void slc_import (int);
314 void slc_export (void);
315 void slc (unsigned char *, int);
316 void slc_check (void);
317 void slc_start_reply (void);
318 void slc_add_reply (unsigned int, unsigned int, cc_t);
319 void slc_end_reply (void);
320 int slc_update (void);
321
322 extern void
323 env_opt (unsigned char *, int),
324 env_opt_start (void),
325 env_opt_start_info (void), env_opt_add (unsigned char *), env_opt_end (int);
326
327 extern unsigned char *env_default (int, int);
328 extern unsigned char *env_getvalue (const char *, bool);
329
330 int dosynch (const char *);
331 int get_status (const char *);
332
333 extern cc_t *tcval (int);
334
335 #ifndef USE_TERMIO
336
337 extern struct tchars ntc;
338 extern struct ltchars nltc;
339 extern struct sgttyb nttyb;
340
341 # define termEofChar ntc.t_eofc
342 # define termEraseChar nttyb.sg_erase
343 # define termFlushChar nltc.t_flushc
344 # define termIntChar ntc.t_intrc
345 # define termKillChar nttyb.sg_kill
346 # define termLiteralNextChar nltc.t_lnextc
347 # define termQuitChar ntc.t_quitc
348 # define termSuspChar nltc.t_suspc
349 # define termRprntChar nltc.t_rprntc
350 # define termWerasChar nltc.t_werasc
351 # define termStartChar ntc.t_startc
352 # define termStopChar ntc.t_stopc
353 # define termForw1Char ntc.t_brkc
354 extern cc_t termForw2Char;
355 extern cc_t termAytChar;
356
357 # define termEofCharp (cc_t *)&ntc.t_eofc
358 # define termEraseCharp (cc_t *)&nttyb.sg_erase
359 # define termFlushCharp (cc_t *)&nltc.t_flushc
360 # define termIntCharp (cc_t *)&ntc.t_intrc
361 # define termKillCharp (cc_t *)&nttyb.sg_kill
362 # define termLiteralNextCharp (cc_t *)&nltc.t_lnextc
363 # define termQuitCharp (cc_t *)&ntc.t_quitc
364 # define termSuspCharp (cc_t *)&nltc.t_suspc
365 # define termRprntCharp (cc_t *)&nltc.t_rprntc
366 # define termWerasCharp (cc_t *)&nltc.t_werasc
367 # define termStartCharp (cc_t *)&ntc.t_startc
368 # define termStopCharp (cc_t *)&ntc.t_stopc
369 # define termForw1Charp (cc_t *)&ntc.t_brkc
370 # define termForw2Charp (cc_t *)&termForw2Char
371 # define termAytCharp (cc_t *)&termAytChar
372
373 #else
374
375 extern struct termio new_tc;
376
377 # define termEofChar new_tc.c_cc[VEOF]
378 # define termEraseChar new_tc.c_cc[VERASE]
379 # define termIntChar new_tc.c_cc[VINTR]
380 # define termKillChar new_tc.c_cc[VKILL]
381 # define termQuitChar new_tc.c_cc[VQUIT]
382
383 # ifndef VSUSP
384 extern cc_t termSuspChar;
385 # else
386 # define termSuspChar new_tc.c_cc[VSUSP]
387 # endif
388 # if defined VFLUSHO && !defined VDISCARD
389 # define VDISCARD VFLUSHO
390 # endif
391 # ifndef VDISCARD
392 extern cc_t termFlushChar;
393 # else
394 # define termFlushChar new_tc.c_cc[VDISCARD]
395 # endif
396 # ifndef VWERASE
397 extern cc_t termWerasChar;
398 # else
399 # define termWerasChar new_tc.c_cc[VWERASE]
400 # endif
401 # ifndef VREPRINT
402 extern cc_t termRprntChar;
403 # else
404 # define termRprntChar new_tc.c_cc[VREPRINT]
405 # endif
406 # ifndef VLNEXT
407 extern cc_t termLiteralNextChar;
408 # else
409 # define termLiteralNextChar new_tc.c_cc[VLNEXT]
410 # endif
411 # ifndef VSTART
412 extern cc_t termStartChar;
413 # else
414 # define termStartChar new_tc.c_cc[VSTART]
415 # endif
416 # ifndef VSTOP
417 extern cc_t termStopChar;
418 # else
419 # define termStopChar new_tc.c_cc[VSTOP]
420 # endif
421 # ifndef VEOL
422 extern cc_t termForw1Char;
423 # else
424 # define termForw1Char new_tc.c_cc[VEOL]
425 # endif
426 # ifndef VEOL2
427 extern cc_t termForw2Char;
428 # else
429 # define termForw2Char new_tc.c_cc[VEOL]
430 # endif
431 # ifndef VSTATUS
432 extern cc_t termAytChar;
433 # else
434 # define termAytChar new_tc.c_cc[VSTATUS]
435 # endif
436
437 # if !defined CRAY || defined __STDC__
438 # define termEofCharp &termEofChar
439 # define termEraseCharp &termEraseChar
440 # define termIntCharp &termIntChar
441 # define termKillCharp &termKillChar
442 # define termQuitCharp &termQuitChar
443 # define termSuspCharp &termSuspChar
444 # define termFlushCharp &termFlushChar
445 # define termWerasCharp &termWerasChar
446 # define termRprntCharp &termRprntChar
447 # define termLiteralNextCharp &termLiteralNextChar
448 # define termStartCharp &termStartChar
449 # define termStopCharp &termStopChar
450 # define termForw1Charp &termForw1Char
451 # define termForw2Charp &termForw2Char
452 # define termAytCharp &termAytChar
453 # else
454 /* Work around a compiler bug */
455 # define termEofCharp 0
456 # define termEraseCharp 0
457 # define termIntCharp 0
458 # define termKillCharp 0
459 # define termQuitCharp 0
460 # define termSuspCharp 0
461 # define termFlushCharp 0
462 # define termWerasCharp 0
463 # define termRprntCharp 0
464 # define termLiteralNextCharp 0
465 # define termStartCharp 0
466 # define termStopCharp 0
467 # define termForw1Charp 0
468 # define termForw2Charp 0
469 # define termAytCharp 0
470 # endif
471 #endif
472
473
474 /* Ring buffer structures which are shared */
475
476 extern Ring netoring, netiring, ttyoring, ttyiring;