1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)defs.h 8.1 (Berkeley) 06/04/93 8 */ 9 10 /* 11 * Telnet server defines 12 */ 13 #include <sys/types.h> 14 #include <sys/param.h> 15 16 #ifndef BSD 17 # define BSD 43 18 #endif 19 20 #if defined(CRAY) && !defined(LINEMODE) 21 # define SYSV_TERMIO 22 # define LINEMODE 23 # define KLUDGELINEMODE 24 # define DIAGNOSTICS 25 # if defined(UNICOS50) && !defined(UNICOS5) 26 # define UNICOS5 27 # endif 28 # if !defined(UNICOS5) 29 # define BFTPDAEMON 30 # define HAS_IP_TOS 31 # endif 32 #endif /* CRAY */ 33 #if defined(UNICOS5) && !defined(NO_SETSID) 34 # define NO_SETSID 35 #endif 36 37 #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS) 38 #define TELOPTS 39 #define TELCMDS 40 #define SLC_NAMES 41 #endif 42 43 #if defined(SYSV_TERMIO) && !defined(USE_TERMIO) 44 # define USE_TERMIO 45 #endif 46 47 #include <sys/socket.h> 48 #ifndef CRAY 49 #include <sys/wait.h> 50 #endif /* CRAY */ 51 #include <fcntl.h> 52 #include <sys/file.h> 53 #include <sys/stat.h> 54 #include <sys/time.h> 55 #ifndef FILIO_H 56 #include <sys/ioctl.h> 57 #else 58 #include <sys/filio.h> 59 #endif 60 61 #include <netinet/in.h> 62 63 #include <arpa/telnet.h> 64 65 #include <stdio.h> 66 #ifdef __STDC__ 67 #include <stdlib.h> 68 #endif 69 #include <signal.h> 70 #include <errno.h> 71 #include <netdb.h> 72 #include <syslog.h> 73 #ifndef LOG_DAEMON 74 #define LOG_DAEMON 0 75 #endif 76 #ifndef LOG_ODELAY 77 #define LOG_ODELAY 0 78 #endif 79 #include <ctype.h> 80 #ifndef NO_STRING_H 81 #include <string.h> 82 #else 83 #include <strings.h> 84 #endif 85 86 #ifndef USE_TERMIO 87 #include <sgtty.h> 88 #else 89 # ifdef SYSV_TERMIO 90 # include <termio.h> 91 # else 92 # include <termios.h> 93 # endif 94 #endif 95 #if !defined(USE_TERMIO) || defined(NO_CC_T) 96 typedef unsigned char cc_t; 97 #endif 98 99 #ifdef __STDC__ 100 #include <unistd.h> 101 #endif 102 103 #ifndef _POSIX_VDISABLE 104 # ifdef VDISABLE 105 # define _POSIX_VDISABLE VDISABLE 106 # else 107 # define _POSIX_VDISABLE ((unsigned char)'\377') 108 # endif 109 #endif 110 111 112 #ifdef CRAY 113 # ifdef CRAY1 114 # include <sys/pty.h> 115 # ifndef FD_ZERO 116 # include <sys/select.h> 117 # endif /* FD_ZERO */ 118 # endif /* CRAY1 */ 119 120 #include <memory.h> 121 #endif /* CRAY */ 122 123 #ifdef __hpux 124 #include <sys/ptyio.h> 125 #endif 126 127 #if !defined(TIOCSCTTY) && defined(TCSETCTTY) 128 # define TIOCSCTTY TCSETCTTY 129 #endif 130 131 #ifndef FD_SET 132 #ifndef HAVE_fd_set 133 typedef struct fd_set { int fds_bits[1]; } fd_set; 134 #endif 135 136 #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n))) 137 #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n))) 138 #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n))) 139 #define FD_ZERO(p) ((p)->fds_bits[0] = 0) 140 #endif /* FD_SET */ 141 142 /* 143 * I/O data buffers defines 144 */ 145 #define NETSLOP 64 146 #ifdef CRAY 147 #undef BUFSIZ 148 #define BUFSIZ 2048 149 #endif 150 151 #define NIACCUM(c) { *netip++ = c; \ 152 ncc++; \ 153 } 154 155 /* clock manipulations */ 156 #define settimer(x) (clocks.x = ++clocks.system) 157 #define sequenceIs(x,y) (clocks.x < clocks.y) 158 159 /* 160 * Linemode support states, in decreasing order of importance 161 */ 162 #define REAL_LINEMODE 0x04 163 #define KLUDGE_OK 0x03 164 #define NO_AUTOKLUDGE 0x02 165 #define KLUDGE_LINEMODE 0x01 166 #define NO_LINEMODE 0x00 167 168 /* 169 * Structures of information for each special character function. 170 */ 171 typedef struct { 172 unsigned char flag; /* the flags for this function */ 173 cc_t val; /* the value of the special character */ 174 } slcent, *Slcent; 175 176 typedef struct { 177 slcent defset; /* the default settings */ 178 slcent current; /* the current settings */ 179 cc_t *sptr; /* a pointer to the char in */ 180 /* system data structures */ 181 } slcfun, *Slcfun; 182 183 #ifdef DIAGNOSTICS 184 /* 185 * Diagnostics capabilities 186 */ 187 #define TD_REPORT 0x01 /* Report operations to client */ 188 #define TD_EXERCISE 0x02 /* Exercise client's implementation */ 189 #define TD_NETDATA 0x04 /* Display received data stream */ 190 #define TD_PTYDATA 0x08 /* Display data passed to pty */ 191 #define TD_OPTIONS 0x10 /* Report just telnet options */ 192 #endif /* DIAGNOSTICS */ 193 194 /* 195 * We keep track of each side of the option negotiation. 196 */ 197 198 #define MY_STATE_WILL 0x01 199 #define MY_WANT_STATE_WILL 0x02 200 #define MY_STATE_DO 0x04 201 #define MY_WANT_STATE_DO 0x08 202 203 /* 204 * Macros to check the current state of things 205 */ 206 207 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 208 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 209 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 210 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 211 212 #define my_state_is_dont(opt) (!my_state_is_do(opt)) 213 #define my_state_is_wont(opt) (!my_state_is_will(opt)) 214 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 215 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 216 217 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO) 218 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL) 219 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO) 220 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL) 221 222 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO) 223 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL) 224 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO) 225 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL) 226 227 /* 228 * Tricky code here. What we want to know is if the MY_STATE_WILL 229 * and MY_WANT_STATE_WILL bits have the same value. Since the two 230 * bits are adjacent, a little arithmatic will show that by adding 231 * in the lower bit, the upper bit will be set if the two bits were 232 * different, and clear if they were the same. 233 */ 234 #define my_will_wont_is_changing(opt) \ 235 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL) 236 237 #define my_do_dont_is_changing(opt) \ 238 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO) 239 240 /* 241 * Make everything symetrical 242 */ 243 244 #define HIS_STATE_WILL MY_STATE_DO 245 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 246 #define HIS_STATE_DO MY_STATE_WILL 247 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 248 249 #define his_state_is_do my_state_is_will 250 #define his_state_is_will my_state_is_do 251 #define his_want_state_is_do my_want_state_is_will 252 #define his_want_state_is_will my_want_state_is_do 253 254 #define his_state_is_dont my_state_is_wont 255 #define his_state_is_wont my_state_is_dont 256 #define his_want_state_is_dont my_want_state_is_wont 257 #define his_want_state_is_wont my_want_state_is_dont 258 259 #define set_his_state_do set_my_state_will 260 #define set_his_state_will set_my_state_do 261 #define set_his_want_state_do set_my_want_state_will 262 #define set_his_want_state_will set_my_want_state_do 263 264 #define set_his_state_dont set_my_state_wont 265 #define set_his_state_wont set_my_state_dont 266 #define set_his_want_state_dont set_my_want_state_wont 267 #define set_his_want_state_wont set_my_want_state_dont 268 269 #define his_will_wont_is_changing my_do_dont_is_changing 270 #define his_do_dont_is_changing my_will_wont_is_changing 271