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