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