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