xref: /csrg-svn/libexec/telnetd/defs.h (revision 61451)
138905Sborman /*
2*61451Sbostic  * Copyright (c) 1989, 1993
3*61451Sbostic  *	The Regents of the University of California.  All rights reserved.
438905Sborman  *
542673Sbostic  * %sccs.include.redist.c%
638905Sborman  *
7*61451Sbostic  *	@(#)defs.h	8.1 (Berkeley) 06/04/93
838905Sborman  */
938905Sborman 
1038905Sborman /*
1138905Sborman  * Telnet server defines
1238905Sborman  */
1338905Sborman #include <sys/types.h>
1438905Sborman #include <sys/param.h>
1538905Sborman 
1638905Sborman #ifndef	BSD
1738905Sborman # define	BSD 43
1838905Sborman #endif
1938905Sborman 
2044364Sborman #if	defined(CRAY) && !defined(LINEMODE)
2144364Sborman # define SYSV_TERMIO
2244364Sborman # define LINEMODE
2344364Sborman # define KLUDGELINEMODE
2444364Sborman # define DIAGNOSTICS
2546809Sdab # if defined(UNICOS50) && !defined(UNICOS5)
2646809Sdab #  define UNICOS5
2746809Sdab # endif
2844364Sborman # if !defined(UNICOS5)
2944364Sborman #  define BFTPDAEMON
3044364Sborman #  define HAS_IP_TOS
3144364Sborman # endif
3244364Sborman #endif /* CRAY */
3344364Sborman #if defined(UNICOS5) && !defined(NO_SETSID)
3444364Sborman # define NO_SETSID
3538905Sborman #endif
3638905Sborman 
3744364Sborman #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
3844364Sborman #define TELOPTS
3944364Sborman #define TELCMDS
4046809Sdab #define	SLC_NAMES
4144364Sborman #endif
4238905Sborman 
4344364Sborman #if	defined(SYSV_TERMIO) && !defined(USE_TERMIO)
4438905Sborman # define	USE_TERMIO
4538905Sborman #endif
4638905Sborman 
4738905Sborman #include <sys/socket.h>
4838905Sborman #ifndef	CRAY
4938905Sborman #include <sys/wait.h>
5038905Sborman #endif	/* CRAY */
5146809Sdab #include <fcntl.h>
5238905Sborman #include <sys/file.h>
5338905Sborman #include <sys/stat.h>
5438905Sborman #include <sys/time.h>
5544364Sborman #ifndef	FILIO_H
5639503Sborman #include <sys/ioctl.h>
5744364Sborman #else
5844364Sborman #include <sys/filio.h>
5944364Sborman #endif
6038905Sborman 
6138905Sborman #include <netinet/in.h>
6238905Sborman 
6338905Sborman #include <arpa/telnet.h>
6438905Sborman 
6538905Sborman #include <stdio.h>
6646809Sdab #ifdef	__STDC__
6746809Sdab #include <stdlib.h>
6846809Sdab #endif
6938905Sborman #include <signal.h>
7038905Sborman #include <errno.h>
7138905Sborman #include <netdb.h>
7238905Sborman #include <syslog.h>
7340242Sborman #ifndef	LOG_DAEMON
7440242Sborman #define	LOG_DAEMON	0
7540242Sborman #endif
7640242Sborman #ifndef	LOG_ODELAY
7740242Sborman #define	LOG_ODELAY	0
7840242Sborman #endif
7938905Sborman #include <ctype.h>
8044364Sborman #ifndef NO_STRING_H
8142029Sbostic #include <string.h>
8244364Sborman #else
8344364Sborman #include <strings.h>
8444364Sborman #endif
8538905Sborman 
8638905Sborman #ifndef	USE_TERMIO
8738905Sborman #include <sgtty.h>
8838905Sborman #else
8938905Sborman # ifdef	SYSV_TERMIO
9038905Sborman # include <termio.h>
9138905Sborman # else
9238905Sborman # include <termios.h>
9338905Sborman # endif
9438905Sborman #endif
9544364Sborman #if !defined(USE_TERMIO) || defined(NO_CC_T)
9644364Sborman typedef unsigned char cc_t;
9744364Sborman #endif
9838905Sborman 
9946809Sdab #ifdef	__STDC__
10046809Sdab #include <unistd.h>
10146809Sdab #endif
10246809Sdab 
10345234Sborman #ifndef _POSIX_VDISABLE
10445234Sborman # ifdef VDISABLE
10545234Sborman #  define _POSIX_VDISABLE VDISABLE
10645234Sborman # else
10745234Sborman #  define _POSIX_VDISABLE ((unsigned char)'\377')
10845234Sborman # endif
10945234Sborman #endif
11045234Sborman 
11145234Sborman 
11238905Sborman #ifdef	CRAY
11338905Sborman # ifdef	CRAY1
11438905Sborman # include <sys/pty.h>
11538905Sborman #  ifndef FD_ZERO
11638905Sborman # include <sys/select.h>
11738905Sborman #  endif /* FD_ZERO */
11838905Sborman # endif	/* CRAY1 */
11938905Sborman 
12038905Sborman #include <memory.h>
12138905Sborman #endif	/* CRAY */
12238905Sborman 
12360151Sdab #ifdef __hpux
12460151Sdab #include <sys/ptyio.h>
12560151Sdab #endif
12660151Sdab 
12744364Sborman #if	!defined(TIOCSCTTY) && defined(TCSETCTTY)
12844364Sborman # define	TIOCSCTTY TCSETCTTY
12938905Sborman #endif
13038905Sborman 
13138905Sborman #ifndef	FD_SET
13240242Sborman #ifndef	HAVE_fd_set
13338905Sborman typedef struct fd_set { int fds_bits[1]; } fd_set;
13440242Sborman #endif
13538905Sborman 
13638905Sborman #define	FD_SET(n, p)	((p)->fds_bits[0] |= (1<<(n)))
13738905Sborman #define	FD_CLR(n, p)	((p)->fds_bits[0] &= ~(1<<(n)))
13838905Sborman #define	FD_ISSET(n, p)	((p)->fds_bits[0] & (1<<(n)))
13938905Sborman #define FD_ZERO(p)	((p)->fds_bits[0] = 0)
14038905Sborman #endif	/* FD_SET */
14138905Sborman 
14238905Sborman /*
14338905Sborman  * I/O data buffers defines
14438905Sborman  */
14538905Sborman #define	NETSLOP	64
14638905Sborman #ifdef CRAY
14738905Sborman #undef BUFSIZ
14838905Sborman #define BUFSIZ  2048
14938905Sborman #endif
15038905Sborman 
15138905Sborman #define	NIACCUM(c)	{   *netip++ = c; \
15238905Sborman 			    ncc++; \
15338905Sborman 			}
15438905Sborman 
15538905Sborman /* clock manipulations */
15638905Sborman #define	settimer(x)	(clocks.x = ++clocks.system)
15738905Sborman #define	sequenceIs(x,y)	(clocks.x < clocks.y)
15838905Sborman 
15938905Sborman /*
16038905Sborman  * Linemode support states, in decreasing order of importance
16138905Sborman  */
16257212Sdab #define REAL_LINEMODE	0x04
16357212Sdab #define KLUDGE_OK	0x03
16457212Sdab #define	NO_AUTOKLUDGE	0x02
16538905Sborman #define KLUDGE_LINEMODE	0x01
16638905Sborman #define NO_LINEMODE	0x00
16738905Sborman 
16838905Sborman /*
16938905Sborman  * Structures of information for each special character function.
17038905Sborman  */
17138905Sborman typedef struct {
17238905Sborman 	unsigned char	flag;		/* the flags for this function */
17340242Sborman 	cc_t		val;		/* the value of the special character */
17438905Sborman } slcent, *Slcent;
17538905Sborman 
17638905Sborman typedef struct {
17738905Sborman 	slcent		defset;		/* the default settings */
17838905Sborman 	slcent		current;	/* the current settings */
17940242Sborman 	cc_t		*sptr;		/* a pointer to the char in */
18038905Sborman 					/* system data structures */
18138905Sborman } slcfun, *Slcfun;
18244364Sborman 
18344364Sborman #ifdef DIAGNOSTICS
18444364Sborman /*
18544364Sborman  * Diagnostics capabilities
18644364Sborman  */
18744364Sborman #define	TD_REPORT	0x01	/* Report operations to client */
18844364Sborman #define TD_EXERCISE	0x02	/* Exercise client's implementation */
18944364Sborman #define TD_NETDATA	0x04	/* Display received data stream */
19044364Sborman #define TD_PTYDATA	0x08	/* Display data passed to pty */
19144364Sborman #define	TD_OPTIONS	0x10	/* Report just telnet options */
19244364Sborman #endif /* DIAGNOSTICS */
19344364Sborman 
19444364Sborman /*
19544364Sborman  * We keep track of each side of the option negotiation.
19644364Sborman  */
19744364Sborman 
19844364Sborman #define	MY_STATE_WILL		0x01
19944364Sborman #define	MY_WANT_STATE_WILL	0x02
20044364Sborman #define	MY_STATE_DO		0x04
20144364Sborman #define	MY_WANT_STATE_DO	0x08
20244364Sborman 
20344364Sborman /*
20444364Sborman  * Macros to check the current state of things
20544364Sborman  */
20644364Sborman 
20744364Sborman #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
20844364Sborman #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
20944364Sborman #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
21044364Sborman #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
21144364Sborman 
21244364Sborman #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
21344364Sborman #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
21444364Sborman #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
21544364Sborman #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
21644364Sborman 
21744364Sborman #define	set_my_state_do(opt)		(options[opt] |= MY_STATE_DO)
21844364Sborman #define	set_my_state_will(opt)		(options[opt] |= MY_STATE_WILL)
21944364Sborman #define	set_my_want_state_do(opt)	(options[opt] |= MY_WANT_STATE_DO)
22044364Sborman #define	set_my_want_state_will(opt)	(options[opt] |= MY_WANT_STATE_WILL)
22144364Sborman 
22244364Sborman #define	set_my_state_dont(opt)		(options[opt] &= ~MY_STATE_DO)
22344364Sborman #define	set_my_state_wont(opt)		(options[opt] &= ~MY_STATE_WILL)
22444364Sborman #define	set_my_want_state_dont(opt)	(options[opt] &= ~MY_WANT_STATE_DO)
22544364Sborman #define	set_my_want_state_wont(opt)	(options[opt] &= ~MY_WANT_STATE_WILL)
22644364Sborman 
22744364Sborman /*
22844364Sborman  * Tricky code here.  What we want to know is if the MY_STATE_WILL
22944364Sborman  * and MY_WANT_STATE_WILL bits have the same value.  Since the two
23044364Sborman  * bits are adjacent, a little arithmatic will show that by adding
23144364Sborman  * in the lower bit, the upper bit will be set if the two bits were
23244364Sborman  * different, and clear if they were the same.
23344364Sborman  */
23444364Sborman #define my_will_wont_is_changing(opt) \
23544364Sborman 			((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
23644364Sborman 
23744364Sborman #define my_do_dont_is_changing(opt) \
23844364Sborman 			((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
23944364Sborman 
24044364Sborman /*
24144364Sborman  * Make everything symetrical
24244364Sborman  */
24344364Sborman 
24444364Sborman #define	HIS_STATE_WILL			MY_STATE_DO
24544364Sborman #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
24644364Sborman #define HIS_STATE_DO			MY_STATE_WILL
24744364Sborman #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
24844364Sborman 
24944364Sborman #define	his_state_is_do			my_state_is_will
25044364Sborman #define	his_state_is_will		my_state_is_do
25144364Sborman #define his_want_state_is_do		my_want_state_is_will
25244364Sborman #define his_want_state_is_will		my_want_state_is_do
25344364Sborman 
25444364Sborman #define	his_state_is_dont		my_state_is_wont
25544364Sborman #define	his_state_is_wont		my_state_is_dont
25644364Sborman #define his_want_state_is_dont		my_want_state_is_wont
25744364Sborman #define his_want_state_is_wont		my_want_state_is_dont
25844364Sborman 
25944364Sborman #define	set_his_state_do		set_my_state_will
26044364Sborman #define	set_his_state_will		set_my_state_do
26144364Sborman #define	set_his_want_state_do		set_my_want_state_will
26244364Sborman #define	set_his_want_state_will		set_my_want_state_do
26344364Sborman 
26444364Sborman #define	set_his_state_dont		set_my_state_wont
26544364Sborman #define	set_his_state_wont		set_my_state_dont
26644364Sborman #define	set_his_want_state_dont		set_my_want_state_wont
26744364Sborman #define	set_his_want_state_wont		set_my_want_state_dont
26844364Sborman 
26944364Sborman #define his_will_wont_is_changing	my_do_dont_is_changing
27044364Sborman #define his_do_dont_is_changing		my_will_wont_is_changing
271