1 /* $NetBSD: externs.h,v 1.38 2016/10/04 14:35:38 joerg 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) 46 extern char *ipsec_policy_in; 47 extern 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 66 extern 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 102 extern cc_t escape; /* Escape to command mode */ 103 extern cc_t rlogin; /* Rlogin mode escape character */ 104 #ifdef KLUDGELINEMODE 105 extern cc_t echoc; /* Toggle local echoing */ 106 #endif 107 108 extern char 109 *prompt; /* Prompt for command. */ 110 111 extern 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 120 extern void (*encrypt_output)(unsigned char *, int); 121 extern 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 187 extern FILE 188 *NetTrace; /* Where debugging output goes */ 189 extern char 190 NetTraceFile[]; /* Name of file where debugging output goes */ 191 192 extern jmp_buf 193 toplevel; /* For error conditions. */ 194 195 196 /* authenc.c */ 197 int telnet_net_write(unsigned char *, int); 198 void net_encrypt(void); 199 int telnet_spin(void); 200 char *telnet_getenv(char *); 201 char *telnet_gets(char *, char *, int, int); 202 203 /* commands.c */ 204 int send_tncmd(void (*)(int, int), const char *, char *); 205 void _setlist_init(void); 206 void set_escape_char(char *); 207 int set_mode(int); 208 int clear_mode(int); 209 int modehelp(int); 210 int suspend(int, char *[]); 211 int shell(int, char *[]); 212 int quit(int, char *[]); 213 int logout(int, char *[]); 214 int env_cmd(int, char *[]); 215 struct env_lst *env_find(const unsigned char *); 216 void env_init(void); 217 struct env_lst *env_define(const unsigned char *, unsigned char *); 218 struct env_lst *env_undefine(const unsigned char *, unsigned char *); 219 struct env_lst *env_export(const unsigned char *, unsigned char *); 220 struct env_lst *env_unexport(const unsigned char *, unsigned char *); 221 struct env_lst *env_send(const unsigned char *, unsigned char *); 222 struct env_lst *env_list(const unsigned char *, unsigned char *); 223 unsigned char *env_default(int, int ); 224 unsigned char *env_getvalue(const unsigned char *); 225 void env_varval(const unsigned char *); 226 int auth_cmd(int, char *[]); 227 int ayt_status(void); 228 int encrypt_cmd(int, char *[]); 229 int tn(int, char *[]); 230 void command(int, const char *, int); 231 void cmdrc(const char *, const char *); 232 struct addrinfo; 233 234 /* main.c */ 235 void tninit(void); 236 void usage(void) __dead; 237 238 /* network.c */ 239 void init_network(void); 240 int stilloob(void); 241 void setneturg(void); 242 int netflush(void); 243 244 /* sys_bsd.c */ 245 void init_sys(void); 246 int TerminalWrite(char *, int); 247 int TerminalRead(unsigned char *, int); 248 int TerminalAutoFlush(void); 249 int TerminalSpecialChars(int); 250 void TerminalFlushOutput(void); 251 void TerminalSaveState(void); 252 cc_t *tcval(int); 253 void TerminalDefaultChars(void); 254 void TerminalRestoreState(void); 255 void TerminalNewMode(int); 256 void TerminalSpeeds(long *, long *); 257 int TerminalWindowSize(long *, long *); 258 int NetClose(int); 259 void NetNonblockingIO(int, int); 260 void NetSigIO(int, int); 261 void NetSetPgrp(int); 262 void sys_telnet_init(void); 263 int process_rings(int , int , int , int , int , int); 264 265 /* telnet.c */ 266 void init_telnet(void); 267 void send_do(int, int ); 268 void send_dont(int, int ); 269 void send_will(int, int ); 270 void send_wont(int, int ); 271 void willoption(int); 272 void wontoption(int); 273 char **mklist(char *, char *); 274 int is_unique(char *, char **, char **); 275 int setup_term(char *, int, int *); 276 char *gettermname(void); 277 void lm_will(unsigned char *, int); 278 void lm_wont(unsigned char *, int); 279 void lm_do(unsigned char *, int); 280 void lm_dont(unsigned char *, int); 281 void lm_mode(unsigned char *, int, int ); 282 void slc_init(void); 283 void slcstate(void); 284 void slc_mode_export(int); 285 void slc_mode_import(int); 286 void slc_import(int); 287 void slc_export(void); 288 void slc(unsigned char *, int); 289 void slc_check(void); 290 void slc_start_reply(void); 291 void slc_add_reply(unsigned int, unsigned int, cc_t); 292 void slc_end_reply(void); 293 int slc_update(void); 294 void env_opt(unsigned char *, int); 295 void env_opt_start(void); 296 void env_opt_start_info(void); 297 void env_opt_add(unsigned char *); 298 int opt_welldefined(const char *); 299 void env_opt_end(int); 300 int telrcv(void); 301 int rlogin_susp(void); 302 int Scheduler(int); 303 void telnet(const char *); 304 void xmitAO(void); 305 void xmitEL(void); 306 void xmitEC(void); 307 int dosynch(char *); 308 int get_status(char *); 309 void intp(void); 310 void sendbrk(void); 311 void sendabort(void); 312 void sendsusp(void); 313 void sendeof(void); 314 void sendayt(void); 315 void sendnaws(void); 316 void tel_enter_binary(int); 317 void tel_leave_binary(int); 318 319 /* terminal.c */ 320 void init_terminal(void); 321 int ttyflush(int); 322 int getconnmode(void); 323 void setconnmode(int); 324 void setcommandmode(void); 325 326 /* utilities.c */ 327 void upcase(char *); 328 int SetSockOpt(int, int, int, int); 329 void SetNetTrace(char *); 330 void Dump(int, unsigned char *, int); 331 void printoption(const char *, int, int ); 332 void optionstatus(void); 333 void printsub(int, unsigned char *, int); 334 void EmptyTerminal(void); 335 void SetForExit(void); 336 void Exit(int) __attribute__((__noreturn__)); 337 void ExitString(const char *, int) __attribute__((__noreturn__)); 338 339 340 extern struct termios new_tc; 341 342 # define termEofChar new_tc.c_cc[VEOF] 343 # define termEraseChar new_tc.c_cc[VERASE] 344 # define termIntChar new_tc.c_cc[VINTR] 345 # define termKillChar new_tc.c_cc[VKILL] 346 # define termQuitChar new_tc.c_cc[VQUIT] 347 348 # define termSuspChar new_tc.c_cc[VSUSP] 349 # define termFlushChar new_tc.c_cc[VDISCARD] 350 # define termWerasChar new_tc.c_cc[VWERASE] 351 # define termRprntChar new_tc.c_cc[VREPRINT] 352 # define termLiteralNextChar new_tc.c_cc[VLNEXT] 353 # define termStartChar new_tc.c_cc[VSTART] 354 # define termStopChar new_tc.c_cc[VSTOP] 355 # define termForw1Char new_tc.c_cc[VEOL] 356 # define termForw2Char new_tc.c_cc[VEOL] 357 # define termAytChar new_tc.c_cc[VSTATUS] 358 359 # define termEofCharp &termEofChar 360 # define termEraseCharp &termEraseChar 361 # define termIntCharp &termIntChar 362 # define termKillCharp &termKillChar 363 # define termQuitCharp &termQuitChar 364 # define termSuspCharp &termSuspChar 365 # define termFlushCharp &termFlushChar 366 # define termWerasCharp &termWerasChar 367 # define termRprntCharp &termRprntChar 368 # define termLiteralNextCharp &termLiteralNextChar 369 # define termStartCharp &termStartChar 370 # define termStopCharp &termStopChar 371 # define termForw1Charp &termForw1Char 372 # define termForw2Charp &termForw2Char 373 # define termAytCharp &termAytChar 374 375 376 /* Tn3270 section */ 377 #if defined(TN3270) 378 379 extern int 380 HaveInput, /* Whether an asynchronous I/O indication came in */ 381 noasynchtty, /* Don't do signals on I/O (SIGURG, SIGIO) */ 382 noasynchnet, /* Don't do signals on I/O (SIGURG, SIGIO) */ 383 sigiocount, /* Count of SIGIO receptions */ 384 shell_active; /* Subshell is active */ 385 386 extern char 387 *Ibackp, /* Oldest byte of 3270 data */ 388 Ibuf[], /* 3270 buffer */ 389 *Ifrontp, /* Where next 3270 byte goes */ 390 tline[200], 391 *transcom; /* Transparent command */ 392 393 /* tn3270.c */ 394 void init_3270(void); 395 int DataToNetwork(char *, int, int); 396 void inputAvailable(int); 397 void outputPurge(void); 398 int DataToTerminal(char *, int); 399 int Push3270(void); 400 void Finish3270(void); 401 void StringToTerminal(char *); 402 int _putchar(int); 403 void SetIn3270(void); 404 int tn3270_ttype(void); 405 int settranscom(int, char *[]); 406 int shell_continue(void); 407 int DataFromTerminal(char *, int); 408 int DataFromNetwork(char *, int, int); 409 void ConnectScreen(void); 410 int DoTerminalOutput(void); 411 412 #endif /* defined(TN3270) */ 413