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