1/* $NetBSD: externs.h,v 1.36 2012/01/09 16:08:55 christos Exp $ */ 2 3/* 4 * Copyright (c) 1988, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * from: @(#)externs.h 8.3 (Berkeley) 5/30/95 32 */ 33 34#include <stdio.h> 35#include <stdlib.h> 36#include <setjmp.h> 37#include <sys/ioctl.h> 38#include <errno.h> 39#include <sys/termios.h> 40 41#include <string.h> 42 43#if defined(IPSEC) 44#include <netipsec/ipsec.h> 45#if defined(IPSEC_POLICY_IPSEC) 46extern char *ipsec_policy_in; 47extern char *ipsec_policy_out; 48#endif 49#endif 50 51#ifndef _POSIX_VDISABLE 52# ifdef sun 53# include <sys/param.h> /* pick up VDISABLE definition, mayby */ 54# endif 55# ifdef VDISABLE 56# define _POSIX_VDISABLE VDISABLE 57# else 58# define _POSIX_VDISABLE ((cc_t)'\377') 59# endif 60#endif 61 62#define SUBBUFSIZE 256 63 64#include <sys/cdefs.h> 65 66extern int 67 autologin, /* Autologin enabled */ 68 skiprc, /* Don't process the ~/.telnetrc file */ 69 eight, /* use eight bit mode (binary in and/or out */ 70 family, /* address family of peer */ 71 flushout, /* flush output */ 72 connected, /* Are we connected to the other side? */ 73 globalmode, /* Mode tty should be in */ 74 In3270, /* Are we in 3270 mode? */ 75 telnetport, /* Are we connected to the telnet port? */ 76 localflow, /* Flow control handled locally */ 77 restartany, /* If flow control, restart output on any character */ 78 localchars, /* we recognize interrupt/quit */ 79 donelclchars, /* the user has set "localchars" */ 80 showoptions, 81 net, /* Network file descriptor */ 82 tin, /* Terminal input file descriptor */ 83 tout, /* Terminal output file descriptor */ 84 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */ 85 autoflush, /* flush output when interrupting? */ 86 autosynch, /* send interrupt characters with SYNCH? */ 87 SYNCHing, /* Is the stream in telnet SYNCH mode? */ 88 donebinarytoggle, /* the user has put us in binary */ 89 dontlecho, /* do we suppress local echoing right now? */ 90 crmod, 91 netdata, /* Print out network data flow */ 92 prettydump, /* Print "netdata" output in user readable format */ 93#ifdef TN3270 94 cursesdata, /* Print out curses data flow */ 95 apitrace, /* Trace API transactions */ 96#endif /* defined(TN3270) */ 97 termdata, /* Print out terminal data flow */ 98 telnet_debug, /* Debug level */ 99 doaddrlookup, /* do a reverse address lookup? */ 100 clienteof; /* Client received EOF */ 101 102extern cc_t escape; /* Escape to command mode */ 103extern cc_t rlogin; /* Rlogin mode escape character */ 104#ifdef KLUDGELINEMODE 105extern cc_t echoc; /* Toggle local echoing */ 106#endif 107 108extern char 109 *prompt; /* Prompt for command. */ 110 111extern char 112 doopt[], 113 dont[], 114 will[], 115 wont[], 116 options[], /* All the little options */ 117 *hostname; /* Who are we connected to? */ 118 119#ifdef ENCRYPTION 120extern void (*encrypt_output)(unsigned char *, int); 121extern int (*decrypt_input)(int); 122#endif /* ENCRYPTION */ 123 124/* 125 * We keep track of each side of the option negotiation. 126 */ 127 128#define MY_STATE_WILL 0x01 129#define MY_WANT_STATE_WILL 0x02 130#define MY_STATE_DO 0x04 131#define MY_WANT_STATE_DO 0x08 132 133/* 134 * Macros to check the current state of things 135 */ 136 137#define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 138#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 139#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 140#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 141 142#define my_state_is_dont(opt) (!my_state_is_do(opt)) 143#define my_state_is_wont(opt) (!my_state_is_will(opt)) 144#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 145#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 146 147#define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;} 148#define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;} 149#define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;} 150#define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;} 151 152#define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;} 153#define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;} 154#define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;} 155#define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;} 156 157/* 158 * Make everything symmetrical 159 */ 160 161#define HIS_STATE_WILL MY_STATE_DO 162#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 163#define HIS_STATE_DO MY_STATE_WILL 164#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 165 166#define his_state_is_do my_state_is_will 167#define his_state_is_will my_state_is_do 168#define his_want_state_is_do my_want_state_is_will 169#define his_want_state_is_will my_want_state_is_do 170 171#define his_state_is_dont my_state_is_wont 172#define his_state_is_wont my_state_is_dont 173#define his_want_state_is_dont my_want_state_is_wont 174#define his_want_state_is_wont my_want_state_is_dont 175 176#define set_his_state_do set_my_state_will 177#define set_his_state_will set_my_state_do 178#define set_his_want_state_do set_my_want_state_will 179#define set_his_want_state_will set_my_want_state_do 180 181#define set_his_state_dont set_my_state_wont 182#define set_his_state_wont set_my_state_dont 183#define set_his_want_state_dont set_my_want_state_wont 184#define set_his_want_state_wont set_my_want_state_dont 185 186 187extern FILE 188 *NetTrace; /* Where debugging output goes */ 189extern char 190 NetTraceFile[]; /* Name of file where debugging output goes */ 191 192extern jmp_buf 193 toplevel; /* For error conditions. */ 194 195 196/* authenc.c */ 197int telnet_net_write(unsigned char *, int); 198void net_encrypt(void); 199int telnet_spin(void); 200char *telnet_getenv(char *); 201char *telnet_gets(char *, char *, int, int); 202 203/* commands.c */ 204int send_tncmd(void (*)(int, int), const char *, char *); 205void _setlist_init(void); 206void set_escape_char(char *); 207int set_mode(int); 208int clear_mode(int); 209int modehelp(int); 210int suspend(int, char *[]); 211int shell(int, char *[]); 212int quit(int, char *[]); 213int logout(int, char *[]); 214int env_cmd(int, char *[]); 215struct env_lst *env_find(const unsigned char *); 216void env_init(void); 217struct env_lst *env_define(const unsigned char *, unsigned char *); 218struct env_lst *env_undefine(const unsigned char *, unsigned char *); 219struct env_lst *env_export(const unsigned char *, unsigned char *); 220struct env_lst *env_unexport(const unsigned char *, unsigned char *); 221struct env_lst *env_send(const unsigned char *, unsigned char *); 222struct env_lst *env_list(const unsigned char *, unsigned char *); 223unsigned char *env_default(int, int ); 224unsigned char *env_getvalue(const unsigned char *); 225void env_varval(const unsigned char *); 226int auth_cmd(int, char *[]); 227int ayt_status(void); 228int encrypt_cmd(int, char *[]); 229int tn(int, char *[]); 230void command(int, const char *, int); 231void cmdrc(const char *, const char *); 232struct addrinfo; 233int sourceroute(struct addrinfo *, char *, char **, int *, int*); 234 235/* main.c */ 236void tninit(void); 237void usage(void) __dead; 238 239/* network.c */ 240void init_network(void); 241int stilloob(void); 242void setneturg(void); 243int netflush(void); 244 245/* sys_bsd.c */ 246void init_sys(void); 247int TerminalWrite(char *, int); 248int TerminalRead(unsigned char *, int); 249int TerminalAutoFlush(void); 250int TerminalSpecialChars(int); 251void TerminalFlushOutput(void); 252void TerminalSaveState(void); 253cc_t *tcval(int); 254void TerminalDefaultChars(void); 255void TerminalRestoreState(void); 256void TerminalNewMode(int); 257void TerminalSpeeds(long *, long *); 258int TerminalWindowSize(long *, long *); 259int NetClose(int); 260void NetNonblockingIO(int, int); 261void NetSigIO(int, int); 262void NetSetPgrp(int); 263void sys_telnet_init(void); 264int process_rings(int , int , int , int , int , int); 265 266/* telnet.c */ 267void init_telnet(void); 268void send_do(int, int ); 269void send_dont(int, int ); 270void send_will(int, int ); 271void send_wont(int, int ); 272void willoption(int); 273void wontoption(int); 274char **mklist(char *, char *); 275int is_unique(char *, char **, char **); 276int setup_term(char *, int, int *); 277char *gettermname(void); 278void lm_will(unsigned char *, int); 279void lm_wont(unsigned char *, int); 280void lm_do(unsigned char *, int); 281void lm_dont(unsigned char *, int); 282void lm_mode(unsigned char *, int, int ); 283void slc_init(void); 284void slcstate(void); 285void slc_mode_export(int); 286void slc_mode_import(int); 287void slc_import(int); 288void slc_export(void); 289void slc(unsigned char *, int); 290void slc_check(void); 291void slc_start_reply(void); 292void slc_add_reply(unsigned int, unsigned int, cc_t); 293void slc_end_reply(void); 294int slc_update(void); 295void env_opt(unsigned char *, int); 296void env_opt_start(void); 297void env_opt_start_info(void); 298void env_opt_add(unsigned char *); 299int opt_welldefined(const char *); 300void env_opt_end(int); 301int telrcv(void); 302int rlogin_susp(void); 303int Scheduler(int); 304void telnet(const char *); 305void xmitAO(void); 306void xmitEL(void); 307void xmitEC(void); 308int dosynch(char *); 309int get_status(char *); 310void intp(void); 311void sendbrk(void); 312void sendabort(void); 313void sendsusp(void); 314void sendeof(void); 315void sendayt(void); 316void sendnaws(void); 317void tel_enter_binary(int); 318void tel_leave_binary(int); 319 320/* terminal.c */ 321void init_terminal(void); 322int ttyflush(int); 323int getconnmode(void); 324void setconnmode(int); 325void setcommandmode(void); 326 327/* utilities.c */ 328void upcase(char *); 329int SetSockOpt(int, int, int, int); 330void SetNetTrace(char *); 331void Dump(int, unsigned char *, int); 332void printoption(const char *, int, int ); 333void optionstatus(void); 334void printsub(int, unsigned char *, int); 335void EmptyTerminal(void); 336void SetForExit(void); 337void Exit(int) __attribute__((__noreturn__)); 338void ExitString(const char *, int) __attribute__((__noreturn__)); 339 340 341extern struct termios new_tc; 342 343# define termEofChar new_tc.c_cc[VEOF] 344# define termEraseChar new_tc.c_cc[VERASE] 345# define termIntChar new_tc.c_cc[VINTR] 346# define termKillChar new_tc.c_cc[VKILL] 347# define termQuitChar new_tc.c_cc[VQUIT] 348 349# define termSuspChar new_tc.c_cc[VSUSP] 350# define termFlushChar new_tc.c_cc[VDISCARD] 351# define termWerasChar new_tc.c_cc[VWERASE] 352# define termRprntChar new_tc.c_cc[VREPRINT] 353# define termLiteralNextChar new_tc.c_cc[VLNEXT] 354# define termStartChar new_tc.c_cc[VSTART] 355# define termStopChar new_tc.c_cc[VSTOP] 356# define termForw1Char new_tc.c_cc[VEOL] 357# define termForw2Char new_tc.c_cc[VEOL] 358# define termAytChar new_tc.c_cc[VSTATUS] 359 360# define termEofCharp &termEofChar 361# define termEraseCharp &termEraseChar 362# define termIntCharp &termIntChar 363# define termKillCharp &termKillChar 364# define termQuitCharp &termQuitChar 365# define termSuspCharp &termSuspChar 366# define termFlushCharp &termFlushChar 367# define termWerasCharp &termWerasChar 368# define termRprntCharp &termRprntChar 369# define termLiteralNextCharp &termLiteralNextChar 370# define termStartCharp &termStartChar 371# define termStopCharp &termStopChar 372# define termForw1Charp &termForw1Char 373# define termForw2Charp &termForw2Char 374# define termAytCharp &termAytChar 375 376 377/* Tn3270 section */ 378#if defined(TN3270) 379 380extern int 381 HaveInput, /* Whether an asynchronous I/O indication came in */ 382 noasynchtty, /* Don't do signals on I/O (SIGURG, SIGIO) */ 383 noasynchnet, /* Don't do signals on I/O (SIGURG, SIGIO) */ 384 sigiocount, /* Count of SIGIO receptions */ 385 shell_active; /* Subshell is active */ 386 387extern char 388 *Ibackp, /* Oldest byte of 3270 data */ 389 Ibuf[], /* 3270 buffer */ 390 *Ifrontp, /* Where next 3270 byte goes */ 391 tline[200], 392 *transcom; /* Transparent command */ 393 394/* tn3270.c */ 395void init_3270(void); 396int DataToNetwork(char *, int, int); 397void inputAvailable(int); 398void outputPurge(void); 399int DataToTerminal(char *, int); 400int Push3270(void); 401void Finish3270(void); 402void StringToTerminal(char *); 403int _putchar(int); 404void SetIn3270(void); 405int tn3270_ttype(void); 406int settranscom(int, char *[]); 407int shell_continue(void); 408int DataFromTerminal(char *, int); 409int DataFromNetwork(char *, int, int); 410void ConnectScreen(void); 411int DoTerminalOutput(void); 412 413#endif /* defined(TN3270) */ 414