xref: /csrg-svn/libexec/telnetd/defs.h (revision 44364)
138905Sborman /*
238905Sborman  * Copyright (c) 1989 The Regents of the University of California.
338905Sborman  * All rights reserved.
438905Sborman  *
542673Sbostic  * %sccs.include.redist.c%
638905Sborman  *
7*44364Sborman  *	@(#)defs.h	5.8 (Berkeley) 06/28/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 
20*44364Sborman #if	defined(CRAY) && !defined(LINEMODE)
21*44364Sborman # define SYSV_TERMIO
22*44364Sborman # define LINEMODE
23*44364Sborman # define KLUDGELINEMODE
24*44364Sborman # define NO_GETTYTAB
25*44364Sborman # define DIAGNOSTICS
26*44364Sborman # if !defined(UNICOS5)
27*44364Sborman #  define BFTPDAEMON
28*44364Sborman #  define HAS_IP_TOS
29*44364Sborman # endif
30*44364Sborman #endif /* CRAY */
31*44364Sborman #if defined(UNICOS5) && !defined(NO_SETSID)
32*44364Sborman # define NO_SETSID
3338905Sborman #endif
3438905Sborman 
35*44364Sborman #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
36*44364Sborman #define TELOPTS
37*44364Sborman #define TELCMDS
38*44364Sborman #endif
3938905Sborman 
40*44364Sborman #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>
51*44364Sborman #ifndef	FILIO_H
5239503Sborman #include <sys/ioctl.h>
53*44364Sborman #else
54*44364Sborman #include <sys/filio.h>
55*44364Sborman #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>
73*44364Sborman #ifndef NO_STRING_H
7442029Sbostic #include <string.h>
75*44364Sborman #else
76*44364Sborman #include <strings.h>
77*44364Sborman #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
88*44364Sborman #if !defined(USE_TERMIO) || defined(NO_CC_T)
89*44364Sborman typedef unsigned char cc_t;
90*44364Sborman #endif
9138905Sborman 
9238905Sborman #ifdef	CRAY
9338905Sborman #include <sys/fcntl.h>
9438905Sborman # ifdef	CRAY1
9538905Sborman # include <sys/pty.h>
9638905Sborman #  ifndef FD_ZERO
9738905Sborman # include <sys/select.h>
9838905Sborman #  endif /* FD_ZERO */
9938905Sborman # endif	/* CRAY1 */
10038905Sborman 
10138905Sborman #include <memory.h>
10238905Sborman #endif	/* CRAY */
10338905Sborman 
104*44364Sborman #if	!defined(TIOCSCTTY) && defined(TCSETCTTY)
105*44364Sborman # define	TIOCSCTTY TCSETCTTY
10638905Sborman #endif
10738905Sborman 
10838905Sborman #ifndef	FD_SET
10940242Sborman #ifndef	HAVE_fd_set
11038905Sborman typedef struct fd_set { int fds_bits[1]; } fd_set;
11140242Sborman #endif
11238905Sborman 
11338905Sborman #define	FD_SET(n, p)	((p)->fds_bits[0] |= (1<<(n)))
11438905Sborman #define	FD_CLR(n, p)	((p)->fds_bits[0] &= ~(1<<(n)))
11538905Sborman #define	FD_ISSET(n, p)	((p)->fds_bits[0] & (1<<(n)))
11638905Sborman #define FD_ZERO(p)	((p)->fds_bits[0] = 0)
11738905Sborman #endif	/* FD_SET */
11838905Sborman 
11938905Sborman /*
12038905Sborman  * I/O data buffers defines
12138905Sborman  */
12238905Sborman #define	NETSLOP	64
12338905Sborman #ifdef CRAY
12438905Sborman #undef BUFSIZ
12538905Sborman #define BUFSIZ  2048
12638905Sborman #endif
12738905Sborman 
12838905Sborman #define	NIACCUM(c)	{   *netip++ = c; \
12938905Sborman 			    ncc++; \
13038905Sborman 			}
13138905Sborman 
13238905Sborman /* clock manipulations */
13338905Sborman #define	settimer(x)	(clocks.x = ++clocks.system)
13438905Sborman #define	sequenceIs(x,y)	(clocks.x < clocks.y)
13538905Sborman 
13638905Sborman /*
13738905Sborman  * Linemode support states, in decreasing order of importance
13838905Sborman  */
13938905Sborman #define REAL_LINEMODE	0x02
14038905Sborman #define KLUDGE_LINEMODE	0x01
14138905Sborman #define NO_LINEMODE	0x00
14238905Sborman 
14338905Sborman /*
14438905Sborman  * Structures of information for each special character function.
14538905Sborman  */
14638905Sborman typedef struct {
14738905Sborman 	unsigned char	flag;		/* the flags for this function */
14840242Sborman 	cc_t		val;		/* the value of the special character */
14938905Sborman } slcent, *Slcent;
15038905Sborman 
15138905Sborman typedef struct {
15238905Sborman 	slcent		defset;		/* the default settings */
15338905Sborman 	slcent		current;	/* the current settings */
15440242Sborman 	cc_t		*sptr;		/* a pointer to the char in */
15538905Sborman 					/* system data structures */
15638905Sborman } slcfun, *Slcfun;
157*44364Sborman 
158*44364Sborman #ifdef DIAGNOSTICS
159*44364Sborman /*
160*44364Sborman  * Diagnostics capabilities
161*44364Sborman  */
162*44364Sborman #define	TD_REPORT	0x01	/* Report operations to client */
163*44364Sborman #define TD_EXERCISE	0x02	/* Exercise client's implementation */
164*44364Sborman #define TD_NETDATA	0x04	/* Display received data stream */
165*44364Sborman #define TD_PTYDATA	0x08	/* Display data passed to pty */
166*44364Sborman #define	TD_OPTIONS	0x10	/* Report just telnet options */
167*44364Sborman #endif /* DIAGNOSTICS */
168*44364Sborman 
169*44364Sborman /*
170*44364Sborman  * We keep track of each side of the option negotiation.
171*44364Sborman  */
172*44364Sborman 
173*44364Sborman #define	MY_STATE_WILL		0x01
174*44364Sborman #define	MY_WANT_STATE_WILL	0x02
175*44364Sborman #define	MY_STATE_DO		0x04
176*44364Sborman #define	MY_WANT_STATE_DO	0x08
177*44364Sborman 
178*44364Sborman /*
179*44364Sborman  * Macros to check the current state of things
180*44364Sborman  */
181*44364Sborman 
182*44364Sborman #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
183*44364Sborman #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
184*44364Sborman #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
185*44364Sborman #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
186*44364Sborman 
187*44364Sborman #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
188*44364Sborman #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
189*44364Sborman #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
190*44364Sborman #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
191*44364Sborman 
192*44364Sborman #define	set_my_state_do(opt)		(options[opt] |= MY_STATE_DO)
193*44364Sborman #define	set_my_state_will(opt)		(options[opt] |= MY_STATE_WILL)
194*44364Sborman #define	set_my_want_state_do(opt)	(options[opt] |= MY_WANT_STATE_DO)
195*44364Sborman #define	set_my_want_state_will(opt)	(options[opt] |= MY_WANT_STATE_WILL)
196*44364Sborman 
197*44364Sborman #define	set_my_state_dont(opt)		(options[opt] &= ~MY_STATE_DO)
198*44364Sborman #define	set_my_state_wont(opt)		(options[opt] &= ~MY_STATE_WILL)
199*44364Sborman #define	set_my_want_state_dont(opt)	(options[opt] &= ~MY_WANT_STATE_DO)
200*44364Sborman #define	set_my_want_state_wont(opt)	(options[opt] &= ~MY_WANT_STATE_WILL)
201*44364Sborman 
202*44364Sborman /*
203*44364Sborman  * Tricky code here.  What we want to know is if the MY_STATE_WILL
204*44364Sborman  * and MY_WANT_STATE_WILL bits have the same value.  Since the two
205*44364Sborman  * bits are adjacent, a little arithmatic will show that by adding
206*44364Sborman  * in the lower bit, the upper bit will be set if the two bits were
207*44364Sborman  * different, and clear if they were the same.
208*44364Sborman  */
209*44364Sborman #define my_will_wont_is_changing(opt) \
210*44364Sborman 			((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
211*44364Sborman 
212*44364Sborman #define my_do_dont_is_changing(opt) \
213*44364Sborman 			((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
214*44364Sborman 
215*44364Sborman /*
216*44364Sborman  * Make everything symetrical
217*44364Sborman  */
218*44364Sborman 
219*44364Sborman #define	HIS_STATE_WILL			MY_STATE_DO
220*44364Sborman #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
221*44364Sborman #define HIS_STATE_DO			MY_STATE_WILL
222*44364Sborman #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
223*44364Sborman 
224*44364Sborman #define	his_state_is_do			my_state_is_will
225*44364Sborman #define	his_state_is_will		my_state_is_do
226*44364Sborman #define his_want_state_is_do		my_want_state_is_will
227*44364Sborman #define his_want_state_is_will		my_want_state_is_do
228*44364Sborman 
229*44364Sborman #define	his_state_is_dont		my_state_is_wont
230*44364Sborman #define	his_state_is_wont		my_state_is_dont
231*44364Sborman #define his_want_state_is_dont		my_want_state_is_wont
232*44364Sborman #define his_want_state_is_wont		my_want_state_is_dont
233*44364Sborman 
234*44364Sborman #define	set_his_state_do		set_my_state_will
235*44364Sborman #define	set_his_state_will		set_my_state_do
236*44364Sborman #define	set_his_want_state_do		set_my_want_state_will
237*44364Sborman #define	set_his_want_state_will		set_my_want_state_do
238*44364Sborman 
239*44364Sborman #define	set_his_state_dont		set_my_state_wont
240*44364Sborman #define	set_his_state_wont		set_my_state_dont
241*44364Sborman #define	set_his_want_state_dont		set_my_want_state_wont
242*44364Sborman #define	set_his_want_state_wont		set_my_want_state_dont
243*44364Sborman 
244*44364Sborman #define his_will_wont_is_changing	my_do_dont_is_changing
245*44364Sborman #define his_do_dont_is_changing		my_will_wont_is_changing
246