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