xref: /dragonfly/usr.bin/telnet/externs.h (revision 409b4c59)
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. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)externs.h	8.3 (Berkeley) 5/30/95
34  *	$FreeBSD: src/usr.bin/telnet/externs.h,v 1.5.2.2 2002/04/13 11:07:13 markm Exp $
35  *	$DragonFly: src/usr.bin/telnet/externs.h,v 1.3 2008/10/16 01:52:33 swildner Exp $
36  */
37 
38 #ifndef	BSD
39 # define BSD 43
40 #endif
41 
42 /*
43  * ucb stdio.h defines BSD as something weird
44  */
45 #if defined(sun) && defined(__svr4__)
46 #define BSD 43
47 #endif
48 
49 #ifndef	USE_TERMIO
50 # if BSD > 43 || defined(SYSV_TERMIO)
51 #  define USE_TERMIO
52 # endif
53 #endif
54 
55 #include <stdio.h>
56 #include <setjmp.h>
57 #include <sys/ioctl.h>
58 #include <errno.h>
59 #ifdef	USE_TERMIO
60 # ifndef	VINTR
61 #  include <sys/termios.h>
62 # endif
63 # define termio termios
64 #endif
65 #if defined(NO_CC_T) || !defined(USE_TERMIO)
66 # if !defined(USE_TERMIO)
67 typedef char cc_t;
68 # else
69 typedef unsigned char cc_t;
70 # endif
71 #endif
72 
73 #include <string.h>
74 
75 #if defined(IPSEC)
76 #include <netinet6/ipsec.h>
77 #if defined(IPSEC_POLICY_IPSEC)
78 extern char *ipsec_policy_in;
79 extern char *ipsec_policy_out;
80 #endif
81 #endif
82 
83 #ifndef	_POSIX_VDISABLE
84 # ifdef sun
85 #  include <sys/param.h>	/* pick up VDISABLE definition, mayby */
86 # endif
87 # ifdef VDISABLE
88 #  define _POSIX_VDISABLE VDISABLE
89 # else
90 #  define _POSIX_VDISABLE ((cc_t)'\377')
91 # endif
92 #endif
93 
94 #define	SUBBUFSIZE	256
95 
96 extern int
97     autologin,		/* Autologin enabled */
98     skiprc,		/* Don't process the ~/.telnetrc file */
99     eight,		/* use eight bit mode (binary in and/or out */
100     family,		/* address family of peer */
101     flushout,		/* flush output */
102     connected,		/* Are we connected to the other side? */
103     globalmode,		/* Mode tty should be in */
104     telnetport,		/* Are we connected to the telnet port? */
105     localflow,		/* Flow control handled locally */
106     restartany,		/* If flow control, restart output on any character */
107     localchars,		/* we recognize interrupt/quit */
108     donelclchars,	/* the user has set "localchars" */
109     showoptions,
110     net,		/* Network file descriptor */
111     tin,		/* Terminal input file descriptor */
112     tout,		/* Terminal output file descriptor */
113     crlf,		/* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
114     autoflush,		/* flush output when interrupting? */
115     autosynch,		/* send interrupt characters with SYNCH? */
116     SYNCHing,		/* Is the stream in telnet SYNCH mode? */
117     donebinarytoggle,	/* the user has put us in binary */
118     dontlecho,		/* do we suppress local echoing right now? */
119     crmod,
120     netdata,		/* Print out network data flow */
121     prettydump,		/* Print "netdata" output in user readable format */
122     termdata,		/* Print out terminal data flow */
123     debug,		/* Debug level */
124     doaddrlookup,	/* do a reverse lookup? */
125     clienteof;		/* Client received EOF */
126 
127 extern cc_t escape;	/* Escape to command mode */
128 extern cc_t rlogin;	/* Rlogin mode escape character */
129 #ifdef	KLUDGELINEMODE
130 extern cc_t echoc;	/* Toggle local echoing */
131 #endif
132 
133 extern char
134     *prompt;		/* Prompt for command. */
135 
136 extern char
137     doopt[],
138     dont[],
139     will[],
140     wont[],
141     options[],		/* All the little options */
142     *hostname;		/* Who are we connected to? */
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