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