2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 * @(#)defs.h 8.1 (Berkeley) 6/4/93
34 * $FreeBSD: src/libexec/telnetd/defs.h,v 1.1.1.1.14.1 2002/04/13 11:07:12 markm Exp $
35 * $DragonFly: src/libexec/telnetd/defs.h,v 1.2 2003/06/17 04:27:08 dillon Exp $
39 * Telnet server defines
41 #include <sys/types.h>
42 #include <sys/param.h>
48 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
54 #if defined(SYSV_TERMIO) && !defined(USE_TERMIO)
58 #include <sys/socket.h>
65 #include <sys/ioctl.h>
67 #include <sys/filio.h>
70 #include <netinet/in.h>
72 #include <arpa/telnet.h>
101 # include <termios.h>
104 #if !defined(USE_TERMIO) || defined(NO_CC_T)
105 typedef unsigned char cc_t;
112 #ifndef _POSIX_VDISABLE
114 # define _POSIX_VDISABLE VDISABLE
116 # define _POSIX_VDISABLE ((unsigned char)'\377')
120 #if !defined(TIOCSCTTY) && defined(TCSETCTTY)
121 # define TIOCSCTTY TCSETCTTY
126 typedef struct fd_set { int fds_bits[1]; } fd_set;
129 #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
130 #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
131 #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
132 #define FD_ZERO(p) ((p)->fds_bits[0] = 0)
136 * I/O data buffers defines
140 #define NIACCUM(c) { *netip++ = c; \
144 /* clock manipulations */
145 #define settimer(x) (clocks.x = ++clocks.system)
146 #define sequenceIs(x,y) (clocks.x < clocks.y)
149 * Linemode support states, in decreasing order of importance
151 #define REAL_LINEMODE 0x04
152 #define KLUDGE_OK 0x03
153 #define NO_AUTOKLUDGE 0x02
154 #define KLUDGE_LINEMODE 0x01
155 #define NO_LINEMODE 0x00
158 * Structures of information for each special character function.
161 unsigned char flag; /* the flags for this function */
162 cc_t val; /* the value of the special character */
166 slcent defset; /* the default settings */
167 slcent current; /* the current settings */
168 cc_t *sptr; /* a pointer to the char in */
169 /* system data structures */
174 * Diagnostics capabilities
176 #define TD_REPORT 0x01 /* Report operations to client */
177 #define TD_EXERCISE 0x02 /* Exercise client's implementation */
178 #define TD_NETDATA 0x04 /* Display received data stream */
179 #define TD_PTYDATA 0x08 /* Display data passed to pty */
180 #define TD_OPTIONS 0x10 /* Report just telnet options */
181 #endif /* DIAGNOSTICS */
184 * We keep track of each side of the option negotiation.
187 #define MY_STATE_WILL 0x01
188 #define MY_WANT_STATE_WILL 0x02
189 #define MY_STATE_DO 0x04
190 #define MY_WANT_STATE_DO 0x08
193 * Macros to check the current state of things
196 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
197 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
198 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
199 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
201 #define my_state_is_dont(opt) (!my_state_is_do(opt))
202 #define my_state_is_wont(opt) (!my_state_is_will(opt))
203 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
204 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
206 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
207 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
208 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
209 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
211 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
212 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
213 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
214 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
217 * Tricky code here. What we want to know is if the MY_STATE_WILL
218 * and MY_WANT_STATE_WILL bits have the same value. Since the two
219 * bits are adjacent, a little arithmatic will show that by adding
220 * in the lower bit, the upper bit will be set if the two bits were
221 * different, and clear if they were the same.
223 #define my_will_wont_is_changing(opt) \
224 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
226 #define my_do_dont_is_changing(opt) \
227 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
230 * Make everything symetrical
233 #define HIS_STATE_WILL MY_STATE_DO
234 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
235 #define HIS_STATE_DO MY_STATE_WILL
236 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
238 #define his_state_is_do my_state_is_will
239 #define his_state_is_will my_state_is_do
240 #define his_want_state_is_do my_want_state_is_will
241 #define his_want_state_is_will my_want_state_is_do
243 #define his_state_is_dont my_state_is_wont
244 #define his_state_is_wont my_state_is_dont
245 #define his_want_state_is_dont my_want_state_is_wont
246 #define his_want_state_is_wont my_want_state_is_dont
248 #define set_his_state_do set_my_state_will
249 #define set_his_state_will set_my_state_do
250 #define set_his_want_state_do set_my_want_state_will
251 #define set_his_want_state_will set_my_want_state_do
253 #define set_his_state_dont set_my_state_wont
254 #define set_his_state_wont set_my_state_dont
255 #define set_his_want_state_dont set_my_want_state_wont
256 #define set_his_want_state_wont set_my_want_state_dont
258 #define his_will_wont_is_changing my_do_dont_is_changing
259 #define his_do_dont_is_changing my_will_wont_is_changing