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