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