defs.h revision 1.10 1 /* $NetBSD: defs.h,v 1.10 2001/08/24 00:14:03 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 #ifdef __STDC__
87 #include <stdlib.h>
88 #endif
89 #include <signal.h>
90 #include <errno.h>
91 #include <netdb.h>
92 #include <syslog.h>
93 #ifndef LOG_DAEMON
94 #define LOG_DAEMON 0
95 #endif
96 #ifndef LOG_ODELAY
97 #define LOG_ODELAY 0
98 #endif
99 #include <ctype.h>
100 #ifndef NO_STRING_H
101 #include <string.h>
102 #else
103 #include <strings.h>
104 #endif
105
106 #ifndef USE_TERMIO
107 #include <sgtty.h>
108 #else
109 # ifdef SYSV_TERMIO
110 # include <termio.h>
111 # else
112 # include <termios.h>
113 # endif
114 #endif
115 #if !defined(USE_TERMIO) || defined(NO_CC_T)
116 typedef unsigned char cc_t;
117 #endif
118
119 #include <time.h>
120
121 #ifdef __STDC__
122 #include <unistd.h>
123 #endif
124
125 #ifndef _POSIX_VDISABLE
126 # ifdef VDISABLE
127 # define _POSIX_VDISABLE VDISABLE
128 # else
129 # define _POSIX_VDISABLE ((unsigned char)'\377')
130 # endif
131 #endif
132
133
134 #ifdef CRAY
135 #include <memory.h>
136 #endif /* CRAY */
137
138 #ifdef __hpux
139 #include <sys/ptyio.h>
140 #endif
141
142 #if !defined(TIOCSCTTY) && defined(TCSETCTTY)
143 # define TIOCSCTTY TCSETCTTY
144 #endif
145
146 #ifndef FD_SET
147 #ifndef HAVE_fd_set
148 typedef struct fd_set { int fds_bits[1]; } fd_set;
149 #endif
150
151 #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
152 #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
153 #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
154 #define FD_ZERO(p) ((p)->fds_bits[0] = 0)
155 #endif /* FD_SET */
156
157 /*
158 * I/O data buffers defines
159 */
160 #define NETSLOP 64
161 #ifdef CRAY
162 #undef BUFSIZ
163 #define BUFSIZ 2048
164 #endif
165
166 #define NIACCUM(c) { *netip++ = c; \
167 ncc++; \
168 }
169
170 /* clock manipulations */
171 #define settimer(x) (clocks.x = ++clocks.system)
172 #define sequenceIs(x,y) (clocks.x < clocks.y)
173
174 /*
175 * Linemode support states, in decreasing order of importance
176 */
177 #define REAL_LINEMODE 0x04
178 #define KLUDGE_OK 0x03
179 #define NO_AUTOKLUDGE 0x02
180 #define KLUDGE_LINEMODE 0x01
181 #define NO_LINEMODE 0x00
182
183 /*
184 * Structures of information for each special character function.
185 */
186 typedef struct {
187 unsigned char flag; /* the flags for this function */
188 cc_t val; /* the value of the special character */
189 } slcent, *Slcent;
190
191 typedef struct {
192 slcent defset; /* the default settings */
193 slcent current; /* the current settings */
194 cc_t *sptr; /* a pointer to the char in */
195 /* system data structures */
196 } slcfun, *Slcfun;
197
198 #ifdef DIAGNOSTICS
199 /*
200 * Diagnostics capabilities
201 */
202 #define TD_REPORT 0x01 /* Report operations to client */
203 #define TD_EXERCISE 0x02 /* Exercise client's implementation */
204 #define TD_NETDATA 0x04 /* Display received data stream */
205 #define TD_PTYDATA 0x08 /* Display data passed to pty */
206 #define TD_OPTIONS 0x10 /* Report just telnet options */
207 #endif /* DIAGNOSTICS */
208
209 /*
210 * We keep track of each side of the option negotiation.
211 */
212
213 #define MY_STATE_WILL 0x01
214 #define MY_WANT_STATE_WILL 0x02
215 #define MY_STATE_DO 0x04
216 #define MY_WANT_STATE_DO 0x08
217
218 /*
219 * Macros to check the current state of things
220 */
221
222 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
223 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
224 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
225 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
226
227 #define my_state_is_dont(opt) (!my_state_is_do(opt))
228 #define my_state_is_wont(opt) (!my_state_is_will(opt))
229 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
230 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
231
232 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
233 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
234 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
235 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
236
237 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
238 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
239 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
240 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
241
242 /*
243 * Tricky code here. What we want to know is if the MY_STATE_WILL
244 * and MY_WANT_STATE_WILL bits have the same value. Since the two
245 * bits are adjacent, a little arithmatic will show that by adding
246 * in the lower bit, the upper bit will be set if the two bits were
247 * different, and clear if they were the same.
248 */
249 #define my_will_wont_is_changing(opt) \
250 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
251
252 #define my_do_dont_is_changing(opt) \
253 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
254
255 /*
256 * Make everything symmetrical
257 */
258
259 #define HIS_STATE_WILL MY_STATE_DO
260 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
261 #define HIS_STATE_DO MY_STATE_WILL
262 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
263
264 #define his_state_is_do my_state_is_will
265 #define his_state_is_will my_state_is_do
266 #define his_want_state_is_do my_want_state_is_will
267 #define his_want_state_is_will my_want_state_is_do
268
269 #define his_state_is_dont my_state_is_wont
270 #define his_state_is_wont my_state_is_dont
271 #define his_want_state_is_dont my_want_state_is_wont
272 #define his_want_state_is_wont my_want_state_is_dont
273
274 #define set_his_state_do set_my_state_will
275 #define set_his_state_will set_my_state_do
276 #define set_his_want_state_do set_my_want_state_will
277 #define set_his_want_state_will set_my_want_state_do
278
279 #define set_his_state_dont set_my_state_wont
280 #define set_his_state_wont set_my_state_dont
281 #define set_his_want_state_dont set_my_want_state_wont
282 #define set_his_want_state_wont set_my_want_state_dont
283
284 #define his_will_wont_is_changing my_do_dont_is_changing
285 #define his_do_dont_is_changing my_will_wont_is_changing
286
287 /*
288 * Initialization buffer for tty device [16 characters long]
289 */
290 #define NULL16STR "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
291