Home | History | Annotate | Line # | Download | only in telnet
externs.h revision 1.16
      1 /*	$NetBSD: externs.h,v 1.16 2000/01/21 17:08:36 mycroft 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;
     99 #endif
    100 #endif
    101 
    102 #ifndef	_POSIX_VDISABLE
    103 # ifdef sun
    104 #  include <sys/param.h>	/* pick up VDISABLE definition, mayby */
    105 # endif
    106 # ifdef VDISABLE
    107 #  define _POSIX_VDISABLE VDISABLE
    108 # else
    109 #  define _POSIX_VDISABLE ((cc_t)'\377')
    110 # endif
    111 #endif
    112 
    113 #define	SUBBUFSIZE	256
    114 
    115 #include <sys/cdefs.h>
    116 #define P __P
    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 /*
    173  * We keep track of each side of the option negotiation.
    174  */
    175 
    176 #define	MY_STATE_WILL		0x01
    177 #define	MY_WANT_STATE_WILL	0x02
    178 #define	MY_STATE_DO		0x04
    179 #define	MY_WANT_STATE_DO	0x08
    180 
    181 /*
    182  * Macros to check the current state of things
    183  */
    184 
    185 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
    186 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
    187 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
    188 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
    189 
    190 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
    191 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
    192 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
    193 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
    194 
    195 #define	set_my_state_do(opt)		{options[opt] |= MY_STATE_DO;}
    196 #define	set_my_state_will(opt)		{options[opt] |= MY_STATE_WILL;}
    197 #define	set_my_want_state_do(opt)	{options[opt] |= MY_WANT_STATE_DO;}
    198 #define	set_my_want_state_will(opt)	{options[opt] |= MY_WANT_STATE_WILL;}
    199 
    200 #define	set_my_state_dont(opt)		{options[opt] &= ~MY_STATE_DO;}
    201 #define	set_my_state_wont(opt)		{options[opt] &= ~MY_STATE_WILL;}
    202 #define	set_my_want_state_dont(opt)	{options[opt] &= ~MY_WANT_STATE_DO;}
    203 #define	set_my_want_state_wont(opt)	{options[opt] &= ~MY_WANT_STATE_WILL;}
    204 
    205 /*
    206  * Make everything symetrical
    207  */
    208 
    209 #define	HIS_STATE_WILL			MY_STATE_DO
    210 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
    211 #define HIS_STATE_DO			MY_STATE_WILL
    212 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
    213 
    214 #define	his_state_is_do			my_state_is_will
    215 #define	his_state_is_will		my_state_is_do
    216 #define his_want_state_is_do		my_want_state_is_will
    217 #define his_want_state_is_will		my_want_state_is_do
    218 
    219 #define	his_state_is_dont		my_state_is_wont
    220 #define	his_state_is_wont		my_state_is_dont
    221 #define his_want_state_is_dont		my_want_state_is_wont
    222 #define his_want_state_is_wont		my_want_state_is_dont
    223 
    224 #define	set_his_state_do		set_my_state_will
    225 #define	set_his_state_will		set_my_state_do
    226 #define	set_his_want_state_do		set_my_want_state_will
    227 #define	set_his_want_state_will		set_my_want_state_do
    228 
    229 #define	set_his_state_dont		set_my_state_wont
    230 #define	set_his_state_wont		set_my_state_dont
    231 #define	set_his_want_state_dont		set_my_want_state_wont
    232 #define	set_his_want_state_wont		set_my_want_state_dont
    233 
    234 
    235 extern FILE
    236     *NetTrace;		/* Where debugging output goes */
    237 extern unsigned char
    238     NetTraceFile[];	/* Name of file where debugging output goes */
    239 
    240 extern jmp_buf
    241     peerdied,
    242     toplevel;		/* For error conditions. */
    243 
    244 
    245 /* authenc.c */
    246 int net_write P((unsigned char *, int));
    247 void net_encrypt P((void));
    248 int telnet_spin P((void));
    249 char *telnet_getenv P((char *));
    250 char *telnet_gets P((char *, char *, int, int));
    251 
    252 /* commands.c */
    253 int send_tncmd P((void (*)(int, int), char *, char *));
    254 void _setlist_init P((void));
    255 void set_escape_char P((char *));
    256 int set_mode P((int));
    257 int clear_mode P((int));
    258 int modehelp P((int));
    259 int suspend P((int, char *[]));
    260 int shell P((int, char *[]));
    261 int quit P((int, char *[]));
    262 int logout P((int, char *[]));
    263 int env_cmd P((int, char *[]));
    264 struct env_lst *env_find P((unsigned char *));
    265 void env_init P((void));
    266 struct env_lst *env_define P((unsigned char *, unsigned char *));
    267 struct env_lst *env_undefine P((unsigned char *, unsigned char *));
    268 struct env_lst *env_export P((unsigned char *, unsigned char *));
    269 struct env_lst *env_unexport P((unsigned char *, unsigned char *));
    270 struct env_lst *env_send P((unsigned char *, unsigned char *));
    271 struct env_lst *env_list P((unsigned char *, unsigned char *));
    272 unsigned char *env_default P((int, int ));
    273 unsigned char *env_getvalue P((unsigned char *));
    274 void env_varval P((unsigned char *));
    275 int auth_cmd P((int, char *[]));
    276 int ayt_status P((void));
    277 int tn P((int, char *[]));
    278 void command P((int, char *, int));
    279 void cmdrc P((const char *, const char *));
    280 struct addrinfo;
    281 int sourceroute P((struct addrinfo *, char *, char **, int *, int*));
    282 
    283 /* main.c */
    284 void tninit P((void));
    285 void usage P((void));
    286 
    287 /* network.c */
    288 void init_network P((void));
    289 int stilloob P((void));
    290 void setneturg P((void));
    291 int netflush P((void));
    292 
    293 /* sys_bsd.c */
    294 void init_sys P((void));
    295 int TerminalWrite P((char *, int));
    296 int TerminalRead P((unsigned char *, int));
    297 int TerminalAutoFlush P((void));
    298 int TerminalSpecialChars P((int));
    299 void TerminalFlushOutput P((void));
    300 void TerminalSaveState P((void));
    301 cc_t *tcval P((int));
    302 void TerminalDefaultChars P((void));
    303 void TerminalRestoreState P((void));
    304 void TerminalNewMode P((int));
    305 void TerminalSpeeds P((long *, long *));
    306 int TerminalWindowSize P((long *, long *));
    307 int NetClose P((int));
    308 void NetNonblockingIO P((int, int));
    309 void NetSigIO P((int, int));
    310 void NetSetPgrp P((int));
    311 void sys_telnet_init P((void));
    312 int process_rings P((int , int , int , int , int , int));
    313 
    314 /* telnet.c */
    315 void init_telnet P((void));
    316 void send_do P((int, int ));
    317 void send_dont P((int, int ));
    318 void send_will P((int, int ));
    319 void send_wont P((int, int ));
    320 void willoption P((int));
    321 void wontoption P((int));
    322 char **mklist P((char *, char *));
    323 int is_unique P((char *, char **, char **));
    324 int setup_term P((char *, int, int *));
    325 char *gettermname P((void));
    326 void lm_will P((unsigned char *, int));
    327 void lm_wont P((unsigned char *, int));
    328 void lm_do P((unsigned char *, int));
    329 void lm_dont P((unsigned char *, int));
    330 void lm_mode P((unsigned char *, int, int ));
    331 void slc_init P((void));
    332 void slcstate P((void));
    333 void slc_mode_export P((int));
    334 void slc_mode_import P((int));
    335 void slc_import P((int));
    336 void slc_export P((void));
    337 void slc P((unsigned char *, int));
    338 void slc_check P((void));
    339 void slc_start_reply P((void));
    340 void slc_add_reply P((unsigned int, unsigned int, cc_t));
    341 void slc_end_reply P((void));
    342 int slc_update P((void));
    343 void env_opt P((unsigned char *, int));
    344 void env_opt_start P((void));
    345 void env_opt_start_info P((void));
    346 void env_opt_add P((unsigned char *));
    347 int opt_welldefined P((char *));
    348 void env_opt_end P((int));
    349 int telrcv P((void));
    350 int rlogin_susp P((void));
    351 int Scheduler P((int));
    352 void telnet P((const char *));
    353 void xmitAO P((void));
    354 void xmitEL P((void));
    355 void xmitEC P((void));
    356 int dosynch P((char *));
    357 int get_status P((char *));
    358 void intp P((void));
    359 void sendbrk P((void));
    360 void sendabort P((void));
    361 void sendsusp P((void));
    362 void sendeof P((void));
    363 void sendayt P((void));
    364 void sendnaws P((void));
    365 void tel_enter_binary P((int));
    366 void tel_leave_binary P((int));
    367 
    368 /* terminal.c */
    369 void init_terminal P((void));
    370 int ttyflush P((int));
    371 int getconnmode P((void));
    372 void setconnmode P((int));
    373 void setcommandmode P((void));
    374 
    375 /* utilities.c */
    376 void upcase P((char *));
    377 int SetSockOpt P((int, int , int , int ));
    378 void SetNetTrace P((char *));
    379 void Dump P((int, unsigned char *, int));
    380 void printoption P((char *, int, int ));
    381 void optionstatus P((void));
    382 void printsub P((int, unsigned char *, int));
    383 void EmptyTerminal P((void));
    384 void SetForExit P((void));
    385 void Exit P((int)) __attribute__((__noreturn__));
    386 void ExitString P((char *, int)) __attribute__((__noreturn__));
    387 
    388 #ifndef	USE_TERMIO
    389 
    390 extern struct	tchars ntc;
    391 extern struct	ltchars nltc;
    392 extern struct	sgttyb nttyb;
    393 
    394 # define termEofChar		ntc.t_eofc
    395 # define termEraseChar		nttyb.sg_erase
    396 # define termFlushChar		nltc.t_flushc
    397 # define termIntChar		ntc.t_intrc
    398 # define termKillChar		nttyb.sg_kill
    399 # define termLiteralNextChar	nltc.t_lnextc
    400 # define termQuitChar		ntc.t_quitc
    401 # define termSuspChar		nltc.t_suspc
    402 # define termRprntChar		nltc.t_rprntc
    403 # define termWerasChar		nltc.t_werasc
    404 # define termStartChar		ntc.t_startc
    405 # define termStopChar		ntc.t_stopc
    406 # define termForw1Char		ntc.t_brkc
    407 extern cc_t termForw2Char;
    408 extern cc_t termAytChar;
    409 
    410 # define termEofCharp		(cc_t *)&ntc.t_eofc
    411 # define termEraseCharp		(cc_t *)&nttyb.sg_erase
    412 # define termFlushCharp		(cc_t *)&nltc.t_flushc
    413 # define termIntCharp		(cc_t *)&ntc.t_intrc
    414 # define termKillCharp		(cc_t *)&nttyb.sg_kill
    415 # define termLiteralNextCharp	(cc_t *)&nltc.t_lnextc
    416 # define termQuitCharp		(cc_t *)&ntc.t_quitc
    417 # define termSuspCharp		(cc_t *)&nltc.t_suspc
    418 # define termRprntCharp		(cc_t *)&nltc.t_rprntc
    419 # define termWerasCharp		(cc_t *)&nltc.t_werasc
    420 # define termStartCharp		(cc_t *)&ntc.t_startc
    421 # define termStopCharp		(cc_t *)&ntc.t_stopc
    422 # define termForw1Charp		(cc_t *)&ntc.t_brkc
    423 # define termForw2Charp		(cc_t *)&termForw2Char
    424 # define termAytCharp		(cc_t *)&termAytChar
    425 
    426 # else
    427 
    428 extern struct	termio new_tc;
    429 
    430 # define termEofChar		new_tc.c_cc[VEOF]
    431 # define termEraseChar		new_tc.c_cc[VERASE]
    432 # define termIntChar		new_tc.c_cc[VINTR]
    433 # define termKillChar		new_tc.c_cc[VKILL]
    434 # define termQuitChar		new_tc.c_cc[VQUIT]
    435 
    436 # ifndef	VSUSP
    437 extern cc_t termSuspChar;
    438 # else
    439 #  define termSuspChar		new_tc.c_cc[VSUSP]
    440 # endif
    441 # if	defined(VFLUSHO) && !defined(VDISCARD)
    442 #  define VDISCARD VFLUSHO
    443 # endif
    444 # ifndef	VDISCARD
    445 extern cc_t termFlushChar;
    446 # else
    447 #  define termFlushChar		new_tc.c_cc[VDISCARD]
    448 # endif
    449 # ifndef VWERASE
    450 extern cc_t termWerasChar;
    451 # else
    452 #  define termWerasChar		new_tc.c_cc[VWERASE]
    453 # endif
    454 # ifndef	VREPRINT
    455 extern cc_t termRprntChar;
    456 # else
    457 #  define termRprntChar		new_tc.c_cc[VREPRINT]
    458 # endif
    459 # ifndef	VLNEXT
    460 extern cc_t termLiteralNextChar;
    461 # else
    462 #  define termLiteralNextChar	new_tc.c_cc[VLNEXT]
    463 # endif
    464 # ifndef	VSTART
    465 extern cc_t termStartChar;
    466 # else
    467 #  define termStartChar		new_tc.c_cc[VSTART]
    468 # endif
    469 # ifndef	VSTOP
    470 extern cc_t termStopChar;
    471 # else
    472 #  define termStopChar		new_tc.c_cc[VSTOP]
    473 # endif
    474 # ifndef	VEOL
    475 extern cc_t termForw1Char;
    476 # else
    477 #  define termForw1Char		new_tc.c_cc[VEOL]
    478 # endif
    479 # ifndef	VEOL2
    480 extern cc_t termForw2Char;
    481 # else
    482 #  define termForw2Char		new_tc.c_cc[VEOL]
    483 # endif
    484 # ifndef	VSTATUS
    485 extern cc_t termAytChar;
    486 #else
    487 #  define termAytChar		new_tc.c_cc[VSTATUS]
    488 #endif
    489 
    490 # if !defined(CRAY) || defined(__STDC__)
    491 #  define termEofCharp		&termEofChar
    492 #  define termEraseCharp	&termEraseChar
    493 #  define termIntCharp		&termIntChar
    494 #  define termKillCharp		&termKillChar
    495 #  define termQuitCharp		&termQuitChar
    496 #  define termSuspCharp		&termSuspChar
    497 #  define termFlushCharp	&termFlushChar
    498 #  define termWerasCharp	&termWerasChar
    499 #  define termRprntCharp	&termRprntChar
    500 #  define termLiteralNextCharp	&termLiteralNextChar
    501 #  define termStartCharp	&termStartChar
    502 #  define termStopCharp		&termStopChar
    503 #  define termForw1Charp	&termForw1Char
    504 #  define termForw2Charp	&termForw2Char
    505 #  define termAytCharp		&termAytChar
    506 # else
    507 	/* Work around a compiler bug */
    508 #  define termEofCharp		0
    509 #  define termEraseCharp	0
    510 #  define termIntCharp		0
    511 #  define termKillCharp		0
    512 #  define termQuitCharp		0
    513 #  define termSuspCharp		0
    514 #  define termFlushCharp	0
    515 #  define termWerasCharp	0
    516 #  define termRprntCharp	0
    517 #  define termLiteralNextCharp	0
    518 #  define termStartCharp	0
    519 #  define termStopCharp		0
    520 #  define termForw1Charp	0
    521 #  define termForw2Charp	0
    522 #  define termAytCharp		0
    523 # endif
    524 #endif
    525 
    526 
    527 /* Tn3270 section */
    528 #if	defined(TN3270)
    529 
    530 extern int
    531     HaveInput,		/* Whether an asynchronous I/O indication came in */
    532     noasynchtty,	/* Don't do signals on I/O (SIGURG, SIGIO) */
    533     noasynchnet,	/* Don't do signals on I/O (SIGURG, SIGIO) */
    534     sigiocount,		/* Count of SIGIO receptions */
    535     shell_active;	/* Subshell is active */
    536 
    537 extern char
    538     *Ibackp,		/* Oldest byte of 3270 data */
    539     Ibuf[],		/* 3270 buffer */
    540     *Ifrontp,		/* Where next 3270 byte goes */
    541     tline[],
    542     *transcom;		/* Transparent command */
    543 
    544 /* tn3270.c */
    545 void init_3270 P((void));
    546 int DataToNetwork P((char *, int, int));
    547 void inputAvailable P((int));
    548 void outputPurge P((void));
    549 int DataToTerminal P((char *, int));
    550 int Push3270 P((void));
    551 void Finish3270 P((void));
    552 void StringToTerminal P((char *));
    553 void _putchar P((int));
    554 void SetIn3270 P((void));
    555 int tn3270_ttype P((void));
    556 int settranscom P((int, char *[]));
    557 int shell_continue P((void));
    558 int DataFromTerminal __P((char *, int));
    559 int DataFromNetwork __P((char *, int, int));
    560 void ConnectScreen __P((void));
    561 int DoTerminalOutput __P((void));
    562 
    563 #endif	/* defined(TN3270) */
    564