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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)defs.h 8.1 (Berkeley) 6/4/93
30 * $FreeBSD: src/crypto/telnet/telnetd/defs.h,v 1.1.1.1.8.1 2002/04/13 10:59:08 markm Exp $
34 * Telnet server defines
36 #include <sys/types.h>
37 #include <sys/param.h>
43 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
49 #if defined(SYSV_TERMIO) && !defined(USE_TERMIO)
53 #include <sys/socket.h>
60 #include <sys/ioctl.h>
62 #include <sys/filio.h>
65 #include <netinet/in.h>
67 #include <arpa/telnet.h>
94 #if !defined(USE_TERMIO) || defined(NO_CC_T)
95 typedef unsigned char cc_t;
100 #ifndef _POSIX_VDISABLE
102 # define _POSIX_VDISABLE VDISABLE
104 # define _POSIX_VDISABLE ((unsigned char)'\377')
108 #if !defined(TIOCSCTTY) && defined(TCSETCTTY)
109 # define TIOCSCTTY TCSETCTTY
114 typedef struct fd_set { int fds_bits[1]; } fd_set;
117 #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
118 #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
119 #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
120 #define FD_ZERO(p) ((p)->fds_bits[0] = 0)
124 * I/O data buffers defines
128 #define NIACCUM(c) { *netip++ = c; \
132 /* clock manipulations */
133 #define settimer(x) (clocks.x = ++clocks.system)
134 #define sequenceIs(x,y) (clocks.x < clocks.y)
137 * Linemode support states, in decreasing order of importance
139 #define REAL_LINEMODE 0x04
140 #define KLUDGE_OK 0x03
141 #define NO_AUTOKLUDGE 0x02
142 #define KLUDGE_LINEMODE 0x01
143 #define NO_LINEMODE 0x00
146 * Structures of information for each special character function.
149 unsigned char flag; /* the flags for this function */
150 cc_t val; /* the value of the special character */
154 slcent defset; /* the default settings */
155 slcent current; /* the current settings */
156 cc_t *sptr; /* a pointer to the char in */
157 /* system data structures */
162 * Diagnostics capabilities
164 #define TD_REPORT 0x01 /* Report operations to client */
165 #define TD_EXERCISE 0x02 /* Exercise client's implementation */
166 #define TD_NETDATA 0x04 /* Display received data stream */
167 #define TD_PTYDATA 0x08 /* Display data passed to pty */
168 #define TD_OPTIONS 0x10 /* Report just telnet options */
169 #endif /* DIAGNOSTICS */
172 * We keep track of each side of the option negotiation.
175 #define MY_STATE_WILL 0x01
176 #define MY_WANT_STATE_WILL 0x02
177 #define MY_STATE_DO 0x04
178 #define MY_WANT_STATE_DO 0x08
181 * Macros to check the current state of things
184 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
185 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
186 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
187 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
189 #define my_state_is_dont(opt) (!my_state_is_do(opt))
190 #define my_state_is_wont(opt) (!my_state_is_will(opt))
191 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
192 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
194 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
195 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
196 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
197 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
199 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
200 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
201 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
202 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
205 * Tricky code here. What we want to know is if the MY_STATE_WILL
206 * and MY_WANT_STATE_WILL bits have the same value. Since the two
207 * bits are adjacent, a little arithmatic will show that by adding
208 * in the lower bit, the upper bit will be set if the two bits were
209 * different, and clear if they were the same.
211 #define my_will_wont_is_changing(opt) \
212 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
214 #define my_do_dont_is_changing(opt) \
215 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
218 * Make everything symetrical
221 #define HIS_STATE_WILL MY_STATE_DO
222 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
223 #define HIS_STATE_DO MY_STATE_WILL
224 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
226 #define his_state_is_do my_state_is_will
227 #define his_state_is_will my_state_is_do
228 #define his_want_state_is_do my_want_state_is_will
229 #define his_want_state_is_will my_want_state_is_do
231 #define his_state_is_dont my_state_is_wont
232 #define his_state_is_wont my_state_is_dont
233 #define his_want_state_is_dont my_want_state_is_wont
234 #define his_want_state_is_wont my_want_state_is_dont
236 #define set_his_state_do set_my_state_will
237 #define set_his_state_will set_my_state_do
238 #define set_his_want_state_do set_my_want_state_will
239 #define set_his_want_state_will set_my_want_state_do
241 #define set_his_state_dont set_my_state_wont
242 #define set_his_state_wont set_my_state_dont
243 #define set_his_want_state_dont set_my_want_state_wont
244 #define set_his_want_state_wont set_my_want_state_dont
246 #define his_will_wont_is_changing my_do_dont_is_changing
247 #define his_do_dont_is_changing my_will_wont_is_changing