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/contrib/telnet/telnet/externs.h,v 1.11 2007/07/01 12:08:04 gnn Exp $ 35 */ 36 37#ifndef BSD 38# define BSD 43 39#endif 40 41/* 42 * ucb stdio.h defines BSD as something weird 43 */ 44#if defined(sun) && defined(__svr4__) 45#define BSD 43 46#endif 47 48#ifndef USE_TERMIO 49# if BSD > 43 || defined(SYSV_TERMIO) 50# define USE_TERMIO 51# endif 52#endif 53 54#include <stdio.h> 55#include <setjmp.h> 56#include <sys/ioctl.h> 57#include <errno.h> 58#ifdef USE_TERMIO 59# ifndef VINTR 60# include <sys/termios.h> 61# endif 62# define termio termios 63#endif 64#if defined(NO_CC_T) || !defined(USE_TERMIO) 65# if !defined(USE_TERMIO) 66typedef char cc_t; 67# else 68typedef unsigned char cc_t; 69# endif 70#endif 71 72#include <string.h> 73 74#if defined(IPSEC) 75#ifdef __APPLE__ 76#include <netinet6/ipsec.h> 77#else 78#include <netipsec/ipsec.h> 79#endif 80#if defined(IPSEC_POLICY_IPSEC) 81extern char *ipsec_policy_in; 82extern char *ipsec_policy_out; 83#endif 84#endif 85 86#ifndef _POSIX_VDISABLE 87# ifdef sun 88# include <sys/param.h> /* pick up VDISABLE definition, mayby */ 89# endif 90# ifdef VDISABLE 91# define _POSIX_VDISABLE VDISABLE 92# else 93# define _POSIX_VDISABLE ((cc_t)'\377') 94# endif 95#endif 96 97#define SUBBUFSIZE 256 98 99#if !defined(P) 100# ifdef __STDC__ 101# define P(x) x 102# else 103# define P(x) () 104# endif 105#endif 106 107extern int 108 autologin, /* Autologin enabled */ 109 skiprc, /* Don't process the ~/.telnetrc file */ 110 eight, /* use eight bit mode (binary in and/or out */ 111 family, /* address family of peer */ 112 flushout, /* flush output */ 113 connected, /* Are we connected to the other side? */ 114 globalmode, /* Mode tty should be in */ 115 telnetport, /* Are we connected to the telnet port? */ 116 localflow, /* Flow control handled locally */ 117 restartany, /* If flow control, restart output on any character */ 118 localchars, /* we recognize interrupt/quit */ 119 donelclchars, /* the user has set "localchars" */ 120 showoptions, 121 net, /* Network file descriptor */ 122 tin, /* Terminal input file descriptor */ 123 tout, /* Terminal output file descriptor */ 124 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */ 125 autoflush, /* flush output when interrupting? */ 126 autosynch, /* send interrupt characters with SYNCH? */ 127 SYNCHing, /* Is the stream in telnet SYNCH mode? */ 128 donebinarytoggle, /* the user has put us in binary */ 129 dontlecho, /* do we suppress local echoing right now? */ 130 crmod, 131 netdata, /* Print out network data flow */ 132 prettydump, /* Print "netdata" output in user readable format */ 133 termdata, /* Print out terminal data flow */ 134 telnet_debug, /* Debug level */ 135 doaddrlookup, /* do a reverse lookup? */ 136 clienteof; /* Client received EOF */ 137 138extern cc_t escape; /* Escape to command mode */ 139extern cc_t rlogin; /* Rlogin mode escape character */ 140#ifdef KLUDGELINEMODE 141extern cc_t echoc; /* Toggle local echoing */ 142#endif 143 144extern char 145 *prompt; /* Prompt for command. */ 146 147extern char 148 doopt[], 149 dont[], 150 will[], 151 wont[], 152 options[], /* All the little options */ 153 *hostname; /* Who are we connected to? */ 154#ifdef ENCRYPTION 155extern void (*encrypt_output)(unsigned char *, int); 156extern int (*decrypt_input)(int); 157#endif /* ENCRYPTION */ 158 159/* 160 * We keep track of each side of the option negotiation. 161 */ 162 163#define MY_STATE_WILL 0x01 164#define MY_WANT_STATE_WILL 0x02 165#define MY_STATE_DO 0x04 166#define MY_WANT_STATE_DO 0x08 167 168/* 169 * Macros to check the current state of things 170 */ 171 172#define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 173#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 174#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 175#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 176 177#define my_state_is_dont(opt) (!my_state_is_do(opt)) 178#define my_state_is_wont(opt) (!my_state_is_will(opt)) 179#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 180#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 181 182#define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;} 183#define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;} 184#define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;} 185#define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;} 186 187#define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;} 188#define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;} 189#define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;} 190#define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;} 191 192/* 193 * Make everything symetrical 194 */ 195 196#define HIS_STATE_WILL MY_STATE_DO 197#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 198#define HIS_STATE_DO MY_STATE_WILL 199#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 200 201#define his_state_is_do my_state_is_will 202#define his_state_is_will my_state_is_do 203#define his_want_state_is_do my_want_state_is_will 204#define his_want_state_is_will my_want_state_is_do 205 206#define his_state_is_dont my_state_is_wont 207#define his_state_is_wont my_state_is_dont 208#define his_want_state_is_dont my_want_state_is_wont 209#define his_want_state_is_wont my_want_state_is_dont 210 211#define set_his_state_do set_my_state_will 212#define set_his_state_will set_my_state_do 213#define set_his_want_state_do set_my_want_state_will 214#define set_his_want_state_will set_my_want_state_do 215 216#define set_his_state_dont set_my_state_wont 217#define set_his_state_wont set_my_state_dont 218#define set_his_want_state_dont set_my_want_state_wont 219#define set_his_want_state_wont set_my_want_state_dont 220 221#if defined(USE_TERMIO) 222#define SIG_FUNC_RET void 223#else 224#define SIG_FUNC_RET int 225#endif 226 227#ifdef SIGINFO 228extern SIG_FUNC_RET 229 ayt_status(void); 230#endif 231 232extern FILE 233 *NetTrace; /* Where debugging output goes */ 234extern unsigned char 235 NetTraceFile[]; /* Name of file where debugging output goes */ 236extern void 237 SetNetTrace(char *); /* Function to change where debugging goes */ 238 239extern jmp_buf 240 peerdied, 241 toplevel; /* For error conditions. */ 242 243extern void 244 command(int, const char *, int), 245 Dump(char, unsigned char *, int), 246 env_init(void), 247 Exit(int), 248 ExitString(const char *, int), 249 init_network(void), 250 init_sys(void), 251 init_telnet(void), 252 init_terminal(void), 253 intp(void), 254 optionstatus(void), 255 printoption(const char *, int, int), 256 printsub(char, unsigned char *, int), 257 quit(void), 258 sendabort(void), 259 sendbrk(void), 260 sendeof(void), 261 sendsusp(void), 262 sendnaws(void), 263 sendayt(void), 264 setconnmode(int), 265 setcommandmode(void), 266 set_escape_char(char *s), 267 setneturg(void), 268 sys_telnet_init(void), 269 telnet(char *), 270 tel_enter_binary(int), 271 tel_leave_binary(int), 272 TerminalFlushOutput(void), 273 TerminalNewMode(int), 274 TerminalRestoreState(void), 275 TerminalSaveState(void), 276 TerminalDefaultChars(void), 277 TerminalSpeeds(long *, long *), 278 tninit(void), 279 upcase(char *), 280 willoption(int), 281 wontoption(int); 282 283extern void 284 send_do(int, int), 285 send_dont(int, int), 286 send_will(int, int), 287 send_wont(int, int); 288 289extern void 290 lm_will(unsigned char *, int), 291 lm_wont(unsigned char *, int), 292 lm_do(unsigned char *, int), 293 lm_dont(unsigned char *, int), 294 lm_mode(unsigned char *, int, int); 295 296extern void 297 slc_init(void), 298 slcstate(void), 299 slc_mode_export(void), 300 slc_mode_import(int), 301 slc_import(int), 302 slc_export(void), 303 slc(unsigned char *, int), 304 slc_check(void), 305 slc_start_reply(void), 306 slc_add_reply(unsigned char, unsigned char, cc_t), 307 slc_end_reply(void); 308extern int 309 getconnmode(void), 310 opt_welldefined(const char *), 311 NetClose(int), 312 netflush(void), 313 process_rings(int, int, int, int, int, int), 314 rlogin_susp(void), 315 SetSockOpt(int, int, int, int), 316 slc_update(void), 317 stilloob(void), 318 telrcv(void), 319 TerminalRead(char *, int), 320 TerminalWrite(char *, int), 321 TerminalAutoFlush(void), 322 TerminalWindowSize(long *, long *), 323 TerminalSpecialChars(int), 324 tn(int, char **), 325 ttyflush(int); 326 327extern void 328 env_opt(unsigned char *, int), 329 env_opt_start(void), 330 env_opt_start_info(void), 331 env_opt_add(unsigned char *), 332 env_opt_end(int); 333 334extern unsigned char 335 *env_default(int, int), 336 *env_getvalue(const unsigned char *); 337 338extern int 339 get_status(char *), 340 dosynch(char *); 341 342extern cc_t 343 *tcval(int); 344 345#ifndef USE_TERMIO 346 347extern struct tchars ntc; 348extern struct ltchars nltc; 349extern struct sgttyb nttyb; 350 351# define termEofChar ntc.t_eofc 352# define termEraseChar nttyb.sg_erase 353# define termFlushChar nltc.t_flushc 354# define termIntChar ntc.t_intrc 355# define termKillChar nttyb.sg_kill 356# define termLiteralNextChar nltc.t_lnextc 357# define termQuitChar ntc.t_quitc 358# define termSuspChar nltc.t_suspc 359# define termRprntChar nltc.t_rprntc 360# define termWerasChar nltc.t_werasc 361# define termStartChar ntc.t_startc 362# define termStopChar ntc.t_stopc 363# define termForw1Char ntc.t_brkc 364extern cc_t termForw2Char; 365extern cc_t termAytChar; 366 367# define termEofCharp (cc_t *)&ntc.t_eofc 368# define termEraseCharp (cc_t *)&nttyb.sg_erase 369# define termFlushCharp (cc_t *)&nltc.t_flushc 370# define termIntCharp (cc_t *)&ntc.t_intrc 371# define termKillCharp (cc_t *)&nttyb.sg_kill 372# define termLiteralNextCharp (cc_t *)&nltc.t_lnextc 373# define termQuitCharp (cc_t *)&ntc.t_quitc 374# define termSuspCharp (cc_t *)&nltc.t_suspc 375# define termRprntCharp (cc_t *)&nltc.t_rprntc 376# define termWerasCharp (cc_t *)&nltc.t_werasc 377# define termStartCharp (cc_t *)&ntc.t_startc 378# define termStopCharp (cc_t *)&ntc.t_stopc 379# define termForw1Charp (cc_t *)&ntc.t_brkc 380# define termForw2Charp (cc_t *)&termForw2Char 381# define termAytCharp (cc_t *)&termAytChar 382 383# else 384 385extern struct termio new_tc; 386 387# define termEofChar new_tc.c_cc[VEOF] 388# define termEraseChar new_tc.c_cc[VERASE] 389# define termIntChar new_tc.c_cc[VINTR] 390# define termKillChar new_tc.c_cc[VKILL] 391# define termQuitChar new_tc.c_cc[VQUIT] 392 393# ifndef VSUSP 394extern cc_t termSuspChar; 395# else 396# define termSuspChar new_tc.c_cc[VSUSP] 397# endif 398# if defined(VFLUSHO) && !defined(VDISCARD) 399# define VDISCARD VFLUSHO 400# endif 401# ifndef VDISCARD 402extern cc_t termFlushChar; 403# else 404# define termFlushChar new_tc.c_cc[VDISCARD] 405# endif 406# ifndef VWERASE 407extern cc_t termWerasChar; 408# else 409# define termWerasChar new_tc.c_cc[VWERASE] 410# endif 411# ifndef VREPRINT 412extern cc_t termRprntChar; 413# else 414# define termRprntChar new_tc.c_cc[VREPRINT] 415# endif 416# ifndef VLNEXT 417extern cc_t termLiteralNextChar; 418# else 419# define termLiteralNextChar new_tc.c_cc[VLNEXT] 420# endif 421# ifndef VSTART 422extern cc_t termStartChar; 423# else 424# define termStartChar new_tc.c_cc[VSTART] 425# endif 426# ifndef VSTOP 427extern cc_t termStopChar; 428# else 429# define termStopChar new_tc.c_cc[VSTOP] 430# endif 431# ifndef VEOL 432extern cc_t termForw1Char; 433# else 434# define termForw1Char new_tc.c_cc[VEOL] 435# endif 436# ifndef VEOL2 437extern cc_t termForw2Char; 438# else 439# define termForw2Char new_tc.c_cc[VEOL] 440# endif 441# ifndef VSTATUS 442extern cc_t termAytChar; 443#else 444# define termAytChar new_tc.c_cc[VSTATUS] 445#endif 446 447# if defined(__STDC__) 448# define termEofCharp &termEofChar 449# define termEraseCharp &termEraseChar 450# define termIntCharp &termIntChar 451# define termKillCharp &termKillChar 452# define termQuitCharp &termQuitChar 453# define termSuspCharp &termSuspChar 454# define termFlushCharp &termFlushChar 455# define termWerasCharp &termWerasChar 456# define termRprntCharp &termRprntChar 457# define termLiteralNextCharp &termLiteralNextChar 458# define termStartCharp &termStartChar 459# define termStopCharp &termStopChar 460# define termForw1Charp &termForw1Char 461# define termForw2Charp &termForw2Char 462# define termAytCharp &termAytChar 463# else 464 /* Work around a compiler bug */ 465# define termEofCharp 0 466# define termEraseCharp 0 467# define termIntCharp 0 468# define termKillCharp 0 469# define termQuitCharp 0 470# define termSuspCharp 0 471# define termFlushCharp 0 472# define termWerasCharp 0 473# define termRprntCharp 0 474# define termLiteralNextCharp 0 475# define termStartCharp 0 476# define termStopCharp 0 477# define termForw1Charp 0 478# define termForw2Charp 0 479# define termAytCharp 0 480# endif 481#endif 482 483 484/* Ring buffer structures which are shared */ 485 486extern Ring 487 netoring, 488 netiring, 489 ttyoring, 490 ttyiring; 491 492extern void 493 xmitAO(void), 494 xmitEC(void), 495 xmitEL(void); 496