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