xref: /original-bsd/libexec/telnetd/defs.h (revision 96caf292)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)defs.h	5.9 (Berkeley) 09/14/90
8  */
9 
10 /*
11  * Telnet server defines
12  */
13 #include <sys/types.h>
14 #include <sys/param.h>
15 
16 #ifndef	BSD
17 # define	BSD 43
18 #endif
19 
20 #if	defined(CRAY) && !defined(LINEMODE)
21 # define SYSV_TERMIO
22 # define LINEMODE
23 # define KLUDGELINEMODE
24 # define NO_GETTYTAB
25 # define DIAGNOSTICS
26 # if !defined(UNICOS5)
27 #  define BFTPDAEMON
28 #  define HAS_IP_TOS
29 # endif
30 #endif /* CRAY */
31 #if defined(UNICOS5) && !defined(NO_SETSID)
32 # define NO_SETSID
33 #endif
34 
35 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
36 #define TELOPTS
37 #define TELCMDS
38 #endif
39 
40 #if	defined(SYSV_TERMIO) && !defined(USE_TERMIO)
41 # define	USE_TERMIO
42 #endif
43 
44 #include <sys/socket.h>
45 #ifndef	CRAY
46 #include <sys/wait.h>
47 #endif	/* CRAY */
48 #include <sys/file.h>
49 #include <sys/stat.h>
50 #include <sys/time.h>
51 #ifndef	FILIO_H
52 #include <sys/ioctl.h>
53 #else
54 #include <sys/filio.h>
55 #endif
56 
57 #include <netinet/in.h>
58 
59 #include <arpa/telnet.h>
60 
61 #include <stdio.h>
62 #include <signal.h>
63 #include <errno.h>
64 #include <netdb.h>
65 #include <syslog.h>
66 #ifndef	LOG_DAEMON
67 #define	LOG_DAEMON	0
68 #endif
69 #ifndef	LOG_ODELAY
70 #define	LOG_ODELAY	0
71 #endif
72 #include <ctype.h>
73 #ifndef NO_STRING_H
74 #include <string.h>
75 #else
76 #include <strings.h>
77 #endif
78 
79 #ifndef	USE_TERMIO
80 #include <sgtty.h>
81 #else
82 # ifdef	SYSV_TERMIO
83 # include <termio.h>
84 # else
85 # include <termios.h>
86 # endif
87 #endif
88 #if !defined(USE_TERMIO) || defined(NO_CC_T)
89 typedef unsigned char cc_t;
90 #endif
91 
92 #ifndef _POSIX_VDISABLE
93 # ifdef VDISABLE
94 #  define _POSIX_VDISABLE VDISABLE
95 # else
96 #  define _POSIX_VDISABLE ((unsigned char)'\377')
97 # endif
98 #endif
99 
100 
101 #ifdef	CRAY
102 #include <sys/fcntl.h>
103 # ifdef	CRAY1
104 # include <sys/pty.h>
105 #  ifndef FD_ZERO
106 # include <sys/select.h>
107 #  endif /* FD_ZERO */
108 # endif	/* CRAY1 */
109 
110 #include <memory.h>
111 #endif	/* CRAY */
112 
113 #if	!defined(TIOCSCTTY) && defined(TCSETCTTY)
114 # define	TIOCSCTTY TCSETCTTY
115 #endif
116 
117 #ifndef	FD_SET
118 #ifndef	HAVE_fd_set
119 typedef struct fd_set { int fds_bits[1]; } fd_set;
120 #endif
121 
122 #define	FD_SET(n, p)	((p)->fds_bits[0] |= (1<<(n)))
123 #define	FD_CLR(n, p)	((p)->fds_bits[0] &= ~(1<<(n)))
124 #define	FD_ISSET(n, p)	((p)->fds_bits[0] & (1<<(n)))
125 #define FD_ZERO(p)	((p)->fds_bits[0] = 0)
126 #endif	/* FD_SET */
127 
128 /*
129  * I/O data buffers defines
130  */
131 #define	NETSLOP	64
132 #ifdef CRAY
133 #undef BUFSIZ
134 #define BUFSIZ  2048
135 #endif
136 
137 #define	NIACCUM(c)	{   *netip++ = c; \
138 			    ncc++; \
139 			}
140 
141 /* clock manipulations */
142 #define	settimer(x)	(clocks.x = ++clocks.system)
143 #define	sequenceIs(x,y)	(clocks.x < clocks.y)
144 
145 /*
146  * Linemode support states, in decreasing order of importance
147  */
148 #define REAL_LINEMODE	0x02
149 #define KLUDGE_LINEMODE	0x01
150 #define NO_LINEMODE	0x00
151 
152 /*
153  * Structures of information for each special character function.
154  */
155 typedef struct {
156 	unsigned char	flag;		/* the flags for this function */
157 	cc_t		val;		/* the value of the special character */
158 } slcent, *Slcent;
159 
160 typedef struct {
161 	slcent		defset;		/* the default settings */
162 	slcent		current;	/* the current settings */
163 	cc_t		*sptr;		/* a pointer to the char in */
164 					/* system data structures */
165 } slcfun, *Slcfun;
166 
167 #ifdef DIAGNOSTICS
168 /*
169  * Diagnostics capabilities
170  */
171 #define	TD_REPORT	0x01	/* Report operations to client */
172 #define TD_EXERCISE	0x02	/* Exercise client's implementation */
173 #define TD_NETDATA	0x04	/* Display received data stream */
174 #define TD_PTYDATA	0x08	/* Display data passed to pty */
175 #define	TD_OPTIONS	0x10	/* Report just telnet options */
176 #endif /* DIAGNOSTICS */
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  * Tricky code here.  What we want to know is if the MY_STATE_WILL
213  * and MY_WANT_STATE_WILL bits have the same value.  Since the two
214  * bits are adjacent, a little arithmatic will show that by adding
215  * in the lower bit, the upper bit will be set if the two bits were
216  * different, and clear if they were the same.
217  */
218 #define my_will_wont_is_changing(opt) \
219 			((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
220 
221 #define my_do_dont_is_changing(opt) \
222 			((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
223 
224 /*
225  * Make everything symetrical
226  */
227 
228 #define	HIS_STATE_WILL			MY_STATE_DO
229 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
230 #define HIS_STATE_DO			MY_STATE_WILL
231 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
232 
233 #define	his_state_is_do			my_state_is_will
234 #define	his_state_is_will		my_state_is_do
235 #define his_want_state_is_do		my_want_state_is_will
236 #define his_want_state_is_will		my_want_state_is_do
237 
238 #define	his_state_is_dont		my_state_is_wont
239 #define	his_state_is_wont		my_state_is_dont
240 #define his_want_state_is_dont		my_want_state_is_wont
241 #define his_want_state_is_wont		my_want_state_is_dont
242 
243 #define	set_his_state_do		set_my_state_will
244 #define	set_his_state_will		set_my_state_do
245 #define	set_his_want_state_do		set_my_want_state_will
246 #define	set_his_want_state_will		set_my_want_state_do
247 
248 #define	set_his_state_dont		set_my_state_wont
249 #define	set_his_state_wont		set_my_state_dont
250 #define	set_his_want_state_dont		set_my_want_state_wont
251 #define	set_his_want_state_wont		set_my_want_state_dont
252 
253 #define his_will_wont_is_changing	my_do_dont_is_changing
254 #define his_do_dont_is_changing		my_will_wont_is_changing
255