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. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)externs.h 8.3 (Berkeley) 5/30/95 30 * $FreeBSD: src/crypto/telnet/telnet/externs.h,v 1.4.2.2 2002/04/13 10:59:08 markm Exp $ 31 */ 32 33 #ifndef BSD 34 # define BSD 43 35 #endif 36 37 /* 38 * ucb stdio.h defines BSD as something weird 39 */ 40 #if defined(sun) && defined(__svr4__) 41 #define BSD 43 42 #endif 43 44 #ifndef USE_TERMIO 45 # if BSD > 43 || defined(SYSV_TERMIO) 46 # define USE_TERMIO 47 # endif 48 #endif 49 50 #include <stdio.h> 51 #include <setjmp.h> 52 #include <sys/ioctl.h> 53 #include <errno.h> 54 #ifdef USE_TERMIO 55 # ifndef VINTR 56 # include <termios.h> 57 # endif 58 # define termio termios 59 #endif 60 #if defined(NO_CC_T) || !defined(USE_TERMIO) 61 # if !defined(USE_TERMIO) 62 typedef char cc_t; 63 # else 64 typedef unsigned char cc_t; 65 # endif 66 #endif 67 68 #include <string.h> 69 70 #ifndef _POSIX_VDISABLE 71 # ifdef sun 72 # include <sys/param.h> /* pick up VDISABLE definition, mayby */ 73 # endif 74 # ifdef VDISABLE 75 # define _POSIX_VDISABLE VDISABLE 76 # else 77 # define _POSIX_VDISABLE ((cc_t)'\377') 78 # endif 79 #endif 80 81 #define SUBBUFSIZE 256 82 83 extern int 84 autologin, /* Autologin enabled */ 85 skiprc, /* Don't process the ~/.telnetrc file */ 86 eight, /* use eight bit mode (binary in and/or out */ 87 family, /* address family of peer */ 88 flushout, /* flush output */ 89 connected, /* Are we connected to the other side? */ 90 globalmode, /* Mode tty should be in */ 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 termdata, /* Print out terminal data flow */ 110 telnet_debug, /* Debug level */ 111 doaddrlookup, /* do a reverse lookup? */ 112 clienteof; /* Client received EOF */ 113 114 extern cc_t escape; /* Escape to command mode */ 115 extern cc_t rlogin; /* Rlogin mode escape character */ 116 #ifdef KLUDGELINEMODE 117 extern cc_t echoc; /* Toggle local echoing */ 118 #endif 119 120 extern char 121 *prompt; /* Prompt for command. */ 122 123 extern char 124 doopt[], 125 dont[], 126 will[], 127 wont[], 128 options[], /* All the little options */ 129 *hostname; /* Who are we connected to? */ 130 #ifdef ENCRYPTION 131 extern void (*encrypt_output)(unsigned char *, int); 132 extern int (*decrypt_input)(int); 133 #endif /* ENCRYPTION */ 134 135 /* 136 * We keep track of each side of the option negotiation. 137 */ 138 139 #define MY_STATE_WILL 0x01 140 #define MY_WANT_STATE_WILL 0x02 141 #define MY_STATE_DO 0x04 142 #define MY_WANT_STATE_DO 0x08 143 144 /* 145 * Macros to check the current state of things 146 */ 147 148 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 149 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 150 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 151 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 152 153 #define my_state_is_dont(opt) (!my_state_is_do(opt)) 154 #define my_state_is_wont(opt) (!my_state_is_will(opt)) 155 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 156 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 157 158 #define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;} 159 #define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;} 160 #define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;} 161 #define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;} 162 163 #define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;} 164 #define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;} 165 #define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;} 166 #define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;} 167 168 /* 169 * Make everything symetrical 170 */ 171 172 #define HIS_STATE_WILL MY_STATE_DO 173 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 174 #define HIS_STATE_DO MY_STATE_WILL 175 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 176 177 #define his_state_is_do my_state_is_will 178 #define his_state_is_will my_state_is_do 179 #define his_want_state_is_do my_want_state_is_will 180 #define his_want_state_is_will my_want_state_is_do 181 182 #define his_state_is_dont my_state_is_wont 183 #define his_state_is_wont my_state_is_dont 184 #define his_want_state_is_dont my_want_state_is_wont 185 #define his_want_state_is_wont my_want_state_is_dont 186 187 #define set_his_state_do set_my_state_will 188 #define set_his_state_will set_my_state_do 189 #define set_his_want_state_do set_my_want_state_will 190 #define set_his_want_state_will set_my_want_state_do 191 192 #define set_his_state_dont set_my_state_wont 193 #define set_his_state_wont set_my_state_dont 194 #define set_his_want_state_dont set_my_want_state_wont 195 #define set_his_want_state_wont set_my_want_state_dont 196 197 #if defined(USE_TERMIO) 198 #define SIG_FUNC_RET void 199 #else 200 #define SIG_FUNC_RET int 201 #endif 202 203 #ifdef SIGINFO 204 extern SIG_FUNC_RET 205 ayt_status(void); 206 #endif 207 208 extern FILE 209 *NetTrace; /* Where debugging output goes */ 210 extern unsigned char 211 NetTraceFile[]; /* Name of file where debugging output goes */ 212 extern void 213 SetNetTrace(char *); /* Function to change where debugging goes */ 214 215 extern jmp_buf 216 peerdied, 217 toplevel; /* For error conditions. */ 218 219 extern void 220 command(int, const char *, int), 221 Dump(char, unsigned char *, int), 222 env_init(void), 223 Exit(int) __dead2, 224 ExitString(const char *, int) __dead2, 225 init_network(void), 226 init_sys(void), 227 init_telnet(void), 228 init_terminal(void), 229 intp(void), 230 optionstatus(void), 231 printoption(const char *, int, int), 232 printsub(char, unsigned char *, int), 233 quit(void) __dead2, 234 sendabort(void), 235 sendbrk(void), 236 sendeof(void), 237 sendsusp(void), 238 sendnaws(void), 239 sendayt(void), 240 setconnmode(int), 241 setcommandmode(void), 242 set_escape_char(char *s), 243 setneturg(void), 244 sys_telnet_init(void), 245 telnet(char *), 246 tel_enter_binary(int), 247 tel_leave_binary(int), 248 TerminalFlushOutput(void), 249 TerminalNewMode(int), 250 TerminalRestoreState(void), 251 TerminalSaveState(void), 252 TerminalDefaultChars(void), 253 TerminalSpeeds(long *, long *), 254 tninit(void), 255 upcase(char *), 256 willoption(int), 257 wontoption(int); 258 259 extern void 260 send_do(int, int), 261 send_dont(int, int), 262 send_will(int, int), 263 send_wont(int, int); 264 265 extern void 266 lm_will(unsigned char *, int), 267 lm_wont(unsigned char *, int), 268 lm_do(unsigned char *, int), 269 lm_dont(unsigned char *, int), 270 lm_mode(unsigned char *, int, int); 271 272 extern void 273 slc_init(void), 274 slcstate(void), 275 slc_mode_export(void), 276 slc_mode_import(int), 277 slc_import(int), 278 slc_export(void), 279 slc(unsigned char *, int), 280 slc_check(void), 281 slc_start_reply(void), 282 slc_add_reply(unsigned char, unsigned char, cc_t), 283 slc_end_reply(void); 284 extern int 285 getconnmode(void), 286 opt_welldefined(const char *), 287 NetClose(int), 288 netflush(void), 289 process_rings(int, int, int, int, int, int), 290 rlogin_susp(void), 291 SetSockOpt(int, int, int, int), 292 slc_update(void), 293 stilloob(void), 294 telrcv(void), 295 TerminalRead(char *, int), 296 TerminalWrite(char *, int), 297 TerminalAutoFlush(void), 298 TerminalWindowSize(long *, long *), 299 TerminalSpecialChars(int), 300 tn(int, char **), 301 ttyflush(int); 302 303 extern void 304 env_opt(unsigned char *, int), 305 env_opt_start(void), 306 env_opt_start_info(void), 307 env_opt_add(unsigned char *), 308 env_opt_end(int); 309 310 extern unsigned char 311 *env_default(int, int), 312 *env_getvalue(const unsigned char *); 313 314 extern int 315 get_status(char *), 316 dosynch(char *); 317 318 extern cc_t 319 *tcval(int); 320 321 #ifndef USE_TERMIO 322 323 extern struct tchars ntc; 324 extern struct ltchars nltc; 325 extern struct sgttyb nttyb; 326 327 # define termEofChar ntc.t_eofc 328 # define termEraseChar nttyb.sg_erase 329 # define termFlushChar nltc.t_flushc 330 # define termIntChar ntc.t_intrc 331 # define termKillChar nttyb.sg_kill 332 # define termLiteralNextChar nltc.t_lnextc 333 # define termQuitChar ntc.t_quitc 334 # define termSuspChar nltc.t_suspc 335 # define termRprntChar nltc.t_rprntc 336 # define termWerasChar nltc.t_werasc 337 # define termStartChar ntc.t_startc 338 # define termStopChar ntc.t_stopc 339 # define termForw1Char ntc.t_brkc 340 extern cc_t termForw2Char; 341 extern cc_t termAytChar; 342 343 # define termEofCharp (cc_t *)&ntc.t_eofc 344 # define termEraseCharp (cc_t *)&nttyb.sg_erase 345 # define termFlushCharp (cc_t *)&nltc.t_flushc 346 # define termIntCharp (cc_t *)&ntc.t_intrc 347 # define termKillCharp (cc_t *)&nttyb.sg_kill 348 # define termLiteralNextCharp (cc_t *)&nltc.t_lnextc 349 # define termQuitCharp (cc_t *)&ntc.t_quitc 350 # define termSuspCharp (cc_t *)&nltc.t_suspc 351 # define termRprntCharp (cc_t *)&nltc.t_rprntc 352 # define termWerasCharp (cc_t *)&nltc.t_werasc 353 # define termStartCharp (cc_t *)&ntc.t_startc 354 # define termStopCharp (cc_t *)&ntc.t_stopc 355 # define termForw1Charp (cc_t *)&ntc.t_brkc 356 # define termForw2Charp (cc_t *)&termForw2Char 357 # define termAytCharp (cc_t *)&termAytChar 358 359 # else 360 361 extern struct termio new_tc; 362 363 # define termEofChar new_tc.c_cc[VEOF] 364 # define termEraseChar new_tc.c_cc[VERASE] 365 # define termIntChar new_tc.c_cc[VINTR] 366 # define termKillChar new_tc.c_cc[VKILL] 367 # define termQuitChar new_tc.c_cc[VQUIT] 368 369 # ifndef VSUSP 370 extern cc_t termSuspChar; 371 # else 372 # define termSuspChar new_tc.c_cc[VSUSP] 373 # endif 374 # if defined(VFLUSHO) && !defined(VDISCARD) 375 # define VDISCARD VFLUSHO 376 # endif 377 # ifndef VDISCARD 378 extern cc_t termFlushChar; 379 # else 380 # define termFlushChar new_tc.c_cc[VDISCARD] 381 # endif 382 # ifndef VWERASE 383 extern cc_t termWerasChar; 384 # else 385 # define termWerasChar new_tc.c_cc[VWERASE] 386 # endif 387 # ifndef VREPRINT 388 extern cc_t termRprntChar; 389 # else 390 # define termRprntChar new_tc.c_cc[VREPRINT] 391 # endif 392 # ifndef VLNEXT 393 extern cc_t termLiteralNextChar; 394 # else 395 # define termLiteralNextChar new_tc.c_cc[VLNEXT] 396 # endif 397 # ifndef VSTART 398 extern cc_t termStartChar; 399 # else 400 # define termStartChar new_tc.c_cc[VSTART] 401 # endif 402 # ifndef VSTOP 403 extern cc_t termStopChar; 404 # else 405 # define termStopChar new_tc.c_cc[VSTOP] 406 # endif 407 # ifndef VEOL 408 extern cc_t termForw1Char; 409 # else 410 # define termForw1Char new_tc.c_cc[VEOL] 411 # endif 412 # ifndef VEOL2 413 extern cc_t termForw2Char; 414 # else 415 # define termForw2Char new_tc.c_cc[VEOL] 416 # endif 417 # ifndef VSTATUS 418 extern cc_t termAytChar; 419 #else 420 # define termAytChar new_tc.c_cc[VSTATUS] 421 #endif 422 423 # if defined(__STDC__) 424 # define termEofCharp &termEofChar 425 # define termEraseCharp &termEraseChar 426 # define termIntCharp &termIntChar 427 # define termKillCharp &termKillChar 428 # define termQuitCharp &termQuitChar 429 # define termSuspCharp &termSuspChar 430 # define termFlushCharp &termFlushChar 431 # define termWerasCharp &termWerasChar 432 # define termRprntCharp &termRprntChar 433 # define termLiteralNextCharp &termLiteralNextChar 434 # define termStartCharp &termStartChar 435 # define termStopCharp &termStopChar 436 # define termForw1Charp &termForw1Char 437 # define termForw2Charp &termForw2Char 438 # define termAytCharp &termAytChar 439 # else 440 /* Work around a compiler bug */ 441 # define termEofCharp 0 442 # define termEraseCharp 0 443 # define termIntCharp 0 444 # define termKillCharp 0 445 # define termQuitCharp 0 446 # define termSuspCharp 0 447 # define termFlushCharp 0 448 # define termWerasCharp 0 449 # define termRprntCharp 0 450 # define termLiteralNextCharp 0 451 # define termStartCharp 0 452 # define termStopCharp 0 453 # define termForw1Charp 0 454 # define termForw2Charp 0 455 # define termAytCharp 0 456 # endif 457 #endif 458 459 460 /* Ring buffer structures which are shared */ 461 462 extern Ring 463 netoring, 464 netiring, 465 ttyoring, 466 ttyiring; 467 468 extern void 469 xmitAO(void), 470 xmitEC(void), 471 xmitEL(void); 472