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 */ 35 36/* $Id$ */ 37 38#ifndef BSD 39# define BSD 43 40#endif 41 42#ifndef _POSIX_VDISABLE 43# ifdef sun 44# include <sys/param.h> /* pick up VDISABLE definition, mayby */ 45# endif 46# ifdef VDISABLE 47# define _POSIX_VDISABLE VDISABLE 48# else 49# define _POSIX_VDISABLE ((cc_t)'\377') 50# endif 51#endif 52 53#define SUBBUFSIZE 256 54 55extern int 56 autologin, /* Autologin enabled */ 57 skiprc, /* Don't process the ~/.telnetrc file */ 58 eight, /* use eight bit mode (binary in and/or out */ 59 binary, 60 flushout, /* flush output */ 61 connected, /* Are we connected to the other side? */ 62 globalmode, /* Mode tty should be in */ 63 telnetport, /* Are we connected to the telnet port? */ 64 localflow, /* Flow control handled locally */ 65 restartany, /* If flow control, restart output on any character */ 66 localchars, /* we recognize interrupt/quit */ 67 donelclchars, /* the user has set "localchars" */ 68 showoptions, 69 wantencryption, /* User has requested encryption */ 70 net, /* Network file descriptor */ 71 tin, /* Terminal input file descriptor */ 72 tout, /* Terminal output file descriptor */ 73 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */ 74 autoflush, /* flush output when interrupting? */ 75 autosynch, /* send interrupt characters with SYNCH? */ 76 SYNCHing, /* Is the stream in telnet SYNCH mode? */ 77 donebinarytoggle, /* the user has put us in binary */ 78 dontlecho, /* do we suppress local echoing right now? */ 79 crmod, 80 netdata, /* Print out network data flow */ 81 prettydump, /* Print "netdata" output in user readable format */ 82 termdata, /* Print out terminal data flow */ 83 debug; /* Debug level */ 84 85extern int intr_happened, intr_waiting; /* for interrupt handling */ 86 87extern cc_t escape; /* Escape to command mode */ 88extern cc_t rlogin; /* Rlogin mode escape character */ 89#ifdef KLUDGELINEMODE 90extern cc_t echoc; /* Toggle local echoing */ 91#endif 92 93extern char 94 *prompt; /* Prompt for command. */ 95 96extern char 97 doopt[], 98 dont[], 99 will[], 100 wont[], 101 do_dont_resp[], 102 will_wont_resp[], 103 options[], /* All the little options */ 104 *hostname; /* Who are we connected to? */ 105#if defined(ENCRYPTION) 106extern void (*encrypt_output) (unsigned char *, int); 107extern int (*decrypt_input) (int); 108#endif 109 110/* 111 * We keep track of each side of the option negotiation. 112 */ 113 114#define MY_STATE_WILL 0x01 115#define MY_WANT_STATE_WILL 0x02 116#define MY_STATE_DO 0x04 117#define MY_WANT_STATE_DO 0x08 118 119/* 120 * Macros to check the current state of things 121 */ 122 123#define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 124#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 125#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 126#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 127 128#define my_state_is_dont(opt) (!my_state_is_do(opt)) 129#define my_state_is_wont(opt) (!my_state_is_will(opt)) 130#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 131#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 132 133#define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;} 134#define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;} 135#define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;} 136#define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;} 137 138#define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;} 139#define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;} 140#define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;} 141#define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;} 142 143/* 144 * Make everything symmetrical 145 */ 146 147#define HIS_STATE_WILL MY_STATE_DO 148#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 149#define HIS_STATE_DO MY_STATE_WILL 150#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 151 152#define his_state_is_do my_state_is_will 153#define his_state_is_will my_state_is_do 154#define his_want_state_is_do my_want_state_is_will 155#define his_want_state_is_will my_want_state_is_do 156 157#define his_state_is_dont my_state_is_wont 158#define his_state_is_wont my_state_is_dont 159#define his_want_state_is_dont my_want_state_is_wont 160#define his_want_state_is_wont my_want_state_is_dont 161 162#define set_his_state_do set_my_state_will 163#define set_his_state_will set_my_state_do 164#define set_his_want_state_do set_my_want_state_will 165#define set_his_want_state_will set_my_want_state_do 166 167#define set_his_state_dont set_my_state_wont 168#define set_his_state_wont set_my_state_dont 169#define set_his_want_state_dont set_my_want_state_wont 170#define set_his_want_state_wont set_my_want_state_dont 171 172 173extern FILE 174 *NetTrace; /* Where debugging output goes */ 175extern char 176 NetTraceFile[]; /* Name of file where debugging output goes */ 177extern void 178 SetNetTrace (char *); /* Function to change where debugging goes */ 179 180extern jmp_buf 181 peerdied, 182 toplevel; /* For error conditions. */ 183 184int Scheduler(int); 185extern int scheduler_lockout_tty; 186 187 188/* authenc.c */ 189 190#if defined(AUTHENTICATION) || defined(ENCRYPTION) 191int telnet_net_write(unsigned char *str, int len); 192void net_encrypt(void); 193int telnet_spin(void); 194char *telnet_getenv(const char *val); 195char *telnet_gets(char *prompt, char *result, int length, int echo); 196#endif 197 198/* commands.c */ 199 200struct env_lst *env_define (unsigned char *, unsigned char *); 201struct env_lst *env_find(unsigned char *var); 202void env_init (void); 203void env_undefine (unsigned char *); 204void env_export (unsigned char *); 205void env_unexport (unsigned char *); 206void env_send (unsigned char *); 207void env_list (void); 208unsigned char * env_default(int init, int welldefined); 209unsigned char * env_getvalue(unsigned char *var); 210 211void set_escape_char(char *s); 212int sourceroute(struct addrinfo *ai, char *arg, char **cpp, 213 int *prototp, int *optp); 214 215#if defined(AUTHENTICATION) 216int auth_enable (char *); 217int auth_disable (char *); 218int auth_status (void); 219#endif 220 221#if defined(ENCRYPTION) 222int EncryptEnable (char *, char *); 223int EncryptDisable (char *, char *); 224int EncryptType (char *, char *); 225int EncryptStart (char *); 226int EncryptStartInput (void); 227int EncryptStartOutput (void); 228int EncryptStop (char *); 229int EncryptStopInput (void); 230int EncryptStopOutput (void); 231int EncryptStatus (void); 232#endif 233 234#ifdef SIGINFO 235RETSIGTYPE ayt_status(int); 236#endif 237int tn(int argc, char **argv); 238void command(int top, char *tbuf, int cnt); 239 240/* main.c */ 241 242void tninit(void); 243void set_forward_options(void); 244 245/* network.c */ 246 247void init_network(void); 248int stilloob(void); 249void setneturg(void); 250int netflush(void); 251 252/* sys_bsd.c */ 253 254void init_sys(void); 255int TerminalWrite(char *buf, int n); 256int TerminalRead(unsigned char *buf, int n); 257int TerminalAutoFlush(void); 258int TerminalSpecialChars(int c); 259void TerminalFlushOutput(void); 260void TerminalSaveState(void); 261void TerminalDefaultChars(void); 262void TerminalNewMode(int f); 263cc_t *tcval(int func); 264void TerminalSpeeds(long *input_speed, long *output_speed); 265int TerminalWindowSize(long *rows, long *cols); 266int NetClose(int fd); 267void NetNonblockingIO(int fd, int onoff); 268int process_rings(int netin, int netout, int netex, int ttyin, int ttyout, 269 int poll); 270 271/* telnet.c */ 272 273void init_telnet(void); 274 275void tel_leave_binary(int rw); 276void tel_enter_binary(int rw); 277int opt_welldefined(char *ep); 278int telrcv(void); 279int rlogin_susp(void); 280void intp(void); 281void sendbrk(void); 282void sendabort(void); 283void sendsusp(void); 284void sendeof(void); 285void sendayt(void); 286 287void xmitAO(void); 288void xmitEL(void); 289void xmitEC(void); 290 291 292void Dump (char, unsigned char *, int); 293void printoption (char *, int, int); 294void sendnaws (void); 295void setconnmode (int); 296void setcommandmode (void); 297void setneturg (void); 298void sys_telnet_init (void); 299void my_telnet (char *); 300void tel_enter_binary (int); 301void TerminalFlushOutput (void); 302void TerminalNewMode (int); 303void TerminalRestoreState (void); 304void TerminalSaveState (void); 305void willoption (int); 306void wontoption (int); 307 308 309void send_do (int, int); 310void send_dont (int, int); 311void send_will (int, int); 312void send_wont (int, int); 313 314void lm_will (unsigned char *, int); 315void lm_wont (unsigned char *, int); 316void lm_do (unsigned char *, int); 317void lm_dont (unsigned char *, int); 318void lm_mode (unsigned char *, int, int); 319 320void slc_init (void); 321void slcstate (void); 322void slc_mode_export (void); 323void slc_mode_import (int); 324void slc_import (int); 325void slc_export (void); 326void slc (unsigned char *, int); 327void slc_check (void); 328void slc_start_reply (void); 329void slc_add_reply (unsigned char, unsigned char, cc_t); 330void slc_end_reply (void); 331int slc_update (void); 332 333void env_opt (unsigned char *, int); 334void env_opt_start (void); 335void env_opt_start_info (void); 336void env_opt_add (unsigned char *); 337void env_opt_end (int); 338 339unsigned char *env_default (int, int); 340unsigned char *env_getvalue (unsigned char *); 341 342int get_status (void); 343int dosynch (void); 344 345cc_t *tcval (int); 346 347int quit (void); 348 349/* terminal.c */ 350 351void init_terminal(void); 352int ttyflush(int drop); 353int getconnmode(void); 354 355/* utilities.c */ 356 357int SetSockOpt(int fd, int level, int option, int yesno); 358void SetNetTrace(char *file); 359void Dump(char direction, unsigned char *buffer, int length); 360void printoption(char *direction, int cmd, int option); 361void optionstatus(void); 362void printsub(int direction, unsigned char *pointer, size_t length); 363void EmptyTerminal(void); 364void SetForExit(void); 365void Exit(int returnCode); 366void ExitString(char *string, int returnCode); 367 368extern struct termios new_tc; 369 370# define termEofChar new_tc.c_cc[VEOF] 371# define termEraseChar new_tc.c_cc[VERASE] 372# define termIntChar new_tc.c_cc[VINTR] 373# define termKillChar new_tc.c_cc[VKILL] 374# define termQuitChar new_tc.c_cc[VQUIT] 375 376# ifndef VSUSP 377extern cc_t termSuspChar; 378# else 379# define termSuspChar new_tc.c_cc[VSUSP] 380# endif 381# if defined(VFLUSHO) && !defined(VDISCARD) 382# define VDISCARD VFLUSHO 383# endif 384# ifndef VDISCARD 385extern cc_t termFlushChar; 386# else 387# define termFlushChar new_tc.c_cc[VDISCARD] 388# endif 389# ifndef VWERASE 390extern cc_t termWerasChar; 391# else 392# define termWerasChar new_tc.c_cc[VWERASE] 393# endif 394# ifndef VREPRINT 395extern cc_t termRprntChar; 396# else 397# define termRprntChar new_tc.c_cc[VREPRINT] 398# endif 399# ifndef VLNEXT 400extern cc_t termLiteralNextChar; 401# else 402# define termLiteralNextChar new_tc.c_cc[VLNEXT] 403# endif 404# ifndef VSTART 405extern cc_t termStartChar; 406# else 407# define termStartChar new_tc.c_cc[VSTART] 408# endif 409# ifndef VSTOP 410extern cc_t termStopChar; 411# else 412# define termStopChar new_tc.c_cc[VSTOP] 413# endif 414# ifndef VEOL 415extern cc_t termForw1Char; 416# else 417# define termForw1Char new_tc.c_cc[VEOL] 418# endif 419# ifndef VEOL2 420extern cc_t termForw2Char; 421# else 422# define termForw2Char new_tc.c_cc[VEOL] 423# endif 424# ifndef VSTATUS 425extern cc_t termAytChar; 426#else 427# define termAytChar new_tc.c_cc[VSTATUS] 428#endif 429 430/* Ring buffer structures which are shared */ 431 432extern Ring 433 netoring, 434 netiring, 435 ttyoring, 436 ttyiring; 437 438extern int resettermname; 439extern int linemode; 440#ifdef KLUDGELINEMODE 441extern int kludgelinemode; 442#endif 443extern int want_status_response; 444