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