Home | History | Annotate | Line # | Download | only in telnetd
defs.h revision 1.14
      1 /*	$NetBSD: defs.h,v 1.14 2003/08/07 09:46:51 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1989, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	from: @(#)defs.h	8.1 (Berkeley) 6/4/93
     32  */
     33 
     34 /*
     35  * Telnet server defines
     36  */
     37 #include <sys/types.h>
     38 #include <sys/param.h>
     39 
     40 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
     41 #define TELOPTS
     42 #define TELCMDS
     43 #define	SLC_NAMES
     44 #endif
     45 
     46 #include <sys/socket.h>
     47 #include <sys/wait.h>
     48 #include <fcntl.h>
     49 #include <sys/file.h>
     50 #include <sys/stat.h>
     51 #include <sys/time.h>
     52 #include <sys/poll.h>
     53 #include <sys/ioctl.h>
     54 
     55 #include <netinet/in.h>
     56 
     57 #include <arpa/telnet.h>
     58 
     59 #include <stdio.h>
     60 #include <stdlib.h>
     61 #include <signal.h>
     62 #include <errno.h>
     63 #include <netdb.h>
     64 #include <syslog.h>
     65 #include <ctype.h>
     66 #include <string.h>
     67 #include <termios.h>
     68 #include <time.h>
     69 #include <unistd.h>
     70 
     71 /*
     72  * I/O data buffers defines
     73  */
     74 #define	NETSLOP	64
     75 
     76 #define	NIACCUM(c)	do { \
     77 			    *netip++ = c; \
     78 			    ncc++; \
     79 			} while (0)
     80 
     81 /* clock manipulations */
     82 #define	settimer(x)	(clocks.x = ++clocks.system)
     83 #define	sequenceIs(x,y)	(clocks.x < clocks.y)
     84 
     85 /*
     86  * Linemode support states, in decreasing order of importance
     87  */
     88 #define REAL_LINEMODE	0x04
     89 #define KLUDGE_OK	0x03
     90 #define	NO_AUTOKLUDGE	0x02
     91 #define KLUDGE_LINEMODE	0x01
     92 #define NO_LINEMODE	0x00
     93 
     94 /*
     95  * Structures of information for each special character function.
     96  */
     97 typedef struct {
     98 	unsigned char	flag;		/* the flags for this function */
     99 	cc_t		val;		/* the value of the special character */
    100 } slcent, *Slcent;
    101 
    102 typedef struct {
    103 	slcent		defset;		/* the default settings */
    104 	slcent		current;	/* the current settings */
    105 	cc_t		*sptr;		/* a pointer to the char in */
    106 					/* system data structures */
    107 } slcfun, *Slcfun;
    108 
    109 #ifdef DIAGNOSTICS
    110 /*
    111  * Diagnostics capabilities
    112  */
    113 #define	TD_REPORT	0x01	/* Report operations to client */
    114 #define TD_EXERCISE	0x02	/* Exercise client's implementation */
    115 #define TD_NETDATA	0x04	/* Display received data stream */
    116 #define TD_PTYDATA	0x08	/* Display data passed to pty */
    117 #define	TD_OPTIONS	0x10	/* Report just telnet options */
    118 #endif /* DIAGNOSTICS */
    119 
    120 /*
    121  * We keep track of each side of the option negotiation.
    122  */
    123 
    124 #define	MY_STATE_WILL		0x01
    125 #define	MY_WANT_STATE_WILL	0x02
    126 #define	MY_STATE_DO		0x04
    127 #define	MY_WANT_STATE_DO	0x08
    128 
    129 /*
    130  * Macros to check the current state of things
    131  */
    132 
    133 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
    134 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
    135 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
    136 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
    137 
    138 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
    139 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
    140 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
    141 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
    142 
    143 #define	set_my_state_do(opt)		(options[opt] |= MY_STATE_DO)
    144 #define	set_my_state_will(opt)		(options[opt] |= MY_STATE_WILL)
    145 #define	set_my_want_state_do(opt)	(options[opt] |= MY_WANT_STATE_DO)
    146 #define	set_my_want_state_will(opt)	(options[opt] |= MY_WANT_STATE_WILL)
    147 
    148 #define	set_my_state_dont(opt)		(options[opt] &= ~MY_STATE_DO)
    149 #define	set_my_state_wont(opt)		(options[opt] &= ~MY_STATE_WILL)
    150 #define	set_my_want_state_dont(opt)	(options[opt] &= ~MY_WANT_STATE_DO)
    151 #define	set_my_want_state_wont(opt)	(options[opt] &= ~MY_WANT_STATE_WILL)
    152 
    153 /*
    154  * Tricky code here.  What we want to know is if the MY_STATE_WILL
    155  * and MY_WANT_STATE_WILL bits have the same value.  Since the two
    156  * bits are adjacent, a little arithmatic will show that by adding
    157  * in the lower bit, the upper bit will be set if the two bits were
    158  * different, and clear if they were the same.
    159  */
    160 #define my_will_wont_is_changing(opt) \
    161 			((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
    162 
    163 #define my_do_dont_is_changing(opt) \
    164 			((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
    165 
    166 /*
    167  * Make everything symmetrical
    168  */
    169 
    170 #define	HIS_STATE_WILL			MY_STATE_DO
    171 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
    172 #define HIS_STATE_DO			MY_STATE_WILL
    173 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
    174 
    175 #define	his_state_is_do			my_state_is_will
    176 #define	his_state_is_will		my_state_is_do
    177 #define his_want_state_is_do		my_want_state_is_will
    178 #define his_want_state_is_will		my_want_state_is_do
    179 
    180 #define	his_state_is_dont		my_state_is_wont
    181 #define	his_state_is_wont		my_state_is_dont
    182 #define his_want_state_is_dont		my_want_state_is_wont
    183 #define his_want_state_is_wont		my_want_state_is_dont
    184 
    185 #define	set_his_state_do		set_my_state_will
    186 #define	set_his_state_will		set_my_state_do
    187 #define	set_his_want_state_do		set_my_want_state_will
    188 #define	set_his_want_state_will		set_my_want_state_do
    189 
    190 #define	set_his_state_dont		set_my_state_wont
    191 #define	set_his_state_wont		set_my_state_dont
    192 #define	set_his_want_state_dont		set_my_want_state_wont
    193 #define	set_his_want_state_wont		set_my_want_state_dont
    194 
    195 #define his_will_wont_is_changing	my_do_dont_is_changing
    196 #define his_do_dont_is_changing		my_will_wont_is_changing
    197 
    198 /*
    199  * Initialization buffer for tty device [16 characters long]
    200  */
    201 #define NULL16STR	"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
    202