sbin/*hammer: Use typedef'd for struct cache_info*
[dragonfly.git] / libexec / telnetd / defs.h
blobe1ef6d560e9a0ecfa7d4055c1cc46151941e3db1
1 /*
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
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. 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
27 * SUCH DAMAGE.
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 $
31 * $DragonFly: src/crypto/telnet/telnetd/defs.h,v 1.2 2003/06/17 04:24:37 dillon Exp $
35 * Telnet server defines
37 #include <sys/types.h>
38 #include <sys/param.h>
40 #ifndef BSD
41 # define BSD 43
42 #endif
44 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
45 #define TELOPTS
46 #define TELCMDS
47 #define SLC_NAMES
48 #endif
50 #if defined(SYSV_TERMIO) && !defined(USE_TERMIO)
51 # define USE_TERMIO
52 #endif
54 #include <sys/socket.h>
55 #include <sys/wait.h>
56 #include <fcntl.h>
57 #include <sys/file.h>
58 #include <sys/stat.h>
59 #include <sys/time.h>
60 #ifndef FILIO_H
61 #include <sys/ioctl.h>
62 #else
63 #include <sys/filio.h>
64 #endif
66 #include <netinet/in.h>
68 #include <arpa/telnet.h>
70 #include <stdio.h>
71 #ifdef __STDC__
72 #include <stdlib.h>
73 #endif
74 #include <signal.h>
75 #include <errno.h>
76 #include <netdb.h>
77 #include <syslog.h>
78 #ifndef LOG_DAEMON
79 #define LOG_DAEMON 0
80 #endif
81 #ifndef LOG_ODELAY
82 #define LOG_ODELAY 0
83 #endif
84 #include <ctype.h>
85 #ifndef NO_STRING_H
86 #include <string.h>
87 #else
88 #include <strings.h>
89 #endif
91 #ifndef USE_TERMIO
92 #include <sgtty.h>
93 #else
94 # ifdef SYSV_TERMIO
95 # include <termio.h>
96 # else
97 # include <termios.h>
98 # endif
99 #endif
100 #if !defined(USE_TERMIO) || defined(NO_CC_T)
101 typedef unsigned char cc_t;
102 #endif
104 #ifdef __STDC__
105 #include <unistd.h>
106 #endif
108 #ifndef _POSIX_VDISABLE
109 # ifdef VDISABLE
110 # define _POSIX_VDISABLE VDISABLE
111 # else
112 # define _POSIX_VDISABLE ((unsigned char)'\377')
113 # endif
114 #endif
116 #if !defined(TIOCSCTTY) && defined(TCSETCTTY)
117 # define TIOCSCTTY TCSETCTTY
118 #endif
120 #ifndef FD_SET
121 #ifndef HAVE_fd_set
122 typedef struct fd_set { int fds_bits[1]; } fd_set;
123 #endif
125 #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
126 #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
127 #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
128 #define FD_ZERO(p) ((p)->fds_bits[0] = 0)
129 #endif /* FD_SET */
132 * I/O data buffers defines
134 #define NETSLOP 64
136 #define NIACCUM(c) { *netip++ = c; \
137 ncc++; \
140 /* clock manipulations */
141 #define settimer(x) (clocks.x = ++clocks.system)
142 #define sequenceIs(x,y) (clocks.x < clocks.y)
145 * Linemode support states, in decreasing order of importance
147 #define REAL_LINEMODE 0x04
148 #define KLUDGE_OK 0x03
149 #define NO_AUTOKLUDGE 0x02
150 #define KLUDGE_LINEMODE 0x01
151 #define NO_LINEMODE 0x00
154 * Structures of information for each special character function.
156 typedef struct {
157 unsigned char flag; /* the flags for this function */
158 cc_t val; /* the value of the special character */
159 } slcent, *Slcent;
161 typedef struct {
162 slcent defset; /* the default settings */
163 slcent current; /* the current settings */
164 cc_t *sptr; /* a pointer to the char in */
165 /* system data structures */
166 } slcfun, *Slcfun;
168 #ifdef DIAGNOSTICS
170 * Diagnostics capabilities
172 #define TD_REPORT 0x01 /* Report operations to client */
173 #define TD_EXERCISE 0x02 /* Exercise client's implementation */
174 #define TD_NETDATA 0x04 /* Display received data stream */
175 #define TD_PTYDATA 0x08 /* Display data passed to pty */
176 #define TD_OPTIONS 0x10 /* Report just telnet options */
177 #endif /* DIAGNOSTICS */
180 * We keep track of each side of the option negotiation.
183 #define MY_STATE_WILL 0x01
184 #define MY_WANT_STATE_WILL 0x02
185 #define MY_STATE_DO 0x04
186 #define MY_WANT_STATE_DO 0x08
189 * Macros to check the current state of things
192 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
193 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
194 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
195 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
197 #define my_state_is_dont(opt) (!my_state_is_do(opt))
198 #define my_state_is_wont(opt) (!my_state_is_will(opt))
199 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
200 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
202 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
203 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
204 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
205 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
207 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
208 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
209 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
210 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
213 * Tricky code here. What we want to know is if the MY_STATE_WILL
214 * and MY_WANT_STATE_WILL bits have the same value. Since the two
215 * bits are adjacent, a little arithmatic will show that by adding
216 * in the lower bit, the upper bit will be set if the two bits were
217 * different, and clear if they were the same.
219 #define my_will_wont_is_changing(opt) \
220 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
222 #define my_do_dont_is_changing(opt) \
223 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
226 * Make everything symetrical
229 #define HIS_STATE_WILL MY_STATE_DO
230 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
231 #define HIS_STATE_DO MY_STATE_WILL
232 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
234 #define his_state_is_do my_state_is_will
235 #define his_state_is_will my_state_is_do
236 #define his_want_state_is_do my_want_state_is_will
237 #define his_want_state_is_will my_want_state_is_do
239 #define his_state_is_dont my_state_is_wont
240 #define his_state_is_wont my_state_is_dont
241 #define his_want_state_is_dont my_want_state_is_wont
242 #define his_want_state_is_wont my_want_state_is_dont
244 #define set_his_state_do set_my_state_will
245 #define set_his_state_will set_my_state_do
246 #define set_his_want_state_do set_my_want_state_will
247 #define set_his_want_state_will set_my_want_state_do
249 #define set_his_state_dont set_my_state_wont
250 #define set_his_state_wont set_my_state_dont
251 #define set_his_want_state_dont set_my_want_state_wont
252 #define set_his_want_state_wont set_my_want_state_dont
254 #define his_will_wont_is_changing my_do_dont_is_changing
255 #define his_do_dont_is_changing my_will_wont_is_changing