Home | History | Annotate | Line # | Download | only in telnet
externs.h revision 1.23
      1 /*	$NetBSD: externs.h,v 1.23 2002/06/14 00:30:56 wiz 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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	from: @(#)externs.h	8.3 (Berkeley) 5/30/95
     36  */
     37 
     38 #ifndef	BSD
     39 # define BSD 43
     40 #endif
     41 
     42 /*
     43  * ucb stdio.h defines BSD as something weird
     44  */
     45 #if defined(sun) && defined(__svr4__) && !defined(BSD)
     46 #define BSD 43
     47 #endif
     48 
     49 #ifndef	USE_TERMIO
     50 # if BSD > 43 || defined(SYSV_TERMIO)
     51 #  define USE_TERMIO
     52 # endif
     53 #endif
     54 
     55 #include <stdio.h>
     56 #include <stdlib.h>
     57 #include <setjmp.h>
     58 #if defined(CRAY) && !defined(NO_BSD_SETJMP)
     59 #include <bsdsetjmp.h>
     60 #endif
     61 #ifndef	FILIO_H
     62 #include <sys/ioctl.h>
     63 #else
     64 #include <sys/filio.h>
     65 #endif
     66 #include <errno.h>
     67 #ifdef	USE_TERMIO
     68 # ifndef	VINTR
     69 #  ifdef SYSV_TERMIO
     70 #   include <sys/termio.h>
     71 #  else
     72 #   include <sys/termios.h>
     73 #   define termio termios
     74 #  endif
     75 # else
     76 #  if defined(TCSANOW)
     77 #   define termio termios
     78 #  endif
     79 # endif
     80 #endif
     81 #if defined(NO_CC_T) || !defined(USE_TERMIO)
     82 # if !defined(USE_TERMIO)
     83 typedef char cc_t;
     84 # else
     85 typedef unsigned char cc_t;
     86 # endif
     87 #endif
     88 
     89 #ifndef	NO_STRING_H
     90 #include <string.h>
     91 #else
     92 #include <strings.h>
     93 #endif
     94 
     95 #if defined(IPSEC)
     96 #include <netinet6/ipsec.h>
     97 #if defined(IPSEC_POLICY_IPSEC)
     98 extern char *ipsec_policy_in;
     99 extern char *ipsec_policy_out;
    100 #endif
    101 #endif
    102 
    103 #ifndef	_POSIX_VDISABLE
    104 # ifdef sun
    105 #  include <sys/param.h>	/* pick up VDISABLE definition, mayby */
    106 # endif
    107 # ifdef VDISABLE
    108 #  define _POSIX_VDISABLE VDISABLE
    109 # else
    110 #  define _POSIX_VDISABLE ((cc_t)'\377')
    111 # endif
    112 #endif
    113 
    114 #define	SUBBUFSIZE	256
    115 
    116 #include <sys/cdefs.h>
    117 
    118 extern int
    119     autologin,		/* Autologin enabled */
    120     skiprc,		/* Don't process the ~/.telnetrc file */
    121     eight,		/* use eight bit mode (binary in and/or out */
    122     flushout,		/* flush output */
    123     connected,		/* Are we connected to the other side? */
    124     globalmode,		/* Mode tty should be in */
    125     In3270,		/* Are we in 3270 mode? */
    126     telnetport,		/* Are we connected to the telnet port? */
    127     localflow,		/* Flow control handled locally */
    128     restartany,		/* If flow control, restart output on any character */
    129     localchars,		/* we recognize interrupt/quit */
    130     donelclchars,	/* the user has set "localchars" */
    131     showoptions,
    132     net,		/* Network file descriptor */
    133     tin,		/* Terminal input file descriptor */
    134     tout,		/* Terminal output file descriptor */
    135     crlf,		/* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
    136     autoflush,		/* flush output when interrupting? */
    137     autosynch,		/* send interrupt characters with SYNCH? */
    138     SYNCHing,		/* Is the stream in telnet SYNCH mode? */
    139     donebinarytoggle,	/* the user has put us in binary */
    140     dontlecho,		/* do we suppress local echoing right now? */
    141     crmod,
    142     netdata,		/* Print out network data flow */
    143     prettydump,		/* Print "netdata" output in user readable format */
    144 #if	defined(unix)
    145 #if	defined(TN3270)
    146     cursesdata,		/* Print out curses data flow */
    147     apitrace,		/* Trace API transactions */
    148 #endif	/* defined(TN3270) */
    149     termdata,		/* Print out terminal data flow */
    150 #endif	/* defined(unix) */
    151     debug,		/* Debug level */
    152     doaddrlookup,	/* do a reverse address lookup? */
    153     clienteof;		/* Client received EOF */
    154 
    155 extern cc_t escape;	/* Escape to command mode */
    156 extern cc_t rlogin;	/* Rlogin mode escape character */
    157 #ifdef	KLUDGELINEMODE
    158 extern cc_t echoc;	/* Toggle local echoing */
    159 #endif
    160 
    161 extern char
    162     *prompt;		/* Prompt for command. */
    163 
    164 extern char
    165     doopt[],
    166     dont[],
    167     will[],
    168     wont[],
    169     options[],		/* All the little options */
    170     *hostname;		/* Who are we connected to? */
    171 
    172 #ifdef	ENCRYPTION
    173 extern void (*encrypt_output)(unsigned char *, int);
    174 extern int (*decrypt_input)(int);
    175 #endif	/* ENCRYPTION */
    176 
    177 /*
    178  * We keep track of each side of the option negotiation.
    179  */
    180 
    181 #define	MY_STATE_WILL		0x01
    182 #define	MY_WANT_STATE_WILL	0x02
    183 #define	MY_STATE_DO		0x04
    184 #define	MY_WANT_STATE_DO	0x08
    185 
    186 /*
    187  * Macros to check the current state of things
    188  */
    189 
    190 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
    191 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
    192 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
    193 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
    194 
    195 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
    196 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
    197 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
    198 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
    199 
    200 #define	set_my_state_do(opt)		{options[opt] |= MY_STATE_DO;}
    201 #define	set_my_state_will(opt)		{options[opt] |= MY_STATE_WILL;}
    202 #define	set_my_want_state_do(opt)	{options[opt] |= MY_WANT_STATE_DO;}
    203 #define	set_my_want_state_will(opt)	{options[opt] |= MY_WANT_STATE_WILL;}
    204 
    205 #define	set_my_state_dont(opt)		{options[opt] &= ~MY_STATE_DO;}
    206 #define	set_my_state_wont(opt)		{options[opt] &= ~MY_STATE_WILL;}
    207 #define	set_my_want_state_dont(opt)	{options[opt] &= ~MY_WANT_STATE_DO;}
    208 #define	set_my_want_state_wont(opt)	{options[opt] &= ~MY_WANT_STATE_WILL;}
    209 
    210 /*
    211  * Make everything symmetrical
    212  */
    213 
    214 #define	HIS_STATE_WILL			MY_STATE_DO
    215 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
    216 #define HIS_STATE_DO			MY_STATE_WILL
    217 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
    218 
    219 #define	his_state_is_do			my_state_is_will
    220 #define	his_state_is_will		my_state_is_do
    221 #define his_want_state_is_do		my_want_state_is_will
    222 #define his_want_state_is_will		my_want_state_is_do
    223 
    224 #define	his_state_is_dont		my_state_is_wont
    225 #define	his_state_is_wont		my_state_is_dont
    226 #define his_want_state_is_dont		my_want_state_is_wont
    227 #define his_want_state_is_wont		my_want_state_is_dont
    228 
    229 #define	set_his_state_do		set_my_state_will
    230 #define	set_his_state_will		set_my_state_do
    231 #define	set_his_want_state_do		set_my_want_state_will
    232 #define	set_his_want_state_will		set_my_want_state_do
    233 
    234 #define	set_his_state_dont		set_my_state_wont
    235 #define	set_his_state_wont		set_my_state_dont
    236 #define	set_his_want_state_dont		set_my_want_state_wont
    237 #define	set_his_want_state_wont		set_my_want_state_dont
    238 
    239 
    240 extern FILE
    241     *NetTrace;		/* Where debugging output goes */
    242 extern unsigned char
    243     NetTraceFile[];	/* Name of file where debugging output goes */
    244 
    245 extern jmp_buf
    246     peerdied,
    247     toplevel;		/* For error conditions. */
    248 
    249 
    250 /* authenc.c */
    251 int telnet_net_write(unsigned char *, int);
    252 void net_encrypt(void);
    253 int telnet_spin(void);
    254 char *telnet_getenv(char *);
    255 char *telnet_gets(char *, char *, int, int);
    256 
    257 /* commands.c */
    258 int send_tncmd(void (*)(int, int), char *, char *);
    259 void _setlist_init(void);
    260 void set_escape_char(char *);
    261 int set_mode(int);
    262 int clear_mode(int);
    263 int modehelp(int);
    264 int suspend(int, char *[]);
    265 int shell(int, char *[]);
    266 int quit(int, char *[]);
    267 int logout(int, char *[]);
    268 int env_cmd(int, char *[]);
    269 struct env_lst *env_find(unsigned char *);
    270 void env_init(void);
    271 struct env_lst *env_define(unsigned char *, unsigned char *);
    272 struct env_lst *env_undefine(unsigned char *, unsigned char *);
    273 struct env_lst *env_export(unsigned char *, unsigned char *);
    274 struct env_lst *env_unexport(unsigned char *, unsigned char *);
    275 struct env_lst *env_send(unsigned char *, unsigned char *);
    276 struct env_lst *env_list(unsigned char *, unsigned char *);
    277 unsigned char *env_default(int, int );
    278 unsigned char *env_getvalue(unsigned char *);
    279 void env_varval(unsigned char *);
    280 int auth_cmd(int, char *[]);
    281 int ayt_status(void);
    282 int encrypt_cmd(int, char *[]);
    283 int tn(int, char *[]);
    284 void command(int, char *, int);
    285 void cmdrc(const char *, const char *);
    286 struct addrinfo;
    287 int sourceroute(struct addrinfo *, char *, char **, int *, int*);
    288 
    289 /* main.c */
    290 void tninit(void);
    291 void usage(void);
    292 
    293 /* network.c */
    294 void init_network(void);
    295 int stilloob(void);
    296 void setneturg(void);
    297 int netflush(void);
    298 
    299 /* sys_bsd.c */
    300 void init_sys(void);
    301 int TerminalWrite(char *, int);
    302 int TerminalRead(unsigned char *, int);
    303 int TerminalAutoFlush(void);
    304 int TerminalSpecialChars(int);
    305 void TerminalFlushOutput(void);
    306 void TerminalSaveState(void);
    307 cc_t *tcval(int);
    308 void TerminalDefaultChars(void);
    309 void TerminalRestoreState(void);
    310 void TerminalNewMode(int);
    311 void TerminalSpeeds(long *, long *);
    312 int TerminalWindowSize(long *, long *);
    313 int NetClose(int);
    314 void NetNonblockingIO(int, int);
    315 void NetSigIO(int, int);
    316 void NetSetPgrp(int);
    317 void sys_telnet_init(void);
    318 int process_rings(int , int , int , int , int , int);
    319 
    320 /* telnet.c */
    321 void init_telnet(void);
    322 void send_do(int, int );
    323 void send_dont(int, int );
    324 void send_will(int, int );
    325 void send_wont(int, int );
    326 void willoption(int);
    327 void wontoption(int);
    328 char **mklist(char *, char *);
    329 int is_unique(char *, char **, char **);
    330 int setup_term(char *, int, int *);
    331 char *gettermname(void);
    332 void lm_will(unsigned char *, int);
    333 void lm_wont(unsigned char *, int);
    334 void lm_do(unsigned char *, int);
    335 void lm_dont(unsigned char *, int);
    336 void lm_mode(unsigned char *, int, int );
    337 void slc_init(void);
    338 void slcstate(void);
    339 void slc_mode_export(int);
    340 void slc_mode_import(int);
    341 void slc_import(int);
    342 void slc_export(void);
    343 void slc(unsigned char *, int);
    344 void slc_check(void);
    345 void slc_start_reply(void);
    346 void slc_add_reply(unsigned int, unsigned int, cc_t);
    347 void slc_end_reply(void);
    348 int slc_update(void);
    349 void env_opt(unsigned char *, int);
    350 void env_opt_start(void);
    351 void env_opt_start_info(void);
    352 void env_opt_add(unsigned char *);
    353 int opt_welldefined(char *);
    354 void env_opt_end(int);
    355 int telrcv(void);
    356 int rlogin_susp(void);
    357 int Scheduler(int);
    358 void telnet(const char *);
    359 void xmitAO(void);
    360 void xmitEL(void);
    361 void xmitEC(void);
    362 int dosynch(char *);
    363 int get_status(char *);
    364 void intp(void);
    365 void sendbrk(void);
    366 void sendabort(void);
    367 void sendsusp(void);
    368 void sendeof(void);
    369 void sendayt(void);
    370 void sendnaws(void);
    371 void tel_enter_binary(int);
    372 void tel_leave_binary(int);
    373 
    374 /* terminal.c */
    375 void init_terminal(void);
    376 int ttyflush(int);
    377 int getconnmode(void);
    378 void setconnmode(int);
    379 void setcommandmode(void);
    380 
    381 /* utilities.c */
    382 void upcase(char *);
    383 int SetSockOpt(int, int , int , int );
    384 void SetNetTrace(char *);
    385 void Dump(int, unsigned char *, int);
    386 void printoption(char *, int, int );
    387 void optionstatus(void);
    388 void printsub(int, unsigned char *, int);
    389 void EmptyTerminal(void);
    390 void SetForExit(void);
    391 void Exit(int) __attribute__((__noreturn__));
    392 void ExitString(char *, int) __attribute__((__noreturn__));
    393 
    394 #ifndef	USE_TERMIO
    395 
    396 extern struct	tchars ntc;
    397 extern struct	ltchars nltc;
    398 extern struct	sgttyb nttyb;
    399 
    400 # define termEofChar		ntc.t_eofc
    401 # define termEraseChar		nttyb.sg_erase
    402 # define termFlushChar		nltc.t_flushc
    403 # define termIntChar		ntc.t_intrc
    404 # define termKillChar		nttyb.sg_kill
    405 # define termLiteralNextChar	nltc.t_lnextc
    406 # define termQuitChar		ntc.t_quitc
    407 # define termSuspChar		nltc.t_suspc
    408 # define termRprntChar		nltc.t_rprntc
    409 # define termWerasChar		nltc.t_werasc
    410 # define termStartChar		ntc.t_startc
    411 # define termStopChar		ntc.t_stopc
    412 # define termForw1Char		ntc.t_brkc
    413 extern cc_t termForw2Char;
    414 extern cc_t termAytChar;
    415 
    416 # define termEofCharp		(cc_t *)&ntc.t_eofc
    417 # define termEraseCharp		(cc_t *)&nttyb.sg_erase
    418 # define termFlushCharp		(cc_t *)&nltc.t_flushc
    419 # define termIntCharp		(cc_t *)&ntc.t_intrc
    420 # define termKillCharp		(cc_t *)&nttyb.sg_kill
    421 # define termLiteralNextCharp	(cc_t *)&nltc.t_lnextc
    422 # define termQuitCharp		(cc_t *)&ntc.t_quitc
    423 # define termSuspCharp		(cc_t *)&nltc.t_suspc
    424 # define termRprntCharp		(cc_t *)&nltc.t_rprntc
    425 # define termWerasCharp		(cc_t *)&nltc.t_werasc
    426 # define termStartCharp		(cc_t *)&ntc.t_startc
    427 # define termStopCharp		(cc_t *)&ntc.t_stopc
    428 # define termForw1Charp		(cc_t *)&ntc.t_brkc
    429 # define termForw2Charp		(cc_t *)&termForw2Char
    430 # define termAytCharp		(cc_t *)&termAytChar
    431 
    432 # else
    433 
    434 extern struct	termio new_tc;
    435 
    436 # define termEofChar		new_tc.c_cc[VEOF]
    437 # define termEraseChar		new_tc.c_cc[VERASE]
    438 # define termIntChar		new_tc.c_cc[VINTR]
    439 # define termKillChar		new_tc.c_cc[VKILL]
    440 # define termQuitChar		new_tc.c_cc[VQUIT]
    441 
    442 # ifndef	VSUSP
    443 extern cc_t termSuspChar;
    444 # else
    445 #  define termSuspChar		new_tc.c_cc[VSUSP]
    446 # endif
    447 # if	defined(VFLUSHO) && !defined(VDISCARD)
    448 #  define VDISCARD VFLUSHO
    449 # endif
    450 # ifndef	VDISCARD
    451 extern cc_t termFlushChar;
    452 # else
    453 #  define termFlushChar		new_tc.c_cc[VDISCARD]
    454 # endif
    455 # ifndef VWERASE
    456 extern cc_t termWerasChar;
    457 # else
    458 #  define termWerasChar		new_tc.c_cc[VWERASE]
    459 # endif
    460 # ifndef	VREPRINT
    461 extern cc_t termRprntChar;
    462 # else
    463 #  define termRprntChar		new_tc.c_cc[VREPRINT]
    464 # endif
    465 # ifndef	VLNEXT
    466 extern cc_t termLiteralNextChar;
    467 # else
    468 #  define termLiteralNextChar	new_tc.c_cc[VLNEXT]
    469 # endif
    470 # ifndef	VSTART
    471 extern cc_t termStartChar;
    472 # else
    473 #  define termStartChar		new_tc.c_cc[VSTART]
    474 # endif
    475 # ifndef	VSTOP
    476 extern cc_t termStopChar;
    477 # else
    478 #  define termStopChar		new_tc.c_cc[VSTOP]
    479 # endif
    480 # ifndef	VEOL
    481 extern cc_t termForw1Char;
    482 # else
    483 #  define termForw1Char		new_tc.c_cc[VEOL]
    484 # endif
    485 # ifndef	VEOL2
    486 extern cc_t termForw2Char;
    487 # else
    488 #  define termForw2Char		new_tc.c_cc[VEOL]
    489 # endif
    490 # ifndef	VSTATUS
    491 extern cc_t termAytChar;
    492 #else
    493 #  define termAytChar		new_tc.c_cc[VSTATUS]
    494 #endif
    495 
    496 # define termEofCharp		&termEofChar
    497 # define termEraseCharp		&termEraseChar
    498 # define termIntCharp		&termIntChar
    499 # define termKillCharp		&termKillChar
    500 # define termQuitCharp		&termQuitChar
    501 # define termSuspCharp		&termSuspChar
    502 # define termFlushCharp		&termFlushChar
    503 # define termWerasCharp		&termWerasChar
    504 # define termRprntCharp		&termRprntChar
    505 # define termLiteralNextCharp	&termLiteralNextChar
    506 # define termStartCharp		&termStartChar
    507 # define termStopCharp		&termStopChar
    508 # define termForw1Charp		&termForw1Char
    509 # define termForw2Charp		&termForw2Char
    510 # define termAytCharp		&termAytChar
    511 #endif
    512 
    513 
    514 /* Tn3270 section */
    515 #if	defined(TN3270)
    516 
    517 extern int
    518     HaveInput,		/* Whether an asynchronous I/O indication came in */
    519     noasynchtty,	/* Don't do signals on I/O (SIGURG, SIGIO) */
    520     noasynchnet,	/* Don't do signals on I/O (SIGURG, SIGIO) */
    521     sigiocount,		/* Count of SIGIO receptions */
    522     shell_active;	/* Subshell is active */
    523 
    524 extern char
    525     *Ibackp,		/* Oldest byte of 3270 data */
    526     Ibuf[],		/* 3270 buffer */
    527     *Ifrontp,		/* Where next 3270 byte goes */
    528     tline[200],
    529     *transcom;		/* Transparent command */
    530 
    531 /* tn3270.c */
    532 void init_3270(void);
    533 int DataToNetwork(char *, int, int);
    534 void inputAvailable(int);
    535 void outputPurge(void);
    536 int DataToTerminal(char *, int);
    537 int Push3270(void);
    538 void Finish3270(void);
    539 void StringToTerminal(char *);
    540 void _putchar(int);
    541 void SetIn3270(void);
    542 int tn3270_ttype(void);
    543 int settranscom(int, char *[]);
    544 int shell_continue(void);
    545 int DataFromTerminal __(char *, int);
    546 int DataFromNetwork __(char *, int, int);
    547 void ConnectScreen __(void);
    548 int DoTerminalOutput __(void);
    549 
    550 #endif	/* defined(TN3270) */
    551