defs.h revision 1.13 1 /* $NetBSD: defs.h,v 1.13 2003/07/14 15:55:53 itojun 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 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
45 #define TELOPTS
46 #define TELCMDS
47 #define SLC_NAMES
48 #endif
49
50 #include <sys/socket.h>
51 #include <sys/wait.h>
52 #include <fcntl.h>
53 #include <sys/file.h>
54 #include <sys/stat.h>
55 #include <sys/time.h>
56 #include <sys/poll.h>
57 #include <sys/ioctl.h>
58
59 #include <netinet/in.h>
60
61 #include <arpa/telnet.h>
62
63 #include <stdio.h>
64 #include <stdlib.h>
65 #include <signal.h>
66 #include <errno.h>
67 #include <netdb.h>
68 #include <syslog.h>
69 #include <ctype.h>
70 #include <string.h>
71 #include <termios.h>
72 #include <time.h>
73 #include <unistd.h>
74
75 /*
76 * I/O data buffers defines
77 */
78 #define NETSLOP 64
79
80 #define NIACCUM(c) do { \
81 *netip++ = c; \
82 ncc++; \
83 } while (0)
84
85 /* clock manipulations */
86 #define settimer(x) (clocks.x = ++clocks.system)
87 #define sequenceIs(x,y) (clocks.x < clocks.y)
88
89 /*
90 * Linemode support states, in decreasing order of importance
91 */
92 #define REAL_LINEMODE 0x04
93 #define KLUDGE_OK 0x03
94 #define NO_AUTOKLUDGE 0x02
95 #define KLUDGE_LINEMODE 0x01
96 #define NO_LINEMODE 0x00
97
98 /*
99 * Structures of information for each special character function.
100 */
101 typedef struct {
102 unsigned char flag; /* the flags for this function */
103 cc_t val; /* the value of the special character */
104 } slcent, *Slcent;
105
106 typedef struct {
107 slcent defset; /* the default settings */
108 slcent current; /* the current settings */
109 cc_t *sptr; /* a pointer to the char in */
110 /* system data structures */
111 } slcfun, *Slcfun;
112
113 #ifdef DIAGNOSTICS
114 /*
115 * Diagnostics capabilities
116 */
117 #define TD_REPORT 0x01 /* Report operations to client */
118 #define TD_EXERCISE 0x02 /* Exercise client's implementation */
119 #define TD_NETDATA 0x04 /* Display received data stream */
120 #define TD_PTYDATA 0x08 /* Display data passed to pty */
121 #define TD_OPTIONS 0x10 /* Report just telnet options */
122 #endif /* DIAGNOSTICS */
123
124 /*
125 * We keep track of each side of the option negotiation.
126 */
127
128 #define MY_STATE_WILL 0x01
129 #define MY_WANT_STATE_WILL 0x02
130 #define MY_STATE_DO 0x04
131 #define MY_WANT_STATE_DO 0x08
132
133 /*
134 * Macros to check the current state of things
135 */
136
137 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
138 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
139 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
140 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
141
142 #define my_state_is_dont(opt) (!my_state_is_do(opt))
143 #define my_state_is_wont(opt) (!my_state_is_will(opt))
144 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
145 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
146
147 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
148 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
149 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
150 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
151
152 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
153 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
154 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
155 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
156
157 /*
158 * Tricky code here. What we want to know is if the MY_STATE_WILL
159 * and MY_WANT_STATE_WILL bits have the same value. Since the two
160 * bits are adjacent, a little arithmatic will show that by adding
161 * in the lower bit, the upper bit will be set if the two bits were
162 * different, and clear if they were the same.
163 */
164 #define my_will_wont_is_changing(opt) \
165 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
166
167 #define my_do_dont_is_changing(opt) \
168 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
169
170 /*
171 * Make everything symmetrical
172 */
173
174 #define HIS_STATE_WILL MY_STATE_DO
175 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
176 #define HIS_STATE_DO MY_STATE_WILL
177 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
178
179 #define his_state_is_do my_state_is_will
180 #define his_state_is_will my_state_is_do
181 #define his_want_state_is_do my_want_state_is_will
182 #define his_want_state_is_will my_want_state_is_do
183
184 #define his_state_is_dont my_state_is_wont
185 #define his_state_is_wont my_state_is_dont
186 #define his_want_state_is_dont my_want_state_is_wont
187 #define his_want_state_is_wont my_want_state_is_dont
188
189 #define set_his_state_do set_my_state_will
190 #define set_his_state_will set_my_state_do
191 #define set_his_want_state_do set_my_want_state_will
192 #define set_his_want_state_will set_my_want_state_do
193
194 #define set_his_state_dont set_my_state_wont
195 #define set_his_state_wont set_my_state_dont
196 #define set_his_want_state_dont set_my_want_state_wont
197 #define set_his_want_state_wont set_my_want_state_dont
198
199 #define his_will_wont_is_changing my_do_dont_is_changing
200 #define his_do_dont_is_changing my_will_wont_is_changing
201
202 /*
203 * Initialization buffer for tty device [16 characters long]
204 */
205 #define NULL16STR "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
206