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