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: externs.h 21734 2007-07-31 01:55:45Z lha $ */ 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 printsub (int, unsigned char *, int); 295void sendnaws (void); 296void setconnmode (int); 297void setcommandmode (void); 298void setneturg (void); 299void sys_telnet_init (void); 300void my_telnet (char *); 301void tel_enter_binary (int); 302void TerminalFlushOutput (void); 303void TerminalNewMode (int); 304void TerminalRestoreState (void); 305void TerminalSaveState (void); 306void willoption (int); 307void wontoption (int); 308 309 310void send_do (int, int); 311void send_dont (int, int); 312void send_will (int, int); 313void send_wont (int, int); 314 315void lm_will (unsigned char *, int); 316void lm_wont (unsigned char *, int); 317void lm_do (unsigned char *, int); 318void lm_dont (unsigned char *, int); 319void lm_mode (unsigned char *, int, int); 320 321void slc_init (void); 322void slcstate (void); 323void slc_mode_export (void); 324void slc_mode_import (int); 325void slc_import (int); 326void slc_export (void); 327void slc (unsigned char *, int); 328void slc_check (void); 329void slc_start_reply (void); 330void slc_add_reply (unsigned char, unsigned char, cc_t); 331void slc_end_reply (void); 332int slc_update (void); 333 334void env_opt (unsigned char *, int); 335void env_opt_start (void); 336void env_opt_start_info (void); 337void env_opt_add (unsigned char *); 338void env_opt_end (int); 339 340unsigned char *env_default (int, int); 341unsigned char *env_getvalue (unsigned char *); 342 343int get_status (void); 344int dosynch (void); 345 346cc_t *tcval (int); 347 348int quit (void); 349 350/* terminal.c */ 351 352void init_terminal(void); 353int ttyflush(int drop); 354int getconnmode(void); 355 356/* utilities.c */ 357 358int SetSockOpt(int fd, int level, int option, int yesno); 359void SetNetTrace(char *file); 360void Dump(char direction, unsigned char *buffer, int length); 361void printoption(char *direction, int cmd, int option); 362void optionstatus(void); 363void printsub(int direction, unsigned char *pointer, int length); 364void EmptyTerminal(void); 365void SetForExit(void); 366void Exit(int returnCode); 367void ExitString(char *string, int returnCode); 368 369extern struct termios new_tc; 370 371# define termEofChar new_tc.c_cc[VEOF] 372# define termEraseChar new_tc.c_cc[VERASE] 373# define termIntChar new_tc.c_cc[VINTR] 374# define termKillChar new_tc.c_cc[VKILL] 375# define termQuitChar new_tc.c_cc[VQUIT] 376 377# ifndef VSUSP 378extern cc_t termSuspChar; 379# else 380# define termSuspChar new_tc.c_cc[VSUSP] 381# endif 382# if defined(VFLUSHO) && !defined(VDISCARD) 383# define VDISCARD VFLUSHO 384# endif 385# ifndef VDISCARD 386extern cc_t termFlushChar; 387# else 388# define termFlushChar new_tc.c_cc[VDISCARD] 389# endif 390# ifndef VWERASE 391extern cc_t termWerasChar; 392# else 393# define termWerasChar new_tc.c_cc[VWERASE] 394# endif 395# ifndef VREPRINT 396extern cc_t termRprntChar; 397# else 398# define termRprntChar new_tc.c_cc[VREPRINT] 399# endif 400# ifndef VLNEXT 401extern cc_t termLiteralNextChar; 402# else 403# define termLiteralNextChar new_tc.c_cc[VLNEXT] 404# endif 405# ifndef VSTART 406extern cc_t termStartChar; 407# else 408# define termStartChar new_tc.c_cc[VSTART] 409# endif 410# ifndef VSTOP 411extern cc_t termStopChar; 412# else 413# define termStopChar new_tc.c_cc[VSTOP] 414# endif 415# ifndef VEOL 416extern cc_t termForw1Char; 417# else 418# define termForw1Char new_tc.c_cc[VEOL] 419# endif 420# ifndef VEOL2 421extern cc_t termForw2Char; 422# else 423# define termForw2Char new_tc.c_cc[VEOL] 424# endif 425# ifndef VSTATUS 426extern cc_t termAytChar; 427#else 428# define termAytChar new_tc.c_cc[VSTATUS] 429#endif 430 431/* Ring buffer structures which are shared */ 432 433extern Ring 434 netoring, 435 netiring, 436 ttyoring, 437 ttyiring; 438 439extern int resettermname; 440extern int linemode; 441#ifdef KLUDGELINEMODE 442extern int kludgelinemode; 443#endif 444extern int want_status_response; 445