Home | History | Annotate | Line # | Download | only in telnet
externs.h revision 1.21
      1 /*	$NetBSD: externs.h,v 1.21 2001/06/18 11:23:01 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 wierd
     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 #define P __P
    118 
    119 extern int
    120     autologin,		/* Autologin enabled */
    121     skiprc,		/* Don't process the ~/.telnetrc file */
    122     eight,		/* use eight bit mode (binary in and/or out */
    123     flushout,		/* flush output */
    124     connected,		/* Are we connected to the other side? */
    125     globalmode,		/* Mode tty should be in */
    126     In3270,		/* Are we in 3270 mode? */
    127     telnetport,		/* Are we connected to the telnet port? */
    128     localflow,		/* Flow control handled locally */
    129     restartany,		/* If flow control, restart output on any character */
    130     localchars,		/* we recognize interrupt/quit */
    131     donelclchars,	/* the user has set "localchars" */
    132     showoptions,
    133     net,		/* Network file descriptor */
    134     tin,		/* Terminal input file descriptor */
    135     tout,		/* Terminal output file descriptor */
    136     crlf,		/* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
    137     autoflush,		/* flush output when interrupting? */
    138     autosynch,		/* send interrupt characters with SYNCH? */
    139     SYNCHing,		/* Is the stream in telnet SYNCH mode? */
    140     donebinarytoggle,	/* the user has put us in binary */
    141     dontlecho,		/* do we suppress local echoing right now? */
    142     crmod,
    143     netdata,		/* Print out network data flow */
    144     prettydump,		/* Print "netdata" output in user readable format */
    145 #if	defined(unix)
    146 #if	defined(TN3270)
    147     cursesdata,		/* Print out curses data flow */
    148     apitrace,		/* Trace API transactions */
    149 #endif	/* defined(TN3270) */
    150     termdata,		/* Print out terminal data flow */
    151 #endif	/* defined(unix) */
    152     debug,		/* Debug level */
    153     doaddrlookup,	/* do a reverse address lookup? */
    154     clienteof;		/* Client received EOF */
    155 
    156 extern cc_t escape;	/* Escape to command mode */
    157 extern cc_t rlogin;	/* Rlogin mode escape character */
    158 #ifdef	KLUDGELINEMODE
    159 extern cc_t echoc;	/* Toggle local echoing */
    160 #endif
    161 
    162 extern char
    163     *prompt;		/* Prompt for command. */
    164 
    165 extern char
    166     doopt[],
    167     dont[],
    168     will[],
    169     wont[],
    170     options[],		/* All the little options */
    171     *hostname;		/* Who are we connected to? */
    172 
    173 #ifdef	ENCRYPTION
    174 extern void (*encrypt_output) P((unsigned char *, int));
    175 extern int (*decrypt_input) P((int));
    176 #endif	/* ENCRYPTION */
    177 
    178 /*
    179  * We keep track of each side of the option negotiation.
    180  */
    181 
    182 #define	MY_STATE_WILL		0x01
    183 #define	MY_WANT_STATE_WILL	0x02
    184 #define	MY_STATE_DO		0x04
    185 #define	MY_WANT_STATE_DO	0x08
    186 
    187 /*
    188  * Macros to check the current state of things
    189  */
    190 
    191 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
    192 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
    193 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
    194 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
    195 
    196 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
    197 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
    198 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
    199 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
    200 
    201 #define	set_my_state_do(opt)		{options[opt] |= MY_STATE_DO;}
    202 #define	set_my_state_will(opt)		{options[opt] |= MY_STATE_WILL;}
    203 #define	set_my_want_state_do(opt)	{options[opt] |= MY_WANT_STATE_DO;}
    204 #define	set_my_want_state_will(opt)	{options[opt] |= MY_WANT_STATE_WILL;}
    205 
    206 #define	set_my_state_dont(opt)		{options[opt] &= ~MY_STATE_DO;}
    207 #define	set_my_state_wont(opt)		{options[opt] &= ~MY_STATE_WILL;}
    208 #define	set_my_want_state_dont(opt)	{options[opt] &= ~MY_WANT_STATE_DO;}
    209 #define	set_my_want_state_wont(opt)	{options[opt] &= ~MY_WANT_STATE_WILL;}
    210 
    211 /*
    212  * Make everything symmetrical
    213  */
    214 
    215 #define	HIS_STATE_WILL			MY_STATE_DO
    216 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
    217 #define HIS_STATE_DO			MY_STATE_WILL
    218 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
    219 
    220 #define	his_state_is_do			my_state_is_will
    221 #define	his_state_is_will		my_state_is_do
    222 #define his_want_state_is_do		my_want_state_is_will
    223 #define his_want_state_is_will		my_want_state_is_do
    224 
    225 #define	his_state_is_dont		my_state_is_wont
    226 #define	his_state_is_wont		my_state_is_dont
    227 #define his_want_state_is_dont		my_want_state_is_wont
    228 #define his_want_state_is_wont		my_want_state_is_dont
    229 
    230 #define	set_his_state_do		set_my_state_will
    231 #define	set_his_state_will		set_my_state_do
    232 #define	set_his_want_state_do		set_my_want_state_will
    233 #define	set_his_want_state_will		set_my_want_state_do
    234 
    235 #define	set_his_state_dont		set_my_state_wont
    236 #define	set_his_state_wont		set_my_state_dont
    237 #define	set_his_want_state_dont		set_my_want_state_wont
    238 #define	set_his_want_state_wont		set_my_want_state_dont
    239 
    240 
    241 extern FILE
    242     *NetTrace;		/* Where debugging output goes */
    243 extern unsigned char
    244     NetTraceFile[];	/* Name of file where debugging output goes */
    245 
    246 extern jmp_buf
    247     peerdied,
    248     toplevel;		/* For error conditions. */
    249 
    250 
    251 /* authenc.c */
    252 int telnet_net_write P((unsigned char *, int));
    253 void net_encrypt P((void));
    254 int telnet_spin P((void));
    255 char *telnet_getenv P((char *));
    256 char *telnet_gets P((char *, char *, int, int));
    257 
    258 /* commands.c */
    259 int send_tncmd P((void (*)(int, int), char *, char *));
    260 void _setlist_init P((void));
    261 void set_escape_char P((char *));
    262 int set_mode P((int));
    263 int clear_mode P((int));
    264 int modehelp P((int));
    265 int suspend P((int, char *[]));
    266 int shell P((int, char *[]));
    267 int quit P((int, char *[]));
    268 int logout P((int, char *[]));
    269 int env_cmd P((int, char *[]));
    270 struct env_lst *env_find P((unsigned char *));
    271 void env_init P((void));
    272 struct env_lst *env_define P((unsigned char *, unsigned char *));
    273 struct env_lst *env_undefine P((unsigned char *, unsigned char *));
    274 struct env_lst *env_export P((unsigned char *, unsigned char *));
    275 struct env_lst *env_unexport P((unsigned char *, unsigned char *));
    276 struct env_lst *env_send P((unsigned char *, unsigned char *));
    277 struct env_lst *env_list P((unsigned char *, unsigned char *));
    278 unsigned char *env_default P((int, int ));
    279 unsigned char *env_getvalue P((unsigned char *));
    280 void env_varval P((unsigned char *));
    281 int auth_cmd P((int, char *[]));
    282 int ayt_status P((void));
    283 int encrypt_cmd P((int, char *[]));
    284 int tn P((int, char *[]));
    285 void command P((int, char *, int));
    286 void cmdrc P((const char *, const char *));
    287 struct addrinfo;
    288 int sourceroute P((struct addrinfo *, char *, char **, int *, int*));
    289 
    290 /* main.c */
    291 void tninit P((void));
    292 void usage P((void));
    293 
    294 /* network.c */
    295 void init_network P((void));
    296 int stilloob P((void));
    297 void setneturg P((void));
    298 int netflush P((void));
    299 
    300 /* sys_bsd.c */
    301 void init_sys P((void));
    302 int TerminalWrite P((char *, int));
    303 int TerminalRead P((unsigned char *, int));
    304 int TerminalAutoFlush P((void));
    305 int TerminalSpecialChars P((int));
    306 void TerminalFlushOutput P((void));
    307 void TerminalSaveState P((void));
    308 cc_t *tcval P((int));
    309 void TerminalDefaultChars P((void));
    310 void TerminalRestoreState P((void));
    311 void TerminalNewMode P((int));
    312 void TerminalSpeeds P((long *, long *));
    313 int TerminalWindowSize P((long *, long *));
    314 int NetClose P((int));
    315 void NetNonblockingIO P((int, int));
    316 void NetSigIO P((int, int));
    317 void NetSetPgrp P((int));
    318 void sys_telnet_init P((void));
    319 int process_rings P((int , int , int , int , int , int));
    320 
    321 /* telnet.c */
    322 void init_telnet P((void));
    323 void send_do P((int, int ));
    324 void send_dont P((int, int ));
    325 void send_will P((int, int ));
    326 void send_wont P((int, int ));
    327 void willoption P((int));
    328 void wontoption P((int));
    329 char **mklist P((char *, char *));
    330 int is_unique P((char *, char **, char **));
    331 int setup_term P((char *, int, int *));
    332 char *gettermname P((void));
    333 void lm_will P((unsigned char *, int));
    334 void lm_wont P((unsigned char *, int));
    335 void lm_do P((unsigned char *, int));
    336 void lm_dont P((unsigned char *, int));
    337 void lm_mode P((unsigned char *, int, int ));
    338 void slc_init P((void));
    339 void slcstate P((void));
    340 void slc_mode_export P((int));
    341 void slc_mode_import P((int));
    342 void slc_import P((int));
    343 void slc_export P((void));
    344 void slc P((unsigned char *, int));
    345 void slc_check P((void));
    346 void slc_start_reply P((void));
    347 void slc_add_reply P((unsigned int, unsigned int, cc_t));
    348 void slc_end_reply P((void));
    349 int slc_update P((void));
    350 void env_opt P((unsigned char *, int));
    351 void env_opt_start P((void));
    352 void env_opt_start_info P((void));
    353 void env_opt_add P((unsigned char *));
    354 int opt_welldefined P((char *));
    355 void env_opt_end P((int));
    356 int telrcv P((void));
    357 int rlogin_susp P((void));
    358 int Scheduler P((int));
    359 void telnet P((const char *));
    360 void xmitAO P((void));
    361 void xmitEL P((void));
    362 void xmitEC P((void));
    363 int dosynch P((char *));
    364 int get_status P((char *));
    365 void intp P((void));
    366 void sendbrk P((void));
    367 void sendabort P((void));
    368 void sendsusp P((void));
    369 void sendeof P((void));
    370 void sendayt P((void));
    371 void sendnaws P((void));
    372 void tel_enter_binary P((int));
    373 void tel_leave_binary P((int));
    374 
    375 /* terminal.c */
    376 void init_terminal P((void));
    377 int ttyflush P((int));
    378 int getconnmode P((void));
    379 void setconnmode P((int));
    380 void setcommandmode P((void));
    381 
    382 /* utilities.c */
    383 void upcase P((char *));
    384 int SetSockOpt P((int, int , int , int ));
    385 void SetNetTrace P((char *));
    386 void Dump P((int, unsigned char *, int));
    387 void printoption P((char *, int, int ));
    388 void optionstatus P((void));
    389 void printsub P((int, unsigned char *, int));
    390 void EmptyTerminal P((void));
    391 void SetForExit P((void));
    392 void Exit P((int)) __attribute__((__noreturn__));
    393 void ExitString P((char *, int)) __attribute__((__noreturn__));
    394 
    395 #ifndef	USE_TERMIO
    396 
    397 extern struct	tchars ntc;
    398 extern struct	ltchars nltc;
    399 extern struct	sgttyb nttyb;
    400 
    401 # define termEofChar		ntc.t_eofc
    402 # define termEraseChar		nttyb.sg_erase
    403 # define termFlushChar		nltc.t_flushc
    404 # define termIntChar		ntc.t_intrc
    405 # define termKillChar		nttyb.sg_kill
    406 # define termLiteralNextChar	nltc.t_lnextc
    407 # define termQuitChar		ntc.t_quitc
    408 # define termSuspChar		nltc.t_suspc
    409 # define termRprntChar		nltc.t_rprntc
    410 # define termWerasChar		nltc.t_werasc
    411 # define termStartChar		ntc.t_startc
    412 # define termStopChar		ntc.t_stopc
    413 # define termForw1Char		ntc.t_brkc
    414 extern cc_t termForw2Char;
    415 extern cc_t termAytChar;
    416 
    417 # define termEofCharp		(cc_t *)&ntc.t_eofc
    418 # define termEraseCharp		(cc_t *)&nttyb.sg_erase
    419 # define termFlushCharp		(cc_t *)&nltc.t_flushc
    420 # define termIntCharp		(cc_t *)&ntc.t_intrc
    421 # define termKillCharp		(cc_t *)&nttyb.sg_kill
    422 # define termLiteralNextCharp	(cc_t *)&nltc.t_lnextc
    423 # define termQuitCharp		(cc_t *)&ntc.t_quitc
    424 # define termSuspCharp		(cc_t *)&nltc.t_suspc
    425 # define termRprntCharp		(cc_t *)&nltc.t_rprntc
    426 # define termWerasCharp		(cc_t *)&nltc.t_werasc
    427 # define termStartCharp		(cc_t *)&ntc.t_startc
    428 # define termStopCharp		(cc_t *)&ntc.t_stopc
    429 # define termForw1Charp		(cc_t *)&ntc.t_brkc
    430 # define termForw2Charp		(cc_t *)&termForw2Char
    431 # define termAytCharp		(cc_t *)&termAytChar
    432 
    433 # else
    434 
    435 extern struct	termio new_tc;
    436 
    437 # define termEofChar		new_tc.c_cc[VEOF]
    438 # define termEraseChar		new_tc.c_cc[VERASE]
    439 # define termIntChar		new_tc.c_cc[VINTR]
    440 # define termKillChar		new_tc.c_cc[VKILL]
    441 # define termQuitChar		new_tc.c_cc[VQUIT]
    442 
    443 # ifndef	VSUSP
    444 extern cc_t termSuspChar;
    445 # else
    446 #  define termSuspChar		new_tc.c_cc[VSUSP]
    447 # endif
    448 # if	defined(VFLUSHO) && !defined(VDISCARD)
    449 #  define VDISCARD VFLUSHO
    450 # endif
    451 # ifndef	VDISCARD
    452 extern cc_t termFlushChar;
    453 # else
    454 #  define termFlushChar		new_tc.c_cc[VDISCARD]
    455 # endif
    456 # ifndef VWERASE
    457 extern cc_t termWerasChar;
    458 # else
    459 #  define termWerasChar		new_tc.c_cc[VWERASE]
    460 # endif
    461 # ifndef	VREPRINT
    462 extern cc_t termRprntChar;
    463 # else
    464 #  define termRprntChar		new_tc.c_cc[VREPRINT]
    465 # endif
    466 # ifndef	VLNEXT
    467 extern cc_t termLiteralNextChar;
    468 # else
    469 #  define termLiteralNextChar	new_tc.c_cc[VLNEXT]
    470 # endif
    471 # ifndef	VSTART
    472 extern cc_t termStartChar;
    473 # else
    474 #  define termStartChar		new_tc.c_cc[VSTART]
    475 # endif
    476 # ifndef	VSTOP
    477 extern cc_t termStopChar;
    478 # else
    479 #  define termStopChar		new_tc.c_cc[VSTOP]
    480 # endif
    481 # ifndef	VEOL
    482 extern cc_t termForw1Char;
    483 # else
    484 #  define termForw1Char		new_tc.c_cc[VEOL]
    485 # endif
    486 # ifndef	VEOL2
    487 extern cc_t termForw2Char;
    488 # else
    489 #  define termForw2Char		new_tc.c_cc[VEOL]
    490 # endif
    491 # ifndef	VSTATUS
    492 extern cc_t termAytChar;
    493 #else
    494 #  define termAytChar		new_tc.c_cc[VSTATUS]
    495 #endif
    496 
    497 # if !defined(CRAY) || defined(__STDC__)
    498 #  define termEofCharp		&termEofChar
    499 #  define termEraseCharp	&termEraseChar
    500 #  define termIntCharp		&termIntChar
    501 #  define termKillCharp		&termKillChar
    502 #  define termQuitCharp		&termQuitChar
    503 #  define termSuspCharp		&termSuspChar
    504 #  define termFlushCharp	&termFlushChar
    505 #  define termWerasCharp	&termWerasChar
    506 #  define termRprntCharp	&termRprntChar
    507 #  define termLiteralNextCharp	&termLiteralNextChar
    508 #  define termStartCharp	&termStartChar
    509 #  define termStopCharp		&termStopChar
    510 #  define termForw1Charp	&termForw1Char
    511 #  define termForw2Charp	&termForw2Char
    512 #  define termAytCharp		&termAytChar
    513 # else
    514 	/* Work around a compiler bug */
    515 #  define termEofCharp		0
    516 #  define termEraseCharp	0
    517 #  define termIntCharp		0
    518 #  define termKillCharp		0
    519 #  define termQuitCharp		0
    520 #  define termSuspCharp		0
    521 #  define termFlushCharp	0
    522 #  define termWerasCharp	0
    523 #  define termRprntCharp	0
    524 #  define termLiteralNextCharp	0
    525 #  define termStartCharp	0
    526 #  define termStopCharp		0
    527 #  define termForw1Charp	0
    528 #  define termForw2Charp	0
    529 #  define termAytCharp		0
    530 # endif
    531 #endif
    532 
    533 
    534 /* Tn3270 section */
    535 #if	defined(TN3270)
    536 
    537 extern int
    538     HaveInput,		/* Whether an asynchronous I/O indication came in */
    539     noasynchtty,	/* Don't do signals on I/O (SIGURG, SIGIO) */
    540     noasynchnet,	/* Don't do signals on I/O (SIGURG, SIGIO) */
    541     sigiocount,		/* Count of SIGIO receptions */
    542     shell_active;	/* Subshell is active */
    543 
    544 extern char
    545     *Ibackp,		/* Oldest byte of 3270 data */
    546     Ibuf[],		/* 3270 buffer */
    547     *Ifrontp,		/* Where next 3270 byte goes */
    548     tline[200],
    549     *transcom;		/* Transparent command */
    550 
    551 /* tn3270.c */
    552 void init_3270 P((void));
    553 int DataToNetwork P((char *, int, int));
    554 void inputAvailable P((int));
    555 void outputPurge P((void));
    556 int DataToTerminal P((char *, int));
    557 int Push3270 P((void));
    558 void Finish3270 P((void));
    559 void StringToTerminal P((char *));
    560 void _putchar P((int));
    561 void SetIn3270 P((void));
    562 int tn3270_ttype P((void));
    563 int settranscom P((int, char *[]));
    564 int shell_continue P((void));
    565 int DataFromTerminal __P((char *, int));
    566 int DataFromNetwork __P((char *, int, int));
    567 void ConnectScreen __P((void));
    568 int DoTerminalOutput __P((void));
    569 
    570 #endif	/* defined(TN3270) */
    571