xref: /csrg-svn/libexec/telnetd/defs.h (revision 45234)
138905Sborman /*
238905Sborman  * Copyright (c) 1989 The Regents of the University of California.
338905Sborman  * All rights reserved.
438905Sborman  *
542673Sbostic  * %sccs.include.redist.c%
638905Sborman  *
7*45234Sborman  *	@(#)defs.h	5.9 (Berkeley) 09/14/90
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 NO_GETTYTAB
2544364Sborman # define DIAGNOSTICS
2644364Sborman # if !defined(UNICOS5)
2744364Sborman #  define BFTPDAEMON
2844364Sborman #  define HAS_IP_TOS
2944364Sborman # endif
3044364Sborman #endif /* CRAY */
3144364Sborman #if defined(UNICOS5) && !defined(NO_SETSID)
3244364Sborman # define NO_SETSID
3338905Sborman #endif
3438905Sborman 
3544364Sborman #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
3644364Sborman #define TELOPTS
3744364Sborman #define TELCMDS
3844364Sborman #endif
3938905Sborman 
4044364Sborman #if	defined(SYSV_TERMIO) && !defined(USE_TERMIO)
4138905Sborman # define	USE_TERMIO
4238905Sborman #endif
4338905Sborman 
4438905Sborman #include <sys/socket.h>
4538905Sborman #ifndef	CRAY
4638905Sborman #include <sys/wait.h>
4738905Sborman #endif	/* CRAY */
4838905Sborman #include <sys/file.h>
4938905Sborman #include <sys/stat.h>
5038905Sborman #include <sys/time.h>
5144364Sborman #ifndef	FILIO_H
5239503Sborman #include <sys/ioctl.h>
5344364Sborman #else
5444364Sborman #include <sys/filio.h>
5544364Sborman #endif
5638905Sborman 
5738905Sborman #include <netinet/in.h>
5838905Sborman 
5938905Sborman #include <arpa/telnet.h>
6038905Sborman 
6138905Sborman #include <stdio.h>
6238905Sborman #include <signal.h>
6338905Sborman #include <errno.h>
6438905Sborman #include <netdb.h>
6538905Sborman #include <syslog.h>
6640242Sborman #ifndef	LOG_DAEMON
6740242Sborman #define	LOG_DAEMON	0
6840242Sborman #endif
6940242Sborman #ifndef	LOG_ODELAY
7040242Sborman #define	LOG_ODELAY	0
7140242Sborman #endif
7238905Sborman #include <ctype.h>
7344364Sborman #ifndef NO_STRING_H
7442029Sbostic #include <string.h>
7544364Sborman #else
7644364Sborman #include <strings.h>
7744364Sborman #endif
7838905Sborman 
7938905Sborman #ifndef	USE_TERMIO
8038905Sborman #include <sgtty.h>
8138905Sborman #else
8238905Sborman # ifdef	SYSV_TERMIO
8338905Sborman # include <termio.h>
8438905Sborman # else
8538905Sborman # include <termios.h>
8638905Sborman # endif
8738905Sborman #endif
8844364Sborman #if !defined(USE_TERMIO) || defined(NO_CC_T)
8944364Sborman typedef unsigned char cc_t;
9044364Sborman #endif
9138905Sborman 
92*45234Sborman #ifndef _POSIX_VDISABLE
93*45234Sborman # ifdef VDISABLE
94*45234Sborman #  define _POSIX_VDISABLE VDISABLE
95*45234Sborman # else
96*45234Sborman #  define _POSIX_VDISABLE ((unsigned char)'\377')
97*45234Sborman # endif
98*45234Sborman #endif
99*45234Sborman 
100*45234Sborman 
10138905Sborman #ifdef	CRAY
10238905Sborman #include <sys/fcntl.h>
10338905Sborman # ifdef	CRAY1
10438905Sborman # include <sys/pty.h>
10538905Sborman #  ifndef FD_ZERO
10638905Sborman # include <sys/select.h>
10738905Sborman #  endif /* FD_ZERO */
10838905Sborman # endif	/* CRAY1 */
10938905Sborman 
11038905Sborman #include <memory.h>
11138905Sborman #endif	/* CRAY */
11238905Sborman 
11344364Sborman #if	!defined(TIOCSCTTY) && defined(TCSETCTTY)
11444364Sborman # define	TIOCSCTTY TCSETCTTY
11538905Sborman #endif
11638905Sborman 
11738905Sborman #ifndef	FD_SET
11840242Sborman #ifndef	HAVE_fd_set
11938905Sborman typedef struct fd_set { int fds_bits[1]; } fd_set;
12040242Sborman #endif
12138905Sborman 
12238905Sborman #define	FD_SET(n, p)	((p)->fds_bits[0] |= (1<<(n)))
12338905Sborman #define	FD_CLR(n, p)	((p)->fds_bits[0] &= ~(1<<(n)))
12438905Sborman #define	FD_ISSET(n, p)	((p)->fds_bits[0] & (1<<(n)))
12538905Sborman #define FD_ZERO(p)	((p)->fds_bits[0] = 0)
12638905Sborman #endif	/* FD_SET */
12738905Sborman 
12838905Sborman /*
12938905Sborman  * I/O data buffers defines
13038905Sborman  */
13138905Sborman #define	NETSLOP	64
13238905Sborman #ifdef CRAY
13338905Sborman #undef BUFSIZ
13438905Sborman #define BUFSIZ  2048
13538905Sborman #endif
13638905Sborman 
13738905Sborman #define	NIACCUM(c)	{   *netip++ = c; \
13838905Sborman 			    ncc++; \
13938905Sborman 			}
14038905Sborman 
14138905Sborman /* clock manipulations */
14238905Sborman #define	settimer(x)	(clocks.x = ++clocks.system)
14338905Sborman #define	sequenceIs(x,y)	(clocks.x < clocks.y)
14438905Sborman 
14538905Sborman /*
14638905Sborman  * Linemode support states, in decreasing order of importance
14738905Sborman  */
14838905Sborman #define REAL_LINEMODE	0x02
14938905Sborman #define KLUDGE_LINEMODE	0x01
15038905Sborman #define NO_LINEMODE	0x00
15138905Sborman 
15238905Sborman /*
15338905Sborman  * Structures of information for each special character function.
15438905Sborman  */
15538905Sborman typedef struct {
15638905Sborman 	unsigned char	flag;		/* the flags for this function */
15740242Sborman 	cc_t		val;		/* the value of the special character */
15838905Sborman } slcent, *Slcent;
15938905Sborman 
16038905Sborman typedef struct {
16138905Sborman 	slcent		defset;		/* the default settings */
16238905Sborman 	slcent		current;	/* the current settings */
16340242Sborman 	cc_t		*sptr;		/* a pointer to the char in */
16438905Sborman 					/* system data structures */
16538905Sborman } slcfun, *Slcfun;
16644364Sborman 
16744364Sborman #ifdef DIAGNOSTICS
16844364Sborman /*
16944364Sborman  * Diagnostics capabilities
17044364Sborman  */
17144364Sborman #define	TD_REPORT	0x01	/* Report operations to client */
17244364Sborman #define TD_EXERCISE	0x02	/* Exercise client's implementation */
17344364Sborman #define TD_NETDATA	0x04	/* Display received data stream */
17444364Sborman #define TD_PTYDATA	0x08	/* Display data passed to pty */
17544364Sborman #define	TD_OPTIONS	0x10	/* Report just telnet options */
17644364Sborman #endif /* DIAGNOSTICS */
17744364Sborman 
17844364Sborman /*
17944364Sborman  * We keep track of each side of the option negotiation.
18044364Sborman  */
18144364Sborman 
18244364Sborman #define	MY_STATE_WILL		0x01
18344364Sborman #define	MY_WANT_STATE_WILL	0x02
18444364Sborman #define	MY_STATE_DO		0x04
18544364Sborman #define	MY_WANT_STATE_DO	0x08
18644364Sborman 
18744364Sborman /*
18844364Sborman  * Macros to check the current state of things
18944364Sborman  */
19044364Sborman 
19144364Sborman #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
19244364Sborman #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
19344364Sborman #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
19444364Sborman #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
19544364Sborman 
19644364Sborman #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
19744364Sborman #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
19844364Sborman #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
19944364Sborman #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
20044364Sborman 
20144364Sborman #define	set_my_state_do(opt)		(options[opt] |= MY_STATE_DO)
20244364Sborman #define	set_my_state_will(opt)		(options[opt] |= MY_STATE_WILL)
20344364Sborman #define	set_my_want_state_do(opt)	(options[opt] |= MY_WANT_STATE_DO)
20444364Sborman #define	set_my_want_state_will(opt)	(options[opt] |= MY_WANT_STATE_WILL)
20544364Sborman 
20644364Sborman #define	set_my_state_dont(opt)		(options[opt] &= ~MY_STATE_DO)
20744364Sborman #define	set_my_state_wont(opt)		(options[opt] &= ~MY_STATE_WILL)
20844364Sborman #define	set_my_want_state_dont(opt)	(options[opt] &= ~MY_WANT_STATE_DO)
20944364Sborman #define	set_my_want_state_wont(opt)	(options[opt] &= ~MY_WANT_STATE_WILL)
21044364Sborman 
21144364Sborman /*
21244364Sborman  * Tricky code here.  What we want to know is if the MY_STATE_WILL
21344364Sborman  * and MY_WANT_STATE_WILL bits have the same value.  Since the two
21444364Sborman  * bits are adjacent, a little arithmatic will show that by adding
21544364Sborman  * in the lower bit, the upper bit will be set if the two bits were
21644364Sborman  * different, and clear if they were the same.
21744364Sborman  */
21844364Sborman #define my_will_wont_is_changing(opt) \
21944364Sborman 			((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
22044364Sborman 
22144364Sborman #define my_do_dont_is_changing(opt) \
22244364Sborman 			((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
22344364Sborman 
22444364Sborman /*
22544364Sborman  * Make everything symetrical
22644364Sborman  */
22744364Sborman 
22844364Sborman #define	HIS_STATE_WILL			MY_STATE_DO
22944364Sborman #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
23044364Sborman #define HIS_STATE_DO			MY_STATE_WILL
23144364Sborman #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
23244364Sborman 
23344364Sborman #define	his_state_is_do			my_state_is_will
23444364Sborman #define	his_state_is_will		my_state_is_do
23544364Sborman #define his_want_state_is_do		my_want_state_is_will
23644364Sborman #define his_want_state_is_will		my_want_state_is_do
23744364Sborman 
23844364Sborman #define	his_state_is_dont		my_state_is_wont
23944364Sborman #define	his_state_is_wont		my_state_is_dont
24044364Sborman #define his_want_state_is_dont		my_want_state_is_wont
24144364Sborman #define his_want_state_is_wont		my_want_state_is_dont
24244364Sborman 
24344364Sborman #define	set_his_state_do		set_my_state_will
24444364Sborman #define	set_his_state_will		set_my_state_do
24544364Sborman #define	set_his_want_state_do		set_my_want_state_will
24644364Sborman #define	set_his_want_state_will		set_my_want_state_do
24744364Sborman 
24844364Sborman #define	set_his_state_dont		set_my_state_wont
24944364Sborman #define	set_his_state_wont		set_my_state_dont
25044364Sborman #define	set_his_want_state_dont		set_my_want_state_wont
25144364Sborman #define	set_his_want_state_wont		set_my_want_state_dont
25244364Sborman 
25344364Sborman #define his_will_wont_is_changing	my_do_dont_is_changing
25444364Sborman #define his_do_dont_is_changing		my_will_wont_is_changing
255