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