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/usr.bin/telnet/externs.h,v 1.5.2.2 2002/04/13 11:07:13 markm 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) 66 typedef char cc_t; 67 # else 68 typedef unsigned char cc_t; 69 # endif 70 #endif 71 72 #include <string.h> 73 74 #if defined(IPSEC) 75 #include <netinet6/ipsec.h> 76 #if defined(IPSEC_POLICY_IPSEC) 77 extern char *ipsec_policy_in; 78 extern char *ipsec_policy_out; 79 #endif 80 #endif 81 82 #ifndef _POSIX_VDISABLE 83 # ifdef sun 84 # include <sys/param.h> /* pick up VDISABLE definition, mayby */ 85 # endif 86 # ifdef VDISABLE 87 # define _POSIX_VDISABLE VDISABLE 88 # else 89 # define _POSIX_VDISABLE ((cc_t)'\377') 90 # endif 91 #endif 92 93 #define SUBBUFSIZE 256 94 95 #if !defined(P) 96 # ifdef __STDC__ 97 # define P(x) x 98 # else 99 # define P(x) () 100 # endif 101 #endif 102 103 extern int 104 autologin, /* Autologin enabled */ 105 skiprc, /* Don't process the ~/.telnetrc file */ 106 eight, /* use eight bit mode (binary in and/or out */ 107 family, /* address family of peer */ 108 flushout, /* flush output */ 109 connected, /* Are we connected to the other side? */ 110 globalmode, /* Mode tty should be in */ 111 telnetport, /* Are we connected to the telnet port? */ 112 localflow, /* Flow control handled locally */ 113 restartany, /* If flow control, restart output on any character */ 114 localchars, /* we recognize interrupt/quit */ 115 donelclchars, /* the user has set "localchars" */ 116 showoptions, 117 net, /* Network file descriptor */ 118 tin, /* Terminal input file descriptor */ 119 tout, /* Terminal output file descriptor */ 120 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */ 121 autoflush, /* flush output when interrupting? */ 122 autosynch, /* send interrupt characters with SYNCH? */ 123 SYNCHing, /* Is the stream in telnet SYNCH mode? */ 124 donebinarytoggle, /* the user has put us in binary */ 125 dontlecho, /* do we suppress local echoing right now? */ 126 crmod, 127 netdata, /* Print out network data flow */ 128 prettydump, /* Print "netdata" output in user readable format */ 129 termdata, /* Print out terminal data flow */ 130 debug, /* Debug level */ 131 doaddrlookup, /* do a reverse lookup? */ 132 clienteof; /* Client received EOF */ 133 134 extern cc_t escape; /* Escape to command mode */ 135 extern cc_t rlogin; /* Rlogin mode escape character */ 136 #ifdef KLUDGELINEMODE 137 extern cc_t echoc; /* Toggle local echoing */ 138 #endif 139 140 extern char 141 *prompt; /* Prompt for command. */ 142 143 extern char 144 doopt[], 145 dont[], 146 will[], 147 wont[], 148 options[], /* All the little options */ 149 *hostname; /* Who are we connected to? */ 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 231 extern jmp_buf 232 peerdied, 233 toplevel; /* For error conditions. */ 234 235 extern void 236 command(int, const char *, int), 237 Dump(char, unsigned char *, int), 238 env_init(void), 239 Exit(int), 240 ExitString(const char *, int), 241 init_network(void), 242 init_sys(void), 243 init_telnet(void), 244 init_terminal(void), 245 intp(void), 246 optionstatus(void), 247 printoption(const char *, int, int), 248 printsub(char, unsigned char *, int), 249 quit(void), 250 sendabort(void), 251 sendbrk(void), 252 sendeof(void), 253 sendsusp(void), 254 sendnaws(void), 255 sendayt(void), 256 setconnmode(int), 257 setcommandmode(void), 258 set_escape_char(char *s), 259 setneturg(void), 260 sys_telnet_init(void), 261 telnet(char *), 262 tel_enter_binary(int), 263 tel_leave_binary(int), 264 TerminalFlushOutput(void), 265 TerminalNewMode(int), 266 TerminalRestoreState(void), 267 TerminalSaveState(void), 268 TerminalDefaultChars(void), 269 TerminalSpeeds(long *, long *), 270 tninit(void), 271 upcase(char *), 272 willoption(int), 273 wontoption(int); 274 275 extern void 276 send_do(int, int), 277 send_dont(int, int), 278 send_will(int, int), 279 send_wont(int, int); 280 281 extern void 282 lm_will(unsigned char *, int), 283 lm_wont(unsigned char *, int), 284 lm_do(unsigned char *, int), 285 lm_dont(unsigned char *, int), 286 lm_mode(unsigned char *, int, int); 287 288 extern void 289 slc_init(void), 290 slcstate(void), 291 slc_mode_export(void), 292 slc_mode_import(int), 293 slc_import(int), 294 slc_export(void), 295 slc(unsigned char *, int), 296 slc_check(void), 297 slc_start_reply(void), 298 slc_add_reply(unsigned char, unsigned char, cc_t), 299 slc_end_reply(void); 300 extern int 301 getconnmode(void), 302 opt_welldefined(const char *), 303 NetClose(int), 304 netflush(void), 305 process_rings(int, int, int, int, int, int), 306 rlogin_susp(void), 307 SetSockOpt(int, int, int, int), 308 slc_update(void), 309 stilloob(void), 310 telrcv(void), 311 TerminalRead(char *, int), 312 TerminalWrite(char *, int), 313 TerminalAutoFlush(void), 314 TerminalWindowSize(long *, long *), 315 TerminalSpecialChars(int), 316 tn(int, char **), 317 ttyflush(int); 318 319 extern void 320 env_opt(unsigned char *, int), 321 env_opt_start(void), 322 env_opt_start_info(void), 323 env_opt_add(unsigned char *), 324 env_opt_end(int); 325 326 extern unsigned char 327 *env_default(int, int), 328 *env_getvalue(const unsigned char *); 329 330 extern int 331 get_status(char *), 332 dosynch(char *); 333 334 extern cc_t 335 *tcval(int); 336 337 #ifndef USE_TERMIO 338 339 extern struct tchars ntc; 340 extern struct ltchars nltc; 341 extern struct sgttyb nttyb; 342 343 # define termEofChar ntc.t_eofc 344 # define termEraseChar nttyb.sg_erase 345 # define termFlushChar nltc.t_flushc 346 # define termIntChar ntc.t_intrc 347 # define termKillChar nttyb.sg_kill 348 # define termLiteralNextChar nltc.t_lnextc 349 # define termQuitChar ntc.t_quitc 350 # define termSuspChar nltc.t_suspc 351 # define termRprntChar nltc.t_rprntc 352 # define termWerasChar nltc.t_werasc 353 # define termStartChar ntc.t_startc 354 # define termStopChar ntc.t_stopc 355 # define termForw1Char ntc.t_brkc 356 extern cc_t termForw2Char; 357 extern cc_t termAytChar; 358 359 # define termEofCharp (cc_t *)&ntc.t_eofc 360 # define termEraseCharp (cc_t *)&nttyb.sg_erase 361 # define termFlushCharp (cc_t *)&nltc.t_flushc 362 # define termIntCharp (cc_t *)&ntc.t_intrc 363 # define termKillCharp (cc_t *)&nttyb.sg_kill 364 # define termLiteralNextCharp (cc_t *)&nltc.t_lnextc 365 # define termQuitCharp (cc_t *)&ntc.t_quitc 366 # define termSuspCharp (cc_t *)&nltc.t_suspc 367 # define termRprntCharp (cc_t *)&nltc.t_rprntc 368 # define termWerasCharp (cc_t *)&nltc.t_werasc 369 # define termStartCharp (cc_t *)&ntc.t_startc 370 # define termStopCharp (cc_t *)&ntc.t_stopc 371 # define termForw1Charp (cc_t *)&ntc.t_brkc 372 # define termForw2Charp (cc_t *)&termForw2Char 373 # define termAytCharp (cc_t *)&termAytChar 374 375 # else 376 377 extern struct termio new_tc; 378 379 # define termEofChar new_tc.c_cc[VEOF] 380 # define termEraseChar new_tc.c_cc[VERASE] 381 # define termIntChar new_tc.c_cc[VINTR] 382 # define termKillChar new_tc.c_cc[VKILL] 383 # define termQuitChar new_tc.c_cc[VQUIT] 384 385 # ifndef VSUSP 386 extern cc_t termSuspChar; 387 # else 388 # define termSuspChar new_tc.c_cc[VSUSP] 389 # endif 390 # if defined(VFLUSHO) && !defined(VDISCARD) 391 # define VDISCARD VFLUSHO 392 # endif 393 # ifndef VDISCARD 394 extern cc_t termFlushChar; 395 # else 396 # define termFlushChar new_tc.c_cc[VDISCARD] 397 # endif 398 # ifndef VWERASE 399 extern cc_t termWerasChar; 400 # else 401 # define termWerasChar new_tc.c_cc[VWERASE] 402 # endif 403 # ifndef VREPRINT 404 extern cc_t termRprntChar; 405 # else 406 # define termRprntChar new_tc.c_cc[VREPRINT] 407 # endif 408 # ifndef VLNEXT 409 extern cc_t termLiteralNextChar; 410 # else 411 # define termLiteralNextChar new_tc.c_cc[VLNEXT] 412 # endif 413 # ifndef VSTART 414 extern cc_t termStartChar; 415 # else 416 # define termStartChar new_tc.c_cc[VSTART] 417 # endif 418 # ifndef VSTOP 419 extern cc_t termStopChar; 420 # else 421 # define termStopChar new_tc.c_cc[VSTOP] 422 # endif 423 # ifndef VEOL 424 extern cc_t termForw1Char; 425 # else 426 # define termForw1Char new_tc.c_cc[VEOL] 427 # endif 428 # ifndef VEOL2 429 extern cc_t termForw2Char; 430 # else 431 # define termForw2Char new_tc.c_cc[VEOL] 432 # endif 433 # ifndef VSTATUS 434 extern cc_t termAytChar; 435 #else 436 # define termAytChar new_tc.c_cc[VSTATUS] 437 #endif 438 439 # if defined(__STDC__) 440 # define termEofCharp &termEofChar 441 # define termEraseCharp &termEraseChar 442 # define termIntCharp &termIntChar 443 # define termKillCharp &termKillChar 444 # define termQuitCharp &termQuitChar 445 # define termSuspCharp &termSuspChar 446 # define termFlushCharp &termFlushChar 447 # define termWerasCharp &termWerasChar 448 # define termRprntCharp &termRprntChar 449 # define termLiteralNextCharp &termLiteralNextChar 450 # define termStartCharp &termStartChar 451 # define termStopCharp &termStopChar 452 # define termForw1Charp &termForw1Char 453 # define termForw2Charp &termForw2Char 454 # define termAytCharp &termAytChar 455 # else 456 /* Work around a compiler bug */ 457 # define termEofCharp 0 458 # define termEraseCharp 0 459 # define termIntCharp 0 460 # define termKillCharp 0 461 # define termQuitCharp 0 462 # define termSuspCharp 0 463 # define termFlushCharp 0 464 # define termWerasCharp 0 465 # define termRprntCharp 0 466 # define termLiteralNextCharp 0 467 # define termStartCharp 0 468 # define termStopCharp 0 469 # define termForw1Charp 0 470 # define termForw2Charp 0 471 # define termAytCharp 0 472 # endif 473 #endif 474 475 476 /* Ring buffer structures which are shared */ 477 478 extern Ring 479 netoring, 480 netiring, 481 ttyoring, 482 ttyiring; 483 484 extern void 485 xmitAO(void), 486 xmitEC(void), 487 xmitEL(void); 488