defs.h revision 1.2 1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)defs.h 5.10 (Berkeley) 3/1/91
34 * $Id: defs.h,v 1.2 1993/08/01 18:29:25 mycroft Exp $
35 */
36
37 /*
38 * Telnet server defines
39 */
40 #include <sys/types.h>
41 #include <sys/param.h>
42
43 #ifndef BSD
44 # define BSD 43
45 #endif
46
47 #if defined(CRAY) && !defined(LINEMODE)
48 # define SYSV_TERMIO
49 # define LINEMODE
50 # define KLUDGELINEMODE
51 # define DIAGNOSTICS
52 # if defined(UNICOS50) && !defined(UNICOS5)
53 # define UNICOS5
54 # endif
55 # if !defined(UNICOS5)
56 # define BFTPDAEMON
57 # define HAS_IP_TOS
58 # endif
59 #endif /* CRAY */
60 #if defined(UNICOS5) && !defined(NO_SETSID)
61 # define NO_SETSID
62 #endif
63
64 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
65 #define TELOPTS
66 #define TELCMDS
67 #define SLC_NAMES
68 #endif
69
70 #if defined(SYSV_TERMIO) && !defined(USE_TERMIO)
71 # define USE_TERMIO
72 #endif
73
74 #include <sys/socket.h>
75 #ifndef CRAY
76 #include <sys/wait.h>
77 #endif /* CRAY */
78 #include <fcntl.h>
79 #include <sys/file.h>
80 #include <sys/stat.h>
81 #include <sys/time.h>
82 #ifndef FILIO_H
83 #include <sys/ioctl.h>
84 #else
85 #include <sys/filio.h>
86 #endif
87
88 #include <netinet/in.h>
89
90 #include <arpa/telnet.h>
91
92 #include <stdio.h>
93 #ifdef __STDC__
94 #include <stdlib.h>
95 #endif
96 #include <signal.h>
97 #include <errno.h>
98 #include <netdb.h>
99 #include <syslog.h>
100 #ifndef LOG_DAEMON
101 #define LOG_DAEMON 0
102 #endif
103 #ifndef LOG_ODELAY
104 #define LOG_ODELAY 0
105 #endif
106 #include <ctype.h>
107 #ifndef NO_STRING_H
108 #include <string.h>
109 #else
110 #include <strings.h>
111 #endif
112
113 #ifndef USE_TERMIO
114 #include <sgtty.h>
115 #else
116 # ifdef SYSV_TERMIO
117 # include <termio.h>
118 # else
119 # include <termios.h>
120 # endif
121 #endif
122 #if !defined(USE_TERMIO) || defined(NO_CC_T)
123 typedef unsigned char cc_t;
124 #endif
125
126 #ifdef __STDC__
127 #include <unistd.h>
128 #endif
129
130 #ifndef _POSIX_VDISABLE
131 # ifdef VDISABLE
132 # define _POSIX_VDISABLE VDISABLE
133 # else
134 # define _POSIX_VDISABLE ((unsigned char)'\377')
135 # endif
136 #endif
137
138
139 #ifdef CRAY
140 # ifdef CRAY1
141 # include <sys/pty.h>
142 # ifndef FD_ZERO
143 # include <sys/select.h>
144 # endif /* FD_ZERO */
145 # endif /* CRAY1 */
146
147 #include <memory.h>
148 #endif /* CRAY */
149
150 #if !defined(TIOCSCTTY) && defined(TCSETCTTY)
151 # define TIOCSCTTY TCSETCTTY
152 #endif
153
154 #ifndef FD_SET
155 #ifndef HAVE_fd_set
156 typedef struct fd_set { int fds_bits[1]; } fd_set;
157 #endif
158
159 #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
160 #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
161 #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
162 #define FD_ZERO(p) ((p)->fds_bits[0] = 0)
163 #endif /* FD_SET */
164
165 /*
166 * I/O data buffers defines
167 */
168 #define NETSLOP 64
169 #ifdef CRAY
170 #undef BUFSIZ
171 #define BUFSIZ 2048
172 #endif
173
174 #define NIACCUM(c) { *netip++ = c; \
175 ncc++; \
176 }
177
178 /* clock manipulations */
179 #define settimer(x) (clocks.x = ++clocks.system)
180 #define sequenceIs(x,y) (clocks.x < clocks.y)
181
182 /*
183 * Linemode support states, in decreasing order of importance
184 */
185 #define REAL_LINEMODE 0x02
186 #define KLUDGE_LINEMODE 0x01
187 #define NO_LINEMODE 0x00
188
189 /*
190 * Structures of information for each special character function.
191 */
192 typedef struct {
193 unsigned char flag; /* the flags for this function */
194 cc_t val; /* the value of the special character */
195 } slcent, *Slcent;
196
197 typedef struct {
198 slcent defset; /* the default settings */
199 slcent current; /* the current settings */
200 cc_t *sptr; /* a pointer to the char in */
201 /* system data structures */
202 } slcfun, *Slcfun;
203
204 #ifdef DIAGNOSTICS
205 /*
206 * Diagnostics capabilities
207 */
208 #define TD_REPORT 0x01 /* Report operations to client */
209 #define TD_EXERCISE 0x02 /* Exercise client's implementation */
210 #define TD_NETDATA 0x04 /* Display received data stream */
211 #define TD_PTYDATA 0x08 /* Display data passed to pty */
212 #define TD_OPTIONS 0x10 /* Report just telnet options */
213 #endif /* DIAGNOSTICS */
214
215 /*
216 * We keep track of each side of the option negotiation.
217 */
218
219 #define MY_STATE_WILL 0x01
220 #define MY_WANT_STATE_WILL 0x02
221 #define MY_STATE_DO 0x04
222 #define MY_WANT_STATE_DO 0x08
223
224 /*
225 * Macros to check the current state of things
226 */
227
228 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
229 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
230 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
231 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
232
233 #define my_state_is_dont(opt) (!my_state_is_do(opt))
234 #define my_state_is_wont(opt) (!my_state_is_will(opt))
235 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
236 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
237
238 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
239 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
240 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
241 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
242
243 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
244 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
245 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
246 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
247
248 /*
249 * Tricky code here. What we want to know is if the MY_STATE_WILL
250 * and MY_WANT_STATE_WILL bits have the same value. Since the two
251 * bits are adjacent, a little arithmatic will show that by adding
252 * in the lower bit, the upper bit will be set if the two bits were
253 * different, and clear if they were the same.
254 */
255 #define my_will_wont_is_changing(opt) \
256 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
257
258 #define my_do_dont_is_changing(opt) \
259 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
260
261 /*
262 * Make everything symetrical
263 */
264
265 #define HIS_STATE_WILL MY_STATE_DO
266 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
267 #define HIS_STATE_DO MY_STATE_WILL
268 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
269
270 #define his_state_is_do my_state_is_will
271 #define his_state_is_will my_state_is_do
272 #define his_want_state_is_do my_want_state_is_will
273 #define his_want_state_is_will my_want_state_is_do
274
275 #define his_state_is_dont my_state_is_wont
276 #define his_state_is_wont my_state_is_dont
277 #define his_want_state_is_dont my_want_state_is_wont
278 #define his_want_state_is_wont my_want_state_is_dont
279
280 #define set_his_state_do set_my_state_will
281 #define set_his_state_will set_my_state_do
282 #define set_his_want_state_do set_my_want_state_will
283 #define set_his_want_state_will set_my_want_state_do
284
285 #define set_his_state_dont set_my_state_wont
286 #define set_his_state_wont set_my_state_dont
287 #define set_his_want_state_dont set_my_want_state_wont
288 #define set_his_want_state_wont set_my_want_state_dont
289
290 #define his_will_wont_is_changing my_do_dont_is_changing
291 #define his_do_dont_is_changing my_will_wont_is_changing
292