]> git.saurik.com Git - apple/network_cmds.git/blame - telnetd.tproj/defs.h
network_cmds-77.tar.gz
[apple/network_cmds.git] / telnetd.tproj / defs.h
CommitLineData
b7080c8e
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * Copyright (c) 1989, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 *
56 * @(#)defs.h 8.1 (Berkeley) 6/4/93
57 */
58
59/*
60 * Telnet server defines
61 */
62#include <sys/types.h>
63#include <sys/param.h>
64
65#ifndef BSD
66# define BSD 43
67#endif
68
69#if defined(CRAY) && !defined(LINEMODE)
70# define SYSV_TERMIO
71# define LINEMODE
72# define KLUDGELINEMODE
73# define DIAGNOSTICS
74# if defined(UNICOS50) && !defined(UNICOS5)
75# define UNICOS5
76# endif
77# if !defined(UNICOS5)
78# define BFTPDAEMON
79# define HAS_IP_TOS
80# endif
81#endif /* CRAY */
82#if defined(UNICOS5) && !defined(NO_SETSID)
83# define NO_SETSID
84#endif
85
86#if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
87#define TELOPTS
88#define TELCMDS
89#define SLC_NAMES
90#endif
91
92#if defined(SYSV_TERMIO) && !defined(USE_TERMIO)
93# define USE_TERMIO
94#endif
95
96#include <sys/socket.h>
97#ifndef CRAY
98#include <sys/wait.h>
99#endif /* CRAY */
100#include <fcntl.h>
101#include <sys/file.h>
102#include <sys/stat.h>
103#include <sys/time.h>
104#ifndef FILIO_H
105#include <sys/ioctl.h>
106#else
107#include <sys/filio.h>
108#endif
109
110#include <netinet/in.h>
111
112#include <arpa/telnet.h>
113
114#include <stdio.h>
115#ifdef __STDC__
116#include <stdlib.h>
117#endif
118#include <signal.h>
119#include <errno.h>
120#include <netdb.h>
121#include <syslog.h>
122#ifndef LOG_DAEMON
123#define LOG_DAEMON 0
124#endif
125#ifndef LOG_ODELAY
126#define LOG_ODELAY 0
127#endif
128#include <ctype.h>
129#ifndef NO_STRING_H
130#include <string.h>
131#else
132#include <strings.h>
133#endif
134
135#ifndef USE_TERMIO
136#include <sgtty.h>
137#else
138# ifdef SYSV_TERMIO
139# include <termio.h>
140# else
141# ifdef __APPLE__
142# include <sys/termios.h>
143# else
144# include <termios.h>
145# endif
146# endif
147#endif
148#if !defined(USE_TERMIO) || defined(NO_CC_T)
149typedef unsigned char cc_t;
150#endif
151
152#ifdef __STDC__
153#include <unistd.h>
154#endif
155
156#ifndef _POSIX_VDISABLE
157# ifdef VDISABLE
158# define _POSIX_VDISABLE VDISABLE
159# else
160# define _POSIX_VDISABLE ((unsigned char)'\377')
161# endif
162#endif
163
164
165#ifdef CRAY
166# ifdef CRAY1
167# include <sys/pty.h>
168# ifndef FD_ZERO
169# include <sys/select.h>
170# endif /* FD_ZERO */
171# endif /* CRAY1 */
172
173#include <memory.h>
174#endif /* CRAY */
175
176#ifdef __hpux
177#include <sys/ptyio.h>
178#endif
179
180#if !defined(TIOCSCTTY) && defined(TCSETCTTY)
181# define TIOCSCTTY TCSETCTTY
182#endif
183
184#ifndef FD_SET
185#ifndef HAVE_fd_set
186typedef struct fd_set { int fds_bits[1]; } fd_set;
187#endif
188
189#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
190#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
191#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
192#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
193#endif /* FD_SET */
194
195/*
196 * I/O data buffers defines
197 */
198#define NETSLOP 64
199#ifdef CRAY
200#undef BUFSIZ
201#define BUFSIZ 2048
202#endif
203
204#define NIACCUM(c) { *netip++ = c; \
205 ncc++; \
206 }
207
208/* clock manipulations */
209#define settimer(x) (clocks.x = ++clocks.system)
210#define sequenceIs(x,y) (clocks.x < clocks.y)
211
212/*
213 * Linemode support states, in decreasing order of importance
214 */
215#define REAL_LINEMODE 0x04
216#define KLUDGE_OK 0x03
217#define NO_AUTOKLUDGE 0x02
218#define KLUDGE_LINEMODE 0x01
219#define NO_LINEMODE 0x00
220
221/*
222 * Structures of information for each special character function.
223 */
224typedef struct {
225 unsigned char flag; /* the flags for this function */
226 cc_t val; /* the value of the special character */
227} slcent, *Slcent;
228
229typedef struct {
230 slcent defset; /* the default settings */
231 slcent current; /* the current settings */
232 cc_t *sptr; /* a pointer to the char in */
233 /* system data structures */
234} slcfun, *Slcfun;
235
236#ifdef DIAGNOSTICS
237/*
238 * Diagnostics capabilities
239 */
240#define TD_REPORT 0x01 /* Report operations to client */
241#define TD_EXERCISE 0x02 /* Exercise client's implementation */
242#define TD_NETDATA 0x04 /* Display received data stream */
243#define TD_PTYDATA 0x08 /* Display data passed to pty */
244#define TD_OPTIONS 0x10 /* Report just telnet options */
245#endif /* DIAGNOSTICS */
246
247/*
248 * We keep track of each side of the option negotiation.
249 */
250
251#define MY_STATE_WILL 0x01
252#define MY_WANT_STATE_WILL 0x02
253#define MY_STATE_DO 0x04
254#define MY_WANT_STATE_DO 0x08
255
256/*
257 * Macros to check the current state of things
258 */
259
260#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
261#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
262#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
263#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
264
265#define my_state_is_dont(opt) (!my_state_is_do(opt))
266#define my_state_is_wont(opt) (!my_state_is_will(opt))
267#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
268#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
269
270#define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
271#define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
272#define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
273#define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
274
275#define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
276#define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
277#define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
278#define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
279
280/*
281 * Tricky code here. What we want to know is if the MY_STATE_WILL
282 * and MY_WANT_STATE_WILL bits have the same value. Since the two
283 * bits are adjacent, a little arithmatic will show that by adding
284 * in the lower bit, the upper bit will be set if the two bits were
285 * different, and clear if they were the same.
286 */
287#define my_will_wont_is_changing(opt) \
288 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
289
290#define my_do_dont_is_changing(opt) \
291 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
292
293/*
294 * Make everything symetrical
295 */
296
297#define HIS_STATE_WILL MY_STATE_DO
298#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
299#define HIS_STATE_DO MY_STATE_WILL
300#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
301
302#define his_state_is_do my_state_is_will
303#define his_state_is_will my_state_is_do
304#define his_want_state_is_do my_want_state_is_will
305#define his_want_state_is_will my_want_state_is_do
306
307#define his_state_is_dont my_state_is_wont
308#define his_state_is_wont my_state_is_dont
309#define his_want_state_is_dont my_want_state_is_wont
310#define his_want_state_is_wont my_want_state_is_dont
311
312#define set_his_state_do set_my_state_will
313#define set_his_state_will set_my_state_do
314#define set_his_want_state_do set_my_want_state_will
315#define set_his_want_state_will set_my_want_state_do
316
317#define set_his_state_dont set_my_state_wont
318#define set_his_state_wont set_my_state_dont
319#define set_his_want_state_dont set_my_want_state_wont
320#define set_his_want_state_wont set_my_want_state_dont
321
322#define his_will_wont_is_changing my_do_dont_is_changing
323#define his_do_dont_is_changing my_will_wont_is_changing