BSD 4_3_Net_2 release
[unix-history] / usr / src / libexec / telnetd / defs.h
CommitLineData
ea139302
PB
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
af359dea
C
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. 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.
ea139302 20 *
af359dea
C
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
31 * SUCH DAMAGE.
32 *
33 * @(#)defs.h 5.10 (Berkeley) 3/1/91
ea139302
PB
34 */
35
36/*
37 * Telnet server defines
38 */
39#include <sys/types.h>
40#include <sys/param.h>
41
42#ifndef BSD
43# define BSD 43
44#endif
45
4a8a7128
PB
46#if defined(CRAY) && !defined(LINEMODE)
47# define SYSV_TERMIO
48# define LINEMODE
49# define KLUDGELINEMODE
4a8a7128 50# define DIAGNOSTICS
1af3d848
DB
51# if defined(UNICOS50) && !defined(UNICOS5)
52# define UNICOS5
53# endif
4a8a7128
PB
54# if !defined(UNICOS5)
55# define BFTPDAEMON
56# define HAS_IP_TOS
57# endif
58#endif /* CRAY */
59#if defined(UNICOS5) && !defined(NO_SETSID)
60# define NO_SETSID
ea139302
PB
61#endif
62
4a8a7128
PB
63#if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
64#define TELOPTS
65#define TELCMDS
1af3d848 66#define SLC_NAMES
4a8a7128 67#endif
ea139302 68
4a8a7128 69#if defined(SYSV_TERMIO) && !defined(USE_TERMIO)
ea139302
PB
70# define USE_TERMIO
71#endif
72
73#include <sys/socket.h>
74#ifndef CRAY
75#include <sys/wait.h>
76#endif /* CRAY */
1af3d848 77#include <fcntl.h>
ea139302
PB
78#include <sys/file.h>
79#include <sys/stat.h>
80#include <sys/time.h>
4a8a7128 81#ifndef FILIO_H
053fd49d 82#include <sys/ioctl.h>
4a8a7128
PB
83#else
84#include <sys/filio.h>
85#endif
ea139302
PB
86
87#include <netinet/in.h>
88
89#include <arpa/telnet.h>
90
91#include <stdio.h>
1af3d848
DB
92#ifdef __STDC__
93#include <stdlib.h>
94#endif
ea139302
PB
95#include <signal.h>
96#include <errno.h>
97#include <netdb.h>
98#include <syslog.h>
ed8f31c1
PB
99#ifndef LOG_DAEMON
100#define LOG_DAEMON 0
101#endif
102#ifndef LOG_ODELAY
103#define LOG_ODELAY 0
104#endif
ea139302 105#include <ctype.h>
4a8a7128 106#ifndef NO_STRING_H
6ebcb998 107#include <string.h>
4a8a7128
PB
108#else
109#include <strings.h>
110#endif
ea139302
PB
111
112#ifndef USE_TERMIO
113#include <sgtty.h>
114#else
115# ifdef SYSV_TERMIO
116# include <termio.h>
117# else
118# include <termios.h>
119# endif
120#endif
4a8a7128
PB
121#if !defined(USE_TERMIO) || defined(NO_CC_T)
122typedef unsigned char cc_t;
123#endif
ea139302 124
1af3d848
DB
125#ifdef __STDC__
126#include <unistd.h>
127#endif
128
2c9c7136
PB
129#ifndef _POSIX_VDISABLE
130# ifdef VDISABLE
131# define _POSIX_VDISABLE VDISABLE
132# else
133# define _POSIX_VDISABLE ((unsigned char)'\377')
134# endif
135#endif
136
137
ea139302 138#ifdef CRAY
ea139302
PB
139# ifdef CRAY1
140# include <sys/pty.h>
141# ifndef FD_ZERO
142# include <sys/select.h>
143# endif /* FD_ZERO */
144# endif /* CRAY1 */
145
146#include <memory.h>
147#endif /* CRAY */
148
4a8a7128
PB
149#if !defined(TIOCSCTTY) && defined(TCSETCTTY)
150# define TIOCSCTTY TCSETCTTY
ea139302
PB
151#endif
152
153#ifndef FD_SET
ed8f31c1 154#ifndef HAVE_fd_set
ea139302 155typedef struct fd_set { int fds_bits[1]; } fd_set;
ed8f31c1 156#endif
ea139302
PB
157
158#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
159#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
160#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
161#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
162#endif /* FD_SET */
163
ea139302
PB
164/*
165 * I/O data buffers defines
166 */
167#define NETSLOP 64
168#ifdef CRAY
169#undef BUFSIZ
170#define BUFSIZ 2048
171#endif
172
173#define NIACCUM(c) { *netip++ = c; \
174 ncc++; \
175 }
176
177/* clock manipulations */
178#define settimer(x) (clocks.x = ++clocks.system)
179#define sequenceIs(x,y) (clocks.x < clocks.y)
180
181/*
182 * Linemode support states, in decreasing order of importance
183 */
184#define REAL_LINEMODE 0x02
185#define KLUDGE_LINEMODE 0x01
186#define NO_LINEMODE 0x00
187
188/*
189 * Structures of information for each special character function.
190 */
191typedef struct {
192 unsigned char flag; /* the flags for this function */
ed8f31c1 193 cc_t val; /* the value of the special character */
ea139302
PB
194} slcent, *Slcent;
195
196typedef struct {
197 slcent defset; /* the default settings */
198 slcent current; /* the current settings */
ed8f31c1 199 cc_t *sptr; /* a pointer to the char in */
ea139302
PB
200 /* system data structures */
201} slcfun, *Slcfun;
4a8a7128
PB
202
203#ifdef DIAGNOSTICS
204/*
205 * Diagnostics capabilities
206 */
207#define TD_REPORT 0x01 /* Report operations to client */
208#define TD_EXERCISE 0x02 /* Exercise client's implementation */
209#define TD_NETDATA 0x04 /* Display received data stream */
210#define TD_PTYDATA 0x08 /* Display data passed to pty */
211#define TD_OPTIONS 0x10 /* Report just telnet options */
212#endif /* DIAGNOSTICS */
213
214/*
215 * We keep track of each side of the option negotiation.
216 */
217
218#define MY_STATE_WILL 0x01
219#define MY_WANT_STATE_WILL 0x02
220#define MY_STATE_DO 0x04
221#define MY_WANT_STATE_DO 0x08
222
223/*
224 * Macros to check the current state of things
225 */
226
227#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
228#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
229#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
230#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
231
232#define my_state_is_dont(opt) (!my_state_is_do(opt))
233#define my_state_is_wont(opt) (!my_state_is_will(opt))
234#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
235#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
236
237#define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
238#define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
239#define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
240#define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
241
242#define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
243#define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
244#define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
245#define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
246
247/*
248 * Tricky code here. What we want to know is if the MY_STATE_WILL
249 * and MY_WANT_STATE_WILL bits have the same value. Since the two
250 * bits are adjacent, a little arithmatic will show that by adding
251 * in the lower bit, the upper bit will be set if the two bits were
252 * different, and clear if they were the same.
253 */
254#define my_will_wont_is_changing(opt) \
255 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
256
257#define my_do_dont_is_changing(opt) \
258 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
259
260/*
261 * Make everything symetrical
262 */
263
264#define HIS_STATE_WILL MY_STATE_DO
265#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
266#define HIS_STATE_DO MY_STATE_WILL
267#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
268
269#define his_state_is_do my_state_is_will
270#define his_state_is_will my_state_is_do
271#define his_want_state_is_do my_want_state_is_will
272#define his_want_state_is_will my_want_state_is_do
273
274#define his_state_is_dont my_state_is_wont
275#define his_state_is_wont my_state_is_dont
276#define his_want_state_is_dont my_want_state_is_wont
277#define his_want_state_is_wont my_want_state_is_dont
278
279#define set_his_state_do set_my_state_will
280#define set_his_state_will set_my_state_do
281#define set_his_want_state_do set_my_want_state_will
282#define set_his_want_state_will set_my_want_state_do
283
284#define set_his_state_dont set_my_state_wont
285#define set_his_state_wont set_my_state_dont
286#define set_his_want_state_dont set_my_want_state_wont
287#define set_his_want_state_wont set_my_want_state_dont
288
289#define his_will_wont_is_changing my_do_dont_is_changing
290#define his_do_dont_is_changing my_will_wont_is_changing