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