Stop building multiple versions of telnet.
[dragonfly.git] / usr.bin / telnet / externs.h
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/crypto/telnet/telnet/externs.h,v 1.4.2.2 2002/04/13 10:59:08 markm Exp $
35  *      $DragonFly: src/crypto/telnet/telnet/externs.h,v 1.2 2003/06/17 04:24:37 dillon 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 #ifdef  ENCRYPTION
144 extern void (*encrypt_output)(unsigned char *, int);
145 extern int (*decrypt_input)(int);
146 #endif  /* ENCRYPTION */
147
148 /*
149  * We keep track of each side of the option negotiation.
150  */
151
152 #define MY_STATE_WILL           0x01
153 #define MY_WANT_STATE_WILL      0x02
154 #define MY_STATE_DO             0x04
155 #define MY_WANT_STATE_DO        0x08
156
157 /*
158  * Macros to check the current state of things
159  */
160
161 #define my_state_is_do(opt)             (options[opt]&MY_STATE_DO)
162 #define my_state_is_will(opt)           (options[opt]&MY_STATE_WILL)
163 #define my_want_state_is_do(opt)        (options[opt]&MY_WANT_STATE_DO)
164 #define my_want_state_is_will(opt)      (options[opt]&MY_WANT_STATE_WILL)
165
166 #define my_state_is_dont(opt)           (!my_state_is_do(opt))
167 #define my_state_is_wont(opt)           (!my_state_is_will(opt))
168 #define my_want_state_is_dont(opt)      (!my_want_state_is_do(opt))
169 #define my_want_state_is_wont(opt)      (!my_want_state_is_will(opt))
170
171 #define set_my_state_do(opt)            {options[opt] |= MY_STATE_DO;}
172 #define set_my_state_will(opt)          {options[opt] |= MY_STATE_WILL;}
173 #define set_my_want_state_do(opt)       {options[opt] |= MY_WANT_STATE_DO;}
174 #define set_my_want_state_will(opt)     {options[opt] |= MY_WANT_STATE_WILL;}
175
176 #define set_my_state_dont(opt)          {options[opt] &= ~MY_STATE_DO;}
177 #define set_my_state_wont(opt)          {options[opt] &= ~MY_STATE_WILL;}
178 #define set_my_want_state_dont(opt)     {options[opt] &= ~MY_WANT_STATE_DO;}
179 #define set_my_want_state_wont(opt)     {options[opt] &= ~MY_WANT_STATE_WILL;}
180
181 /*
182  * Make everything symetrical
183  */
184
185 #define HIS_STATE_WILL                  MY_STATE_DO
186 #define HIS_WANT_STATE_WILL             MY_WANT_STATE_DO
187 #define HIS_STATE_DO                    MY_STATE_WILL
188 #define HIS_WANT_STATE_DO               MY_WANT_STATE_WILL
189
190 #define his_state_is_do                 my_state_is_will
191 #define his_state_is_will               my_state_is_do
192 #define his_want_state_is_do            my_want_state_is_will
193 #define his_want_state_is_will          my_want_state_is_do
194
195 #define his_state_is_dont               my_state_is_wont
196 #define his_state_is_wont               my_state_is_dont
197 #define his_want_state_is_dont          my_want_state_is_wont
198 #define his_want_state_is_wont          my_want_state_is_dont
199
200 #define set_his_state_do                set_my_state_will
201 #define set_his_state_will              set_my_state_do
202 #define set_his_want_state_do           set_my_want_state_will
203 #define set_his_want_state_will         set_my_want_state_do
204
205 #define set_his_state_dont              set_my_state_wont
206 #define set_his_state_wont              set_my_state_dont
207 #define set_his_want_state_dont         set_my_want_state_wont
208 #define set_his_want_state_wont         set_my_want_state_dont
209
210 #if     defined(USE_TERMIO)
211 #define SIG_FUNC_RET    void
212 #else
213 #define SIG_FUNC_RET    int
214 #endif
215
216 #ifdef  SIGINFO
217 extern SIG_FUNC_RET
218     ayt_status(void);
219 #endif
220
221 extern FILE
222     *NetTrace;          /* Where debugging output goes */
223 extern unsigned char
224     NetTraceFile[];     /* Name of file where debugging output goes */
225 extern void
226     SetNetTrace(char *);        /* Function to change where debugging goes */
227
228 extern jmp_buf
229     peerdied,
230     toplevel;           /* For error conditions. */
231
232 extern void
233     command(int, const char *, int),
234     Dump(char, unsigned char *, int),
235     env_init(void),
236     Exit(int),
237     ExitString(const char *, int),
238     init_network(void),
239     init_sys(void),
240     init_telnet(void),
241     init_terminal(void),
242     intp(void),
243     optionstatus(void),
244     printoption(const char *, int, int),
245     printsub(char, unsigned char *, int),
246     quit(void),
247     sendabort(void),
248     sendbrk(void),
249     sendeof(void),
250     sendsusp(void),
251     sendnaws(void),
252     sendayt(void),
253     setconnmode(int),
254     setcommandmode(void),
255     set_escape_char(char *s),
256     setneturg(void),
257     sys_telnet_init(void),
258     telnet(char *),
259     tel_enter_binary(int),
260     tel_leave_binary(int),
261     TerminalFlushOutput(void),
262     TerminalNewMode(int),
263     TerminalRestoreState(void),
264     TerminalSaveState(void),
265     TerminalDefaultChars(void),
266     TerminalSpeeds(long *, long *),
267     tninit(void),
268     upcase(char *),
269     willoption(int),
270     wontoption(int);
271
272 extern void
273     send_do(int, int),
274     send_dont(int, int),
275     send_will(int, int),
276     send_wont(int, int);
277
278 extern void
279     lm_will(unsigned char *, int),
280     lm_wont(unsigned char *, int),
281     lm_do(unsigned char *, int),
282     lm_dont(unsigned char *, int),
283     lm_mode(unsigned char *, int, int);
284
285 extern void
286     slc_init(void),
287     slcstate(void),
288     slc_mode_export(void),
289     slc_mode_import(int),
290     slc_import(int),
291     slc_export(void),
292     slc(unsigned char *, int),
293     slc_check(void),
294     slc_start_reply(void),
295     slc_add_reply(unsigned char, unsigned char, cc_t),
296     slc_end_reply(void);
297 extern int
298     getconnmode(void),
299     opt_welldefined(const char *),
300     NetClose(int),
301     netflush(void),
302     process_rings(int, int, int, int, int, int),
303     rlogin_susp(void),
304     SetSockOpt(int, int, int, int),
305     slc_update(void),
306     stilloob(void),
307     telrcv(void),
308     TerminalRead(char *, int),
309     TerminalWrite(char *, int),
310     TerminalAutoFlush(void),
311     TerminalWindowSize(long *, long *),
312     TerminalSpecialChars(int),
313     tn(int, char **),
314     ttyflush(int);
315
316 extern void
317     env_opt(unsigned char *, int),
318     env_opt_start(void),
319     env_opt_start_info(void),
320     env_opt_add(unsigned char *),
321     env_opt_end(int);
322
323 extern unsigned char
324     *env_default(int, int),
325     *env_getvalue(const unsigned char *);
326
327 extern int
328     get_status(char *),
329     dosynch(char *);
330
331 extern cc_t
332     *tcval(int);
333
334 #ifndef USE_TERMIO
335
336 extern struct   tchars ntc;
337 extern struct   ltchars nltc;
338 extern struct   sgttyb nttyb;
339
340 # define termEofChar            ntc.t_eofc
341 # define termEraseChar          nttyb.sg_erase
342 # define termFlushChar          nltc.t_flushc
343 # define termIntChar            ntc.t_intrc
344 # define termKillChar           nttyb.sg_kill
345 # define termLiteralNextChar    nltc.t_lnextc
346 # define termQuitChar           ntc.t_quitc
347 # define termSuspChar           nltc.t_suspc
348 # define termRprntChar          nltc.t_rprntc
349 # define termWerasChar          nltc.t_werasc
350 # define termStartChar          ntc.t_startc
351 # define termStopChar           ntc.t_stopc
352 # define termForw1Char          ntc.t_brkc
353 extern cc_t termForw2Char;
354 extern cc_t termAytChar;
355
356 # define termEofCharp           (cc_t *)&ntc.t_eofc
357 # define termEraseCharp         (cc_t *)&nttyb.sg_erase
358 # define termFlushCharp         (cc_t *)&nltc.t_flushc
359 # define termIntCharp           (cc_t *)&ntc.t_intrc
360 # define termKillCharp          (cc_t *)&nttyb.sg_kill
361 # define termLiteralNextCharp   (cc_t *)&nltc.t_lnextc
362 # define termQuitCharp          (cc_t *)&ntc.t_quitc
363 # define termSuspCharp          (cc_t *)&nltc.t_suspc
364 # define termRprntCharp         (cc_t *)&nltc.t_rprntc
365 # define termWerasCharp         (cc_t *)&nltc.t_werasc
366 # define termStartCharp         (cc_t *)&ntc.t_startc
367 # define termStopCharp          (cc_t *)&ntc.t_stopc
368 # define termForw1Charp         (cc_t *)&ntc.t_brkc
369 # define termForw2Charp         (cc_t *)&termForw2Char
370 # define termAytCharp           (cc_t *)&termAytChar
371
372 # else
373
374 extern struct   termio new_tc;
375
376 # define termEofChar            new_tc.c_cc[VEOF]
377 # define termEraseChar          new_tc.c_cc[VERASE]
378 # define termIntChar            new_tc.c_cc[VINTR]
379 # define termKillChar           new_tc.c_cc[VKILL]
380 # define termQuitChar           new_tc.c_cc[VQUIT]
381
382 # ifndef        VSUSP
383 extern cc_t termSuspChar;
384 # else
385 #  define termSuspChar          new_tc.c_cc[VSUSP]
386 # endif
387 # if    defined(VFLUSHO) && !defined(VDISCARD)
388 #  define VDISCARD VFLUSHO
389 # endif
390 # ifndef        VDISCARD
391 extern cc_t termFlushChar;
392 # else
393 #  define termFlushChar         new_tc.c_cc[VDISCARD]
394 # endif
395 # ifndef VWERASE
396 extern cc_t termWerasChar;
397 # else
398 #  define termWerasChar         new_tc.c_cc[VWERASE]
399 # endif
400 # ifndef        VREPRINT
401 extern cc_t termRprntChar;
402 # else
403 #  define termRprntChar         new_tc.c_cc[VREPRINT]
404 # endif
405 # ifndef        VLNEXT
406 extern cc_t termLiteralNextChar;
407 # else
408 #  define termLiteralNextChar   new_tc.c_cc[VLNEXT]
409 # endif
410 # ifndef        VSTART
411 extern cc_t termStartChar;
412 # else
413 #  define termStartChar         new_tc.c_cc[VSTART]
414 # endif
415 # ifndef        VSTOP
416 extern cc_t termStopChar;
417 # else
418 #  define termStopChar          new_tc.c_cc[VSTOP]
419 # endif
420 # ifndef        VEOL
421 extern cc_t termForw1Char;
422 # else
423 #  define termForw1Char         new_tc.c_cc[VEOL]
424 # endif
425 # ifndef        VEOL2
426 extern cc_t termForw2Char;
427 # else
428 #  define termForw2Char         new_tc.c_cc[VEOL]
429 # endif
430 # ifndef        VSTATUS
431 extern cc_t termAytChar;
432 #else
433 #  define termAytChar           new_tc.c_cc[VSTATUS]
434 #endif
435
436 # if defined(__STDC__)
437 #  define termEofCharp          &termEofChar
438 #  define termEraseCharp        &termEraseChar
439 #  define termIntCharp          &termIntChar
440 #  define termKillCharp         &termKillChar
441 #  define termQuitCharp         &termQuitChar
442 #  define termSuspCharp         &termSuspChar
443 #  define termFlushCharp        &termFlushChar
444 #  define termWerasCharp        &termWerasChar
445 #  define termRprntCharp        &termRprntChar
446 #  define termLiteralNextCharp  &termLiteralNextChar
447 #  define termStartCharp        &termStartChar
448 #  define termStopCharp         &termStopChar
449 #  define termForw1Charp        &termForw1Char
450 #  define termForw2Charp        &termForw2Char
451 #  define termAytCharp          &termAytChar
452 # else
453         /* Work around a compiler bug */
454 #  define termEofCharp          0
455 #  define termEraseCharp        0
456 #  define termIntCharp          0
457 #  define termKillCharp         0
458 #  define termQuitCharp         0
459 #  define termSuspCharp         0
460 #  define termFlushCharp        0
461 #  define termWerasCharp        0
462 #  define termRprntCharp        0
463 #  define termLiteralNextCharp  0
464 #  define termStartCharp        0
465 #  define termStopCharp         0
466 #  define termForw1Charp        0
467 #  define termForw2Charp        0
468 #  define termAytCharp          0
469 # endif
470 #endif
471
472
473 /* Ring buffer structures which are shared */
474
475 extern Ring
476     netoring,
477     netiring,
478     ttyoring,
479     ttyiring;
480
481 extern void
482     xmitAO(void),
483     xmitEC(void),
484     xmitEL(void);