1275970Scy/* 2275970Scy * Copyright (c) 1988, 1990, 1993 3275970Scy * The Regents of the University of California. All rights reserved. 4275970Scy * 5275970Scy * Redistribution and use in source and binary forms, with or without 6275970Scy * modification, are permitted provided that the following conditions 7275970Scy * are met: 8275970Scy * 1. Redistributions of source code must retain the above copyright 9275970Scy * notice, this list of conditions and the following disclaimer. 10275970Scy * 2. Redistributions in binary form must reproduce the above copyright 11275970Scy * notice, this list of conditions and the following disclaimer in the 12275970Scy * documentation and/or other materials provided with the distribution. 13275970Scy * 3. All advertising materials mentioning features or use of this software 14275970Scy * must display the following acknowledgement: 15275970Scy * This product includes software developed by the University of 16275970Scy * California, Berkeley and its contributors. 17275970Scy * 4. Neither the name of the University nor the names of its contributors 18275970Scy * may be used to endorse or promote products derived from this software 19275970Scy * without specific prior written permission. 20275970Scy * 21275970Scy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22275970Scy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23275970Scy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24275970Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25275970Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26275970Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27275970Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28275970Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29275970Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30275970Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31275970Scy * SUCH DAMAGE. 32275970Scy * 33275970Scy * @(#)externs.h 8.3 (Berkeley) 5/30/95 34275970Scy * $FreeBSD: src/contrib/telnet/telnet/externs.h,v 1.10 2003/05/11 18:17:00 markm Exp $ 35275970Scy */ 36275970Scy 37275970Scy#ifndef BSD 38275970Scy# define BSD 43 39275970Scy#endif 40275970Scy 41275970Scy/* 42275970Scy * ucb stdio.h defines BSD as something weird 43275970Scy */ 44275970Scy#if defined(sun) && defined(__svr4__) 45275970Scy#define BSD 43 46275970Scy#endif 47275970Scy 48275970Scy#ifndef USE_TERMIO 49275970Scy# if BSD > 43 || defined(SYSV_TERMIO) 50275970Scy# define USE_TERMIO 51275970Scy# endif 52275970Scy#endif 53275970Scy 54275970Scy#include <stdio.h> 55275970Scy#include <setjmp.h> 56275970Scy#include <sys/ioctl.h> 57275970Scy#include <errno.h> 58275970Scy#ifdef USE_TERMIO 59275970Scy# ifndef VINTR 60275970Scy# include <termios.h> 61275970Scy# endif 62275970Scy# define termio termios 63275970Scy#endif 64275970Scy#if defined(NO_CC_T) || !defined(USE_TERMIO) 65275970Scy# if !defined(USE_TERMIO) 66275970Scytypedef char cc_t; 67275970Scy# else 68275970Scytypedef unsigned char cc_t; 69275970Scy# endif 70275970Scy#endif 71275970Scy 72275970Scy#include <string.h> 73275970Scy 74275970Scy#if defined(IPSEC) 75275970Scy#include <netinet6/ipsec.h> 76275970Scy#if defined(IPSEC_POLICY_IPSEC) 77275970Scyextern char *ipsec_policy_in; 78275970Scyextern char *ipsec_policy_out; 79275970Scy#endif 80275970Scy#endif 81275970Scy 82275970Scy#ifndef _POSIX_VDISABLE 83275970Scy# ifdef sun 84275970Scy# include <sys/param.h> /* pick up VDISABLE definition, mayby */ 85275970Scy# endif 86275970Scy# ifdef VDISABLE 87275970Scy# define _POSIX_VDISABLE VDISABLE 88275970Scy# else 89275970Scy# define _POSIX_VDISABLE ((cc_t)'\377') 90275970Scy# endif 91275970Scy#endif 92275970Scy 93275970Scy#define SUBBUFSIZE 256 94275970Scy 95275970Scy#if !defined(P) 96275970Scy# ifdef __STDC__ 97275970Scy# define P(x) x 98275970Scy# else 99275970Scy# define P(x) () 100275970Scy# endif 101275970Scy#endif 102275970Scy 103275970Scyextern int 104275970Scy autologin, /* Autologin enabled */ 105275970Scy skiprc, /* Don't process the ~/.telnetrc file */ 106275970Scy eight, /* use eight bit mode (binary in and/or out */ 107275970Scy family, /* address family of peer */ 108275970Scy flushout, /* flush output */ 109275970Scy connected, /* Are we connected to the other side? */ 110275970Scy globalmode, /* Mode tty should be in */ 111275970Scy telnetport, /* Are we connected to the telnet port? */ 112275970Scy localflow, /* Flow control handled locally */ 113275970Scy restartany, /* If flow control, restart output on any character */ 114275970Scy localchars, /* we recognize interrupt/quit */ 115275970Scy donelclchars, /* the user has set "localchars" */ 116275970Scy showoptions, 117275970Scy net, /* Network file descriptor */ 118275970Scy tin, /* Terminal input file descriptor */ 119275970Scy tout, /* Terminal output file descriptor */ 120275970Scy crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */ 121275970Scy autoflush, /* flush output when interrupting? */ 122275970Scy autosynch, /* send interrupt characters with SYNCH? */ 123275970Scy SYNCHing, /* Is the stream in telnet SYNCH mode? */ 124275970Scy donebinarytoggle, /* the user has put us in binary */ 125275970Scy dontlecho, /* do we suppress local echoing right now? */ 126275970Scy crmod, 127275970Scy netdata, /* Print out network data flow */ 128275970Scy prettydump, /* Print "netdata" output in user readable format */ 129275970Scy termdata, /* Print out terminal data flow */ 130275970Scy telnet_debug, /* Debug level */ 131275970Scy doaddrlookup, /* do a reverse lookup? */ 132275970Scy clienteof; /* Client received EOF */ 133275970Scy 134275970Scyextern cc_t escape; /* Escape to command mode */ 135275970Scyextern cc_t rlogin; /* Rlogin mode escape character */ 136275970Scy#ifdef KLUDGELINEMODE 137275970Scyextern cc_t echoc; /* Toggle local echoing */ 138275970Scy#endif 139275970Scy 140275970Scyextern char 141275970Scy *prompt; /* Prompt for command. */ 142275970Scy 143275970Scyextern char 144275970Scy doopt[], 145275970Scy dont[], 146275970Scy will[], 147275970Scy wont[], 148275970Scy options[], /* All the little options */ 149275970Scy *hostname; /* Who are we connected to? */ 150275970Scy#ifdef ENCRYPTION 151275970Scyextern void (*encrypt_output)(unsigned char *, int); 152275970Scyextern int (*decrypt_input)(int); 153275970Scy#endif /* ENCRYPTION */ 154275970Scy 155275970Scy/* 156275970Scy * We keep track of each side of the option negotiation. 157275970Scy */ 158275970Scy 159275970Scy#define MY_STATE_WILL 0x01 160275970Scy#define MY_WANT_STATE_WILL 0x02 161275970Scy#define MY_STATE_DO 0x04 162275970Scy#define MY_WANT_STATE_DO 0x08 163275970Scy 164275970Scy/* 165275970Scy * Macros to check the current state of things 166275970Scy */ 167275970Scy 168275970Scy#define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 169275970Scy#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 170275970Scy#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 171275970Scy#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 172275970Scy 173275970Scy#define my_state_is_dont(opt) (!my_state_is_do(opt)) 174275970Scy#define my_state_is_wont(opt) (!my_state_is_will(opt)) 175275970Scy#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 176275970Scy#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 177275970Scy 178275970Scy#define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;} 179275970Scy#define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;} 180275970Scy#define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;} 181275970Scy#define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;} 182275970Scy 183275970Scy#define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;} 184275970Scy#define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;} 185275970Scy#define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;} 186275970Scy#define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;} 187275970Scy 188275970Scy/* 189275970Scy * Make everything symetrical 190275970Scy */ 191275970Scy 192275970Scy#define HIS_STATE_WILL MY_STATE_DO 193275970Scy#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 194275970Scy#define HIS_STATE_DO MY_STATE_WILL 195275970Scy#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 196275970Scy 197275970Scy#define his_state_is_do my_state_is_will 198275970Scy#define his_state_is_will my_state_is_do 199275970Scy#define his_want_state_is_do my_want_state_is_will 200275970Scy#define his_want_state_is_will my_want_state_is_do 201275970Scy 202275970Scy#define his_state_is_dont my_state_is_wont 203275970Scy#define his_state_is_wont my_state_is_dont 204275970Scy#define his_want_state_is_dont my_want_state_is_wont 205275970Scy#define his_want_state_is_wont my_want_state_is_dont 206275970Scy 207275970Scy#define set_his_state_do set_my_state_will 208275970Scy#define set_his_state_will set_my_state_do 209275970Scy#define set_his_want_state_do set_my_want_state_will 210275970Scy#define set_his_want_state_will set_my_want_state_do 211275970Scy 212275970Scy#define set_his_state_dont set_my_state_wont 213275970Scy#define set_his_state_wont set_my_state_dont 214275970Scy#define set_his_want_state_dont set_my_want_state_wont 215275970Scy#define set_his_want_state_wont set_my_want_state_dont 216275970Scy 217275970Scy#if defined(USE_TERMIO) 218275970Scy#define SIG_FUNC_RET void 219275970Scy#else 220275970Scy#define SIG_FUNC_RET int 221275970Scy#endif 222275970Scy 223275970Scy#ifdef SIGINFO 224275970Scyextern SIG_FUNC_RET 225275970Scy ayt_status(void); 226275970Scy#endif 227275970Scy 228275970Scyextern FILE 229275970Scy *NetTrace; /* Where debugging output goes */ 230275970Scyextern unsigned char 231275970Scy NetTraceFile[]; /* Name of file where debugging output goes */ 232275970Scyextern void 233275970Scy SetNetTrace(char *); /* Function to change where debugging goes */ 234275970Scy 235275970Scyextern jmp_buf 236275970Scy peerdied, 237275970Scy toplevel; /* For error conditions. */ 238275970Scy 239275970Scyextern void 240275970Scy command(int, const char *, int), 241275970Scy Dump(char, unsigned char *, int), 242275970Scy env_init(void), 243275970Scy Exit(int), 244275970Scy ExitString(const char *, int), 245275970Scy init_network(void), 246275970Scy init_sys(void), 247275970Scy init_telnet(void), 248275970Scy init_terminal(void), 249275970Scy intp(void), 250275970Scy optionstatus(void), 251275970Scy printoption(const char *, int, int), 252275970Scy printsub(char, unsigned char *, int), 253275970Scy quit(void), 254275970Scy sendabort(void), 255275970Scy sendbrk(void), 256275970Scy sendeof(void), 257275970Scy sendsusp(void), 258275970Scy sendnaws(void), 259275970Scy sendayt(void), 260275970Scy setconnmode(int), 261275970Scy setcommandmode(void), 262275970Scy set_escape_char(char *s), 263275970Scy setneturg(void), 264275970Scy sys_telnet_init(void), 265275970Scy telnet(char *), 266275970Scy tel_enter_binary(int), 267275970Scy tel_leave_binary(int), 268275970Scy TerminalFlushOutput(void), 269275970Scy TerminalNewMode(int), 270275970Scy TerminalRestoreState(void), 271275970Scy TerminalSaveState(void), 272275970Scy TerminalDefaultChars(void), 273275970Scy TerminalSpeeds(long *, long *), 274275970Scy tninit(void), 275275970Scy upcase(char *), 276275970Scy willoption(int), 277275970Scy wontoption(int); 278275970Scy 279275970Scyextern void 280275970Scy send_do(int, int), 281275970Scy send_dont(int, int), 282275970Scy send_will(int, int), 283275970Scy send_wont(int, int); 284275970Scy 285275970Scyextern void 286275970Scy lm_will(unsigned char *, int), 287275970Scy lm_wont(unsigned char *, int), 288275970Scy lm_do(unsigned char *, int), 289275970Scy lm_dont(unsigned char *, int), 290275970Scy lm_mode(unsigned char *, int, int); 291275970Scy 292275970Scyextern void 293275970Scy slc_init(void), 294275970Scy slcstate(void), 295275970Scy slc_mode_export(void), 296275970Scy slc_mode_import(int), 297275970Scy slc_import(int), 298275970Scy slc_export(void), 299275970Scy slc(unsigned char *, int), 300275970Scy slc_check(void), 301275970Scy slc_start_reply(void), 302275970Scy slc_add_reply(unsigned char, unsigned char, cc_t), 303275970Scy slc_end_reply(void); 304275970Scyextern int 305275970Scy getconnmode(void), 306275970Scy opt_welldefined(const char *), 307275970Scy NetClose(int), 308275970Scy netflush(void), 309275970Scy process_rings(int, int, int, int, int, int), 310275970Scy rlogin_susp(void), 311275970Scy SetSockOpt(int, int, int, int), 312275970Scy slc_update(void), 313275970Scy stilloob(void), 314275970Scy telrcv(void), 315275970Scy TerminalRead(char *, int), 316275970Scy TerminalWrite(char *, int), 317275970Scy TerminalAutoFlush(void), 318275970Scy TerminalWindowSize(long *, long *), 319275970Scy TerminalSpecialChars(int), 320275970Scy tn(int, char **), 321275970Scy ttyflush(int); 322275970Scy 323275970Scyextern void 324275970Scy env_opt(unsigned char *, int), 325275970Scy env_opt_start(void), 326275970Scy env_opt_start_info(void), 327275970Scy env_opt_add(unsigned char *), 328275970Scy env_opt_end(int); 329275970Scy 330275970Scyextern unsigned char 331275970Scy *env_default(int, int), 332275970Scy *env_getvalue(const unsigned char *); 333275970Scy 334275970Scyextern int 335275970Scy get_status(char *), 336275970Scy dosynch(char *); 337275970Scy 338275970Scyextern cc_t 339275970Scy *tcval(int); 340275970Scy 341275970Scy#ifndef USE_TERMIO 342275970Scy 343275970Scyextern struct tchars ntc; 344275970Scyextern struct ltchars nltc; 345275970Scyextern struct sgttyb nttyb; 346275970Scy 347275970Scy# define termEofChar ntc.t_eofc 348275970Scy# define termEraseChar nttyb.sg_erase 349275970Scy# define termFlushChar nltc.t_flushc 350275970Scy# define termIntChar ntc.t_intrc 351275970Scy# define termKillChar nttyb.sg_kill 352275970Scy# define termLiteralNextChar nltc.t_lnextc 353275970Scy# define termQuitChar ntc.t_quitc 354275970Scy# define termSuspChar nltc.t_suspc 355275970Scy# define termRprntChar nltc.t_rprntc 356275970Scy# define termWerasChar nltc.t_werasc 357275970Scy# define termStartChar ntc.t_startc 358275970Scy# define termStopChar ntc.t_stopc 359275970Scy# define termForw1Char ntc.t_brkc 360275970Scyextern cc_t termForw2Char; 361275970Scyextern cc_t termAytChar; 362275970Scy 363275970Scy# define termEofCharp (cc_t *)&ntc.t_eofc 364275970Scy# define termEraseCharp (cc_t *)&nttyb.sg_erase 365275970Scy# define termFlushCharp (cc_t *)&nltc.t_flushc 366275970Scy# define termIntCharp (cc_t *)&ntc.t_intrc 367275970Scy# define termKillCharp (cc_t *)&nttyb.sg_kill 368275970Scy# define termLiteralNextCharp (cc_t *)&nltc.t_lnextc 369275970Scy# define termQuitCharp (cc_t *)&ntc.t_quitc 370275970Scy# define termSuspCharp (cc_t *)&nltc.t_suspc 371275970Scy# define termRprntCharp (cc_t *)&nltc.t_rprntc 372275970Scy# define termWerasCharp (cc_t *)&nltc.t_werasc 373275970Scy# define termStartCharp (cc_t *)&ntc.t_startc 374275970Scy# define termStopCharp (cc_t *)&ntc.t_stopc 375275970Scy# define termForw1Charp (cc_t *)&ntc.t_brkc 376275970Scy# define termForw2Charp (cc_t *)&termForw2Char 377275970Scy# define termAytCharp (cc_t *)&termAytChar 378275970Scy 379275970Scy# else 380275970Scy 381275970Scyextern struct termio new_tc; 382275970Scy 383275970Scy# define termEofChar new_tc.c_cc[VEOF] 384275970Scy# define termEraseChar new_tc.c_cc[VERASE] 385275970Scy# define termIntChar new_tc.c_cc[VINTR] 386275970Scy# define termKillChar new_tc.c_cc[VKILL] 387275970Scy# define termQuitChar new_tc.c_cc[VQUIT] 388275970Scy 389275970Scy# ifndef VSUSP 390275970Scyextern cc_t termSuspChar; 391275970Scy# else 392275970Scy# define termSuspChar new_tc.c_cc[VSUSP] 393275970Scy# endif 394275970Scy# if defined(VFLUSHO) && !defined(VDISCARD) 395275970Scy# define VDISCARD VFLUSHO 396275970Scy# endif 397275970Scy# ifndef VDISCARD 398275970Scyextern cc_t termFlushChar; 399275970Scy# else 400275970Scy# define termFlushChar new_tc.c_cc[VDISCARD] 401275970Scy# endif 402275970Scy# ifndef VWERASE 403275970Scyextern cc_t termWerasChar; 404275970Scy# else 405275970Scy# define termWerasChar new_tc.c_cc[VWERASE] 406275970Scy# endif 407275970Scy# ifndef VREPRINT 408275970Scyextern cc_t termRprntChar; 409275970Scy# else 410275970Scy# define termRprntChar new_tc.c_cc[VREPRINT] 411275970Scy# endif 412275970Scy# ifndef VLNEXT 413275970Scyextern cc_t termLiteralNextChar; 414275970Scy# else 415275970Scy# define termLiteralNextChar new_tc.c_cc[VLNEXT] 416275970Scy# endif 417275970Scy# ifndef VSTART 418275970Scyextern cc_t termStartChar; 419275970Scy# else 420275970Scy# define termStartChar new_tc.c_cc[VSTART] 421275970Scy# endif 422275970Scy# ifndef VSTOP 423275970Scyextern cc_t termStopChar; 424275970Scy# else 425275970Scy# define termStopChar new_tc.c_cc[VSTOP] 426275970Scy# endif 427275970Scy# ifndef VEOL 428275970Scyextern cc_t termForw1Char; 429275970Scy# else 430275970Scy# define termForw1Char new_tc.c_cc[VEOL] 431275970Scy# endif 432275970Scy# ifndef VEOL2 433275970Scyextern cc_t termForw2Char; 434275970Scy# else 435275970Scy# define termForw2Char new_tc.c_cc[VEOL] 436275970Scy# endif 437275970Scy# ifndef VSTATUS 438275970Scyextern cc_t termAytChar; 439275970Scy#else 440275970Scy# define termAytChar new_tc.c_cc[VSTATUS] 441275970Scy#endif 442275970Scy 443275970Scy# if defined(__STDC__) 444275970Scy# define termEofCharp &termEofChar 445275970Scy# define termEraseCharp &termEraseChar 446275970Scy# define termIntCharp &termIntChar 447275970Scy# define termKillCharp &termKillChar 448275970Scy# define termQuitCharp &termQuitChar 449275970Scy# define termSuspCharp &termSuspChar 450275970Scy# define termFlushCharp &termFlushChar 451# define termWerasCharp &termWerasChar 452# define termRprntCharp &termRprntChar 453# define termLiteralNextCharp &termLiteralNextChar 454# define termStartCharp &termStartChar 455# define termStopCharp &termStopChar 456# define termForw1Charp &termForw1Char 457# define termForw2Charp &termForw2Char 458# define termAytCharp &termAytChar 459# else 460 /* Work around a compiler bug */ 461# define termEofCharp 0 462# define termEraseCharp 0 463# define termIntCharp 0 464# define termKillCharp 0 465# define termQuitCharp 0 466# define termSuspCharp 0 467# define termFlushCharp 0 468# define termWerasCharp 0 469# define termRprntCharp 0 470# define termLiteralNextCharp 0 471# define termStartCharp 0 472# define termStopCharp 0 473# define termForw1Charp 0 474# define termForw2Charp 0 475# define termAytCharp 0 476# endif 477#endif 478 479 480/* Ring buffer structures which are shared */ 481 482extern Ring 483 netoring, 484 netiring, 485 ttyoring, 486 ttyiring; 487 488extern void 489 xmitAO(void), 490 xmitEC(void), 491 xmitEL(void); 492