externs.h revision 1.28 1 /* $NetBSD: externs.h,v 1.28 2003/07/14 15:56:29 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 weird
44 */
45 #if defined(sun) && defined(__svr4__) && !defined(BSD)
46 #define BSD 43
47 #endif
48
49
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <setjmp.h>
53 #include <sys/ioctl.h>
54 #include <errno.h>
55 #include <sys/termios.h>
56
57 #include <string.h>
58
59 #if defined(IPSEC)
60 #include <netinet6/ipsec.h>
61 #if defined(IPSEC_POLICY_IPSEC)
62 extern char *ipsec_policy_in;
63 extern char *ipsec_policy_out;
64 #endif
65 #endif
66
67 #ifndef _POSIX_VDISABLE
68 # ifdef sun
69 # include <sys/param.h> /* pick up VDISABLE definition, mayby */
70 # endif
71 # ifdef VDISABLE
72 # define _POSIX_VDISABLE VDISABLE
73 # else
74 # define _POSIX_VDISABLE ((cc_t)'\377')
75 # endif
76 #endif
77
78 #define SUBBUFSIZE 256
79
80 #include <sys/cdefs.h>
81
82 extern int
83 autologin, /* Autologin enabled */
84 skiprc, /* Don't process the ~/.telnetrc file */
85 eight, /* use eight bit mode (binary in and/or out */
86 family, /* address family of peer */
87 flushout, /* flush output */
88 connected, /* Are we connected to the other side? */
89 globalmode, /* Mode tty should be in */
90 In3270, /* Are we in 3270 mode? */
91 telnetport, /* Are we connected to the telnet port? */
92 localflow, /* Flow control handled locally */
93 restartany, /* If flow control, restart output on any character */
94 localchars, /* we recognize interrupt/quit */
95 donelclchars, /* the user has set "localchars" */
96 showoptions,
97 net, /* Network file descriptor */
98 tin, /* Terminal input file descriptor */
99 tout, /* Terminal output file descriptor */
100 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
101 autoflush, /* flush output when interrupting? */
102 autosynch, /* send interrupt characters with SYNCH? */
103 SYNCHing, /* Is the stream in telnet SYNCH mode? */
104 donebinarytoggle, /* the user has put us in binary */
105 dontlecho, /* do we suppress local echoing right now? */
106 crmod,
107 netdata, /* Print out network data flow */
108 prettydump, /* Print "netdata" output in user readable format */
109 #ifdef TN3270
110 cursesdata, /* Print out curses data flow */
111 apitrace, /* Trace API transactions */
112 #endif /* defined(TN3270) */
113 termdata, /* Print out terminal data flow */
114 debug, /* Debug level */
115 doaddrlookup, /* do a reverse address lookup? */
116 clienteof; /* Client received EOF */
117
118 extern cc_t escape; /* Escape to command mode */
119 extern cc_t rlogin; /* Rlogin mode escape character */
120 #ifdef KLUDGELINEMODE
121 extern cc_t echoc; /* Toggle local echoing */
122 #endif
123
124 extern char
125 *prompt; /* Prompt for command. */
126
127 extern char
128 doopt[],
129 dont[],
130 will[],
131 wont[],
132 options[], /* All the little options */
133 *hostname; /* Who are we connected to? */
134
135 #ifdef ENCRYPTION
136 extern void (*encrypt_output)(unsigned char *, int);
137 extern int (*decrypt_input)(int);
138 #endif /* ENCRYPTION */
139
140 /*
141 * We keep track of each side of the option negotiation.
142 */
143
144 #define MY_STATE_WILL 0x01
145 #define MY_WANT_STATE_WILL 0x02
146 #define MY_STATE_DO 0x04
147 #define MY_WANT_STATE_DO 0x08
148
149 /*
150 * Macros to check the current state of things
151 */
152
153 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
154 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
155 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
156 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
157
158 #define my_state_is_dont(opt) (!my_state_is_do(opt))
159 #define my_state_is_wont(opt) (!my_state_is_will(opt))
160 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
161 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
162
163 #define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;}
164 #define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;}
165 #define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;}
166 #define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;}
167
168 #define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;}
169 #define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;}
170 #define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;}
171 #define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;}
172
173 /*
174 * Make everything symmetrical
175 */
176
177 #define HIS_STATE_WILL MY_STATE_DO
178 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
179 #define HIS_STATE_DO MY_STATE_WILL
180 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
181
182 #define his_state_is_do my_state_is_will
183 #define his_state_is_will my_state_is_do
184 #define his_want_state_is_do my_want_state_is_will
185 #define his_want_state_is_will my_want_state_is_do
186
187 #define his_state_is_dont my_state_is_wont
188 #define his_state_is_wont my_state_is_dont
189 #define his_want_state_is_dont my_want_state_is_wont
190 #define his_want_state_is_wont my_want_state_is_dont
191
192 #define set_his_state_do set_my_state_will
193 #define set_his_state_will set_my_state_do
194 #define set_his_want_state_do set_my_want_state_will
195 #define set_his_want_state_will set_my_want_state_do
196
197 #define set_his_state_dont set_my_state_wont
198 #define set_his_state_wont set_my_state_dont
199 #define set_his_want_state_dont set_my_want_state_wont
200 #define set_his_want_state_wont set_my_want_state_dont
201
202
203 extern FILE
204 *NetTrace; /* Where debugging output goes */
205 extern char
206 NetTraceFile[]; /* Name of file where debugging output goes */
207
208 extern jmp_buf
209 peerdied,
210 toplevel; /* For error conditions. */
211
212
213 /* authenc.c */
214 int telnet_net_write(unsigned char *, int);
215 void net_encrypt(void);
216 int telnet_spin(void);
217 char *telnet_getenv(char *);
218 char *telnet_gets(char *, char *, int, int);
219
220 /* commands.c */
221 int send_tncmd(void (*)(int, int), char *, char *);
222 void _setlist_init(void);
223 void set_escape_char(char *);
224 int set_mode(int);
225 int clear_mode(int);
226 int modehelp(int);
227 int suspend(int, char *[]);
228 int shell(int, char *[]);
229 int quit(int, char *[]);
230 int logout(int, char *[]);
231 int env_cmd(int, char *[]);
232 struct env_lst *env_find(unsigned char *);
233 void env_init(void);
234 struct env_lst *env_define(unsigned char *, unsigned char *);
235 struct env_lst *env_undefine(unsigned char *, unsigned char *);
236 struct env_lst *env_export(unsigned char *, unsigned char *);
237 struct env_lst *env_unexport(unsigned char *, unsigned char *);
238 struct env_lst *env_send(unsigned char *, unsigned char *);
239 struct env_lst *env_list(unsigned char *, unsigned char *);
240 unsigned char *env_default(int, int );
241 unsigned char *env_getvalue(unsigned char *);
242 void env_varval(unsigned char *);
243 int auth_cmd(int, char *[]);
244 int ayt_status(void);
245 int encrypt_cmd(int, char *[]);
246 int tn(int, char *[]);
247 void command(int, char *, int);
248 void cmdrc(const char *, const char *);
249 struct addrinfo;
250 int sourceroute(struct addrinfo *, char *, char **, int *, int*);
251
252 /* main.c */
253 void tninit(void);
254 void usage(void);
255
256 /* network.c */
257 void init_network(void);
258 int stilloob(void);
259 void setneturg(void);
260 int netflush(void);
261
262 /* sys_bsd.c */
263 void init_sys(void);
264 int TerminalWrite(char *, int);
265 int TerminalRead(unsigned char *, int);
266 int TerminalAutoFlush(void);
267 int TerminalSpecialChars(int);
268 void TerminalFlushOutput(void);
269 void TerminalSaveState(void);
270 cc_t *tcval(int);
271 void TerminalDefaultChars(void);
272 void TerminalRestoreState(void);
273 void TerminalNewMode(int);
274 void TerminalSpeeds(long *, long *);
275 int TerminalWindowSize(long *, long *);
276 int NetClose(int);
277 void NetNonblockingIO(int, int);
278 void NetSigIO(int, int);
279 void NetSetPgrp(int);
280 void sys_telnet_init(void);
281 int process_rings(int , int , int , int , int , int);
282
283 /* telnet.c */
284 void init_telnet(void);
285 void send_do(int, int );
286 void send_dont(int, int );
287 void send_will(int, int );
288 void send_wont(int, int );
289 void willoption(int);
290 void wontoption(int);
291 char **mklist(char *, char *);
292 int is_unique(char *, char **, char **);
293 int setup_term(char *, int, int *);
294 char *gettermname(void);
295 void lm_will(unsigned char *, int);
296 void lm_wont(unsigned char *, int);
297 void lm_do(unsigned char *, int);
298 void lm_dont(unsigned char *, int);
299 void lm_mode(unsigned char *, int, int );
300 void slc_init(void);
301 void slcstate(void);
302 void slc_mode_export(int);
303 void slc_mode_import(int);
304 void slc_import(int);
305 void slc_export(void);
306 void slc(unsigned char *, int);
307 void slc_check(void);
308 void slc_start_reply(void);
309 void slc_add_reply(unsigned int, unsigned int, cc_t);
310 void slc_end_reply(void);
311 int slc_update(void);
312 void env_opt(unsigned char *, int);
313 void env_opt_start(void);
314 void env_opt_start_info(void);
315 void env_opt_add(unsigned char *);
316 int opt_welldefined(char *);
317 void env_opt_end(int);
318 int telrcv(void);
319 int rlogin_susp(void);
320 int Scheduler(int);
321 void telnet(const char *);
322 void xmitAO(void);
323 void xmitEL(void);
324 void xmitEC(void);
325 int dosynch(char *);
326 int get_status(char *);
327 void intp(void);
328 void sendbrk(void);
329 void sendabort(void);
330 void sendsusp(void);
331 void sendeof(void);
332 void sendayt(void);
333 void sendnaws(void);
334 void tel_enter_binary(int);
335 void tel_leave_binary(int);
336
337 /* terminal.c */
338 void init_terminal(void);
339 int ttyflush(int);
340 int getconnmode(void);
341 void setconnmode(int);
342 void setcommandmode(void);
343
344 /* utilities.c */
345 void upcase(char *);
346 int SetSockOpt(int, int, int, int);
347 void SetNetTrace(char *);
348 void Dump(int, unsigned char *, int);
349 void printoption(char *, int, int );
350 void optionstatus(void);
351 void printsub(int, unsigned char *, int);
352 void EmptyTerminal(void);
353 void SetForExit(void);
354 void Exit(int) __attribute__((__noreturn__));
355 void ExitString(char *, int) __attribute__((__noreturn__));
356
357
358 extern struct termios new_tc;
359
360 # define termEofChar new_tc.c_cc[VEOF]
361 # define termEraseChar new_tc.c_cc[VERASE]
362 # define termIntChar new_tc.c_cc[VINTR]
363 # define termKillChar new_tc.c_cc[VKILL]
364 # define termQuitChar new_tc.c_cc[VQUIT]
365
366 # define termSuspChar new_tc.c_cc[VSUSP]
367 # define termFlushChar new_tc.c_cc[VDISCARD]
368 # define termWerasChar new_tc.c_cc[VWERASE]
369 # define termRprntChar new_tc.c_cc[VREPRINT]
370 # define termLiteralNextChar new_tc.c_cc[VLNEXT]
371 # define termStartChar new_tc.c_cc[VSTART]
372 # define termStopChar new_tc.c_cc[VSTOP]
373 # define termForw1Char new_tc.c_cc[VEOL]
374 # define termForw2Char new_tc.c_cc[VEOL]
375 # define termAytChar new_tc.c_cc[VSTATUS]
376
377 # define termEofCharp &termEofChar
378 # define termEraseCharp &termEraseChar
379 # define termIntCharp &termIntChar
380 # define termKillCharp &termKillChar
381 # define termQuitCharp &termQuitChar
382 # define termSuspCharp &termSuspChar
383 # define termFlushCharp &termFlushChar
384 # define termWerasCharp &termWerasChar
385 # define termRprntCharp &termRprntChar
386 # define termLiteralNextCharp &termLiteralNextChar
387 # define termStartCharp &termStartChar
388 # define termStopCharp &termStopChar
389 # define termForw1Charp &termForw1Char
390 # define termForw2Charp &termForw2Char
391 # define termAytCharp &termAytChar
392
393
394 /* Tn3270 section */
395 #if defined(TN3270)
396
397 extern int
398 HaveInput, /* Whether an asynchronous I/O indication came in */
399 noasynchtty, /* Don't do signals on I/O (SIGURG, SIGIO) */
400 noasynchnet, /* Don't do signals on I/O (SIGURG, SIGIO) */
401 sigiocount, /* Count of SIGIO receptions */
402 shell_active; /* Subshell is active */
403
404 extern char
405 *Ibackp, /* Oldest byte of 3270 data */
406 Ibuf[], /* 3270 buffer */
407 *Ifrontp, /* Where next 3270 byte goes */
408 tline[200],
409 *transcom; /* Transparent command */
410
411 /* tn3270.c */
412 void init_3270(void);
413 int DataToNetwork(char *, int, int);
414 void inputAvailable(int);
415 void outputPurge(void);
416 int DataToTerminal(char *, int);
417 int Push3270(void);
418 void Finish3270(void);
419 void StringToTerminal(char *);
420 int _putchar(int);
421 void SetIn3270(void);
422 int tn3270_ttype(void);
423 int settranscom(int, char *[]);
424 int shell_continue(void);
425 int DataFromTerminal(char *, int);
426 int DataFromNetwork(char *, int, int);
427 void ConnectScreen(void);
428 int DoTerminalOutput(void);
429
430 #endif /* defined(TN3270) */
431