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