xref: /netbsd-src/usr.bin/telnet/externs.h (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1 /*	$NetBSD: externs.h,v 1.18 2000/02/01 02:28:23 assar Exp $	*/
2 
3 /*
4  * Copyright (c) 1988, 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	from: @(#)externs.h	8.3 (Berkeley) 5/30/95
36  */
37 
38 #ifndef	BSD
39 # define BSD 43
40 #endif
41 
42 /*
43  * ucb stdio.h defines BSD as something wierd
44  */
45 #if defined(sun) && defined(__svr4__) && !defined(BSD)
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 <stdlib.h>
57 #include <setjmp.h>
58 #if defined(CRAY) && !defined(NO_BSD_SETJMP)
59 #include <bsdsetjmp.h>
60 #endif
61 #ifndef	FILIO_H
62 #include <sys/ioctl.h>
63 #else
64 #include <sys/filio.h>
65 #endif
66 #include <errno.h>
67 #ifdef	USE_TERMIO
68 # ifndef	VINTR
69 #  ifdef SYSV_TERMIO
70 #   include <sys/termio.h>
71 #  else
72 #   include <sys/termios.h>
73 #   define termio termios
74 #  endif
75 # else
76 #  if defined(TCSANOW)
77 #   define termio termios
78 #  endif
79 # endif
80 #endif
81 #if defined(NO_CC_T) || !defined(USE_TERMIO)
82 # if !defined(USE_TERMIO)
83 typedef char cc_t;
84 # else
85 typedef unsigned char cc_t;
86 # endif
87 #endif
88 
89 #ifndef	NO_STRING_H
90 #include <string.h>
91 #else
92 #include <strings.h>
93 #endif
94 
95 #if defined(IPSEC)
96 #include <netinet6/ipsec.h>
97 #if defined(IPSEC_POLICY_IPSEC)
98 extern char *ipsec_policy_in;
99 extern char *ipsec_policy_out;
100 #endif
101 #endif
102 
103 #ifndef	_POSIX_VDISABLE
104 # ifdef sun
105 #  include <sys/param.h>	/* pick up VDISABLE definition, mayby */
106 # endif
107 # ifdef VDISABLE
108 #  define _POSIX_VDISABLE VDISABLE
109 # else
110 #  define _POSIX_VDISABLE ((cc_t)'\377')
111 # endif
112 #endif
113 
114 #define	SUBBUFSIZE	256
115 
116 #include <sys/cdefs.h>
117 #define P __P
118 
119 extern int
120     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     In3270,		/* Are we in 3270 mode? */
127     telnetport,		/* Are we connected to the telnet port? */
128     localflow,		/* Flow control handled locally */
129     restartany,		/* If flow control, restart output on any character */
130     localchars,		/* we recognize interrupt/quit */
131     donelclchars,	/* the user has set "localchars" */
132     showoptions,
133     net,		/* Network file descriptor */
134     tin,		/* Terminal input file descriptor */
135     tout,		/* Terminal output file descriptor */
136     crlf,		/* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
137     autoflush,		/* flush output when interrupting? */
138     autosynch,		/* send interrupt characters with SYNCH? */
139     SYNCHing,		/* Is the stream in telnet SYNCH mode? */
140     donebinarytoggle,	/* the user has put us in binary */
141     dontlecho,		/* do we suppress local echoing right now? */
142     crmod,
143     netdata,		/* Print out network data flow */
144     prettydump,		/* Print "netdata" output in user readable format */
145 #if	defined(unix)
146 #if	defined(TN3270)
147     cursesdata,		/* Print out curses data flow */
148     apitrace,		/* Trace API transactions */
149 #endif	/* defined(TN3270) */
150     termdata,		/* Print out terminal data flow */
151 #endif	/* defined(unix) */
152     debug,		/* Debug level */
153     doaddrlookup,	/* do a reverse address lookup? */
154     clienteof;		/* Client received EOF */
155 
156 extern cc_t escape;	/* Escape to command mode */
157 extern cc_t rlogin;	/* Rlogin mode escape character */
158 #ifdef	KLUDGELINEMODE
159 extern cc_t echoc;	/* Toggle local echoing */
160 #endif
161 
162 extern char
163     *prompt;		/* Prompt for command. */
164 
165 extern char
166     doopt[],
167     dont[],
168     will[],
169     wont[],
170     options[],		/* All the little options */
171     *hostname;		/* Who are we connected to? */
172 
173 /*
174  * We keep track of each side of the option negotiation.
175  */
176 
177 #define	MY_STATE_WILL		0x01
178 #define	MY_WANT_STATE_WILL	0x02
179 #define	MY_STATE_DO		0x04
180 #define	MY_WANT_STATE_DO	0x08
181 
182 /*
183  * Macros to check the current state of things
184  */
185 
186 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
187 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
188 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
189 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
190 
191 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
192 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
193 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
194 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
195 
196 #define	set_my_state_do(opt)		{options[opt] |= MY_STATE_DO;}
197 #define	set_my_state_will(opt)		{options[opt] |= MY_STATE_WILL;}
198 #define	set_my_want_state_do(opt)	{options[opt] |= MY_WANT_STATE_DO;}
199 #define	set_my_want_state_will(opt)	{options[opt] |= MY_WANT_STATE_WILL;}
200 
201 #define	set_my_state_dont(opt)		{options[opt] &= ~MY_STATE_DO;}
202 #define	set_my_state_wont(opt)		{options[opt] &= ~MY_STATE_WILL;}
203 #define	set_my_want_state_dont(opt)	{options[opt] &= ~MY_WANT_STATE_DO;}
204 #define	set_my_want_state_wont(opt)	{options[opt] &= ~MY_WANT_STATE_WILL;}
205 
206 /*
207  * Make everything symetrical
208  */
209 
210 #define	HIS_STATE_WILL			MY_STATE_DO
211 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
212 #define HIS_STATE_DO			MY_STATE_WILL
213 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
214 
215 #define	his_state_is_do			my_state_is_will
216 #define	his_state_is_will		my_state_is_do
217 #define his_want_state_is_do		my_want_state_is_will
218 #define his_want_state_is_will		my_want_state_is_do
219 
220 #define	his_state_is_dont		my_state_is_wont
221 #define	his_state_is_wont		my_state_is_dont
222 #define his_want_state_is_dont		my_want_state_is_wont
223 #define his_want_state_is_wont		my_want_state_is_dont
224 
225 #define	set_his_state_do		set_my_state_will
226 #define	set_his_state_will		set_my_state_do
227 #define	set_his_want_state_do		set_my_want_state_will
228 #define	set_his_want_state_will		set_my_want_state_do
229 
230 #define	set_his_state_dont		set_my_state_wont
231 #define	set_his_state_wont		set_my_state_dont
232 #define	set_his_want_state_dont		set_my_want_state_wont
233 #define	set_his_want_state_wont		set_my_want_state_dont
234 
235 
236 extern FILE
237     *NetTrace;		/* Where debugging output goes */
238 extern unsigned char
239     NetTraceFile[];	/* Name of file where debugging output goes */
240 
241 extern jmp_buf
242     peerdied,
243     toplevel;		/* For error conditions. */
244 
245 
246 /* authenc.c */
247 int telnet_net_write P((unsigned char *, int));
248 void net_encrypt P((void));
249 int telnet_spin P((void));
250 char *telnet_getenv P((char *));
251 char *telnet_gets P((char *, char *, int, int));
252 
253 /* commands.c */
254 int send_tncmd P((void (*)(int, int), char *, char *));
255 void _setlist_init P((void));
256 void set_escape_char P((char *));
257 int set_mode P((int));
258 int clear_mode P((int));
259 int modehelp P((int));
260 int suspend P((int, char *[]));
261 int shell P((int, char *[]));
262 int quit P((int, char *[]));
263 int logout P((int, char *[]));
264 int env_cmd P((int, char *[]));
265 struct env_lst *env_find P((unsigned char *));
266 void env_init P((void));
267 struct env_lst *env_define P((unsigned char *, unsigned char *));
268 struct env_lst *env_undefine P((unsigned char *, unsigned char *));
269 struct env_lst *env_export P((unsigned char *, unsigned char *));
270 struct env_lst *env_unexport P((unsigned char *, unsigned char *));
271 struct env_lst *env_send P((unsigned char *, unsigned char *));
272 struct env_lst *env_list P((unsigned char *, unsigned char *));
273 unsigned char *env_default P((int, int ));
274 unsigned char *env_getvalue P((unsigned char *));
275 void env_varval P((unsigned char *));
276 int auth_cmd P((int, char *[]));
277 int ayt_status P((void));
278 int tn P((int, char *[]));
279 void command P((int, char *, int));
280 void cmdrc P((const char *, const char *));
281 struct addrinfo;
282 int sourceroute P((struct addrinfo *, char *, char **, int *, int*));
283 
284 /* main.c */
285 void tninit P((void));
286 void usage P((void));
287 
288 /* network.c */
289 void init_network P((void));
290 int stilloob P((void));
291 void setneturg P((void));
292 int netflush P((void));
293 
294 /* sys_bsd.c */
295 void init_sys P((void));
296 int TerminalWrite P((char *, int));
297 int TerminalRead P((unsigned char *, int));
298 int TerminalAutoFlush P((void));
299 int TerminalSpecialChars P((int));
300 void TerminalFlushOutput P((void));
301 void TerminalSaveState P((void));
302 cc_t *tcval P((int));
303 void TerminalDefaultChars P((void));
304 void TerminalRestoreState P((void));
305 void TerminalNewMode P((int));
306 void TerminalSpeeds P((long *, long *));
307 int TerminalWindowSize P((long *, long *));
308 int NetClose P((int));
309 void NetNonblockingIO P((int, int));
310 void NetSigIO P((int, int));
311 void NetSetPgrp P((int));
312 void sys_telnet_init P((void));
313 int process_rings P((int , int , int , int , int , int));
314 
315 /* telnet.c */
316 void init_telnet P((void));
317 void send_do P((int, int ));
318 void send_dont P((int, int ));
319 void send_will P((int, int ));
320 void send_wont P((int, int ));
321 void willoption P((int));
322 void wontoption P((int));
323 char **mklist P((char *, char *));
324 int is_unique P((char *, char **, char **));
325 int setup_term P((char *, int, int *));
326 char *gettermname P((void));
327 void lm_will P((unsigned char *, int));
328 void lm_wont P((unsigned char *, int));
329 void lm_do P((unsigned char *, int));
330 void lm_dont P((unsigned char *, int));
331 void lm_mode P((unsigned char *, int, int ));
332 void slc_init P((void));
333 void slcstate P((void));
334 void slc_mode_export P((int));
335 void slc_mode_import P((int));
336 void slc_import P((int));
337 void slc_export P((void));
338 void slc P((unsigned char *, int));
339 void slc_check P((void));
340 void slc_start_reply P((void));
341 void slc_add_reply P((unsigned int, unsigned int, cc_t));
342 void slc_end_reply P((void));
343 int slc_update P((void));
344 void env_opt P((unsigned char *, int));
345 void env_opt_start P((void));
346 void env_opt_start_info P((void));
347 void env_opt_add P((unsigned char *));
348 int opt_welldefined P((char *));
349 void env_opt_end P((int));
350 int telrcv P((void));
351 int rlogin_susp P((void));
352 int Scheduler P((int));
353 void telnet P((const char *));
354 void xmitAO P((void));
355 void xmitEL P((void));
356 void xmitEC P((void));
357 int dosynch P((char *));
358 int get_status P((char *));
359 void intp P((void));
360 void sendbrk P((void));
361 void sendabort P((void));
362 void sendsusp P((void));
363 void sendeof P((void));
364 void sendayt P((void));
365 void sendnaws P((void));
366 void tel_enter_binary P((int));
367 void tel_leave_binary P((int));
368 
369 /* terminal.c */
370 void init_terminal P((void));
371 int ttyflush P((int));
372 int getconnmode P((void));
373 void setconnmode P((int));
374 void setcommandmode P((void));
375 
376 /* utilities.c */
377 void upcase P((char *));
378 int SetSockOpt P((int, int , int , int ));
379 void SetNetTrace P((char *));
380 void Dump P((int, unsigned char *, int));
381 void printoption P((char *, int, int ));
382 void optionstatus P((void));
383 void printsub P((int, unsigned char *, int));
384 void EmptyTerminal P((void));
385 void SetForExit P((void));
386 void Exit P((int)) __attribute__((__noreturn__));
387 void ExitString P((char *, int)) __attribute__((__noreturn__));
388 
389 #ifndef	USE_TERMIO
390 
391 extern struct	tchars ntc;
392 extern struct	ltchars nltc;
393 extern struct	sgttyb nttyb;
394 
395 # define termEofChar		ntc.t_eofc
396 # define termEraseChar		nttyb.sg_erase
397 # define termFlushChar		nltc.t_flushc
398 # define termIntChar		ntc.t_intrc
399 # define termKillChar		nttyb.sg_kill
400 # define termLiteralNextChar	nltc.t_lnextc
401 # define termQuitChar		ntc.t_quitc
402 # define termSuspChar		nltc.t_suspc
403 # define termRprntChar		nltc.t_rprntc
404 # define termWerasChar		nltc.t_werasc
405 # define termStartChar		ntc.t_startc
406 # define termStopChar		ntc.t_stopc
407 # define termForw1Char		ntc.t_brkc
408 extern cc_t termForw2Char;
409 extern cc_t termAytChar;
410 
411 # define termEofCharp		(cc_t *)&ntc.t_eofc
412 # define termEraseCharp		(cc_t *)&nttyb.sg_erase
413 # define termFlushCharp		(cc_t *)&nltc.t_flushc
414 # define termIntCharp		(cc_t *)&ntc.t_intrc
415 # define termKillCharp		(cc_t *)&nttyb.sg_kill
416 # define termLiteralNextCharp	(cc_t *)&nltc.t_lnextc
417 # define termQuitCharp		(cc_t *)&ntc.t_quitc
418 # define termSuspCharp		(cc_t *)&nltc.t_suspc
419 # define termRprntCharp		(cc_t *)&nltc.t_rprntc
420 # define termWerasCharp		(cc_t *)&nltc.t_werasc
421 # define termStartCharp		(cc_t *)&ntc.t_startc
422 # define termStopCharp		(cc_t *)&ntc.t_stopc
423 # define termForw1Charp		(cc_t *)&ntc.t_brkc
424 # define termForw2Charp		(cc_t *)&termForw2Char
425 # define termAytCharp		(cc_t *)&termAytChar
426 
427 # else
428 
429 extern struct	termio new_tc;
430 
431 # define termEofChar		new_tc.c_cc[VEOF]
432 # define termEraseChar		new_tc.c_cc[VERASE]
433 # define termIntChar		new_tc.c_cc[VINTR]
434 # define termKillChar		new_tc.c_cc[VKILL]
435 # define termQuitChar		new_tc.c_cc[VQUIT]
436 
437 # ifndef	VSUSP
438 extern cc_t termSuspChar;
439 # else
440 #  define termSuspChar		new_tc.c_cc[VSUSP]
441 # endif
442 # if	defined(VFLUSHO) && !defined(VDISCARD)
443 #  define VDISCARD VFLUSHO
444 # endif
445 # ifndef	VDISCARD
446 extern cc_t termFlushChar;
447 # else
448 #  define termFlushChar		new_tc.c_cc[VDISCARD]
449 # endif
450 # ifndef VWERASE
451 extern cc_t termWerasChar;
452 # else
453 #  define termWerasChar		new_tc.c_cc[VWERASE]
454 # endif
455 # ifndef	VREPRINT
456 extern cc_t termRprntChar;
457 # else
458 #  define termRprntChar		new_tc.c_cc[VREPRINT]
459 # endif
460 # ifndef	VLNEXT
461 extern cc_t termLiteralNextChar;
462 # else
463 #  define termLiteralNextChar	new_tc.c_cc[VLNEXT]
464 # endif
465 # ifndef	VSTART
466 extern cc_t termStartChar;
467 # else
468 #  define termStartChar		new_tc.c_cc[VSTART]
469 # endif
470 # ifndef	VSTOP
471 extern cc_t termStopChar;
472 # else
473 #  define termStopChar		new_tc.c_cc[VSTOP]
474 # endif
475 # ifndef	VEOL
476 extern cc_t termForw1Char;
477 # else
478 #  define termForw1Char		new_tc.c_cc[VEOL]
479 # endif
480 # ifndef	VEOL2
481 extern cc_t termForw2Char;
482 # else
483 #  define termForw2Char		new_tc.c_cc[VEOL]
484 # endif
485 # ifndef	VSTATUS
486 extern cc_t termAytChar;
487 #else
488 #  define termAytChar		new_tc.c_cc[VSTATUS]
489 #endif
490 
491 # if !defined(CRAY) || defined(__STDC__)
492 #  define termEofCharp		&termEofChar
493 #  define termEraseCharp	&termEraseChar
494 #  define termIntCharp		&termIntChar
495 #  define termKillCharp		&termKillChar
496 #  define termQuitCharp		&termQuitChar
497 #  define termSuspCharp		&termSuspChar
498 #  define termFlushCharp	&termFlushChar
499 #  define termWerasCharp	&termWerasChar
500 #  define termRprntCharp	&termRprntChar
501 #  define termLiteralNextCharp	&termLiteralNextChar
502 #  define termStartCharp	&termStartChar
503 #  define termStopCharp		&termStopChar
504 #  define termForw1Charp	&termForw1Char
505 #  define termForw2Charp	&termForw2Char
506 #  define termAytCharp		&termAytChar
507 # else
508 	/* Work around a compiler bug */
509 #  define termEofCharp		0
510 #  define termEraseCharp	0
511 #  define termIntCharp		0
512 #  define termKillCharp		0
513 #  define termQuitCharp		0
514 #  define termSuspCharp		0
515 #  define termFlushCharp	0
516 #  define termWerasCharp	0
517 #  define termRprntCharp	0
518 #  define termLiteralNextCharp	0
519 #  define termStartCharp	0
520 #  define termStopCharp		0
521 #  define termForw1Charp	0
522 #  define termForw2Charp	0
523 #  define termAytCharp		0
524 # endif
525 #endif
526 
527 
528 /* Tn3270 section */
529 #if	defined(TN3270)
530 
531 extern int
532     HaveInput,		/* Whether an asynchronous I/O indication came in */
533     noasynchtty,	/* Don't do signals on I/O (SIGURG, SIGIO) */
534     noasynchnet,	/* Don't do signals on I/O (SIGURG, SIGIO) */
535     sigiocount,		/* Count of SIGIO receptions */
536     shell_active;	/* Subshell is active */
537 
538 extern char
539     *Ibackp,		/* Oldest byte of 3270 data */
540     Ibuf[],		/* 3270 buffer */
541     *Ifrontp,		/* Where next 3270 byte goes */
542     tline[],
543     *transcom;		/* Transparent command */
544 
545 /* tn3270.c */
546 void init_3270 P((void));
547 int DataToNetwork P((char *, int, int));
548 void inputAvailable P((int));
549 void outputPurge P((void));
550 int DataToTerminal P((char *, int));
551 int Push3270 P((void));
552 void Finish3270 P((void));
553 void StringToTerminal P((char *));
554 void _putchar P((int));
555 void SetIn3270 P((void));
556 int tn3270_ttype P((void));
557 int settranscom P((int, char *[]));
558 int shell_continue P((void));
559 int DataFromTerminal __P((char *, int));
560 int DataFromNetwork __P((char *, int, int));
561 void ConnectScreen __P((void));
562 int DoTerminalOutput __P((void));
563 
564 #endif	/* defined(TN3270) */
565