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