1 /* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)defs.h 5.10 (Berkeley) 03/01/91 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 #if !defined(TIOCSCTTY) && defined(TCSETCTTY) 124 # define TIOCSCTTY TCSETCTTY 125 #endif 126 127 #ifndef FD_SET 128 #ifndef HAVE_fd_set 129 typedef struct fd_set { int fds_bits[1]; } fd_set; 130 #endif 131 132 #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n))) 133 #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n))) 134 #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n))) 135 #define FD_ZERO(p) ((p)->fds_bits[0] = 0) 136 #endif /* FD_SET */ 137 138 /* 139 * I/O data buffers defines 140 */ 141 #define NETSLOP 64 142 #ifdef CRAY 143 #undef BUFSIZ 144 #define BUFSIZ 2048 145 #endif 146 147 #define NIACCUM(c) { *netip++ = c; \ 148 ncc++; \ 149 } 150 151 /* clock manipulations */ 152 #define settimer(x) (clocks.x = ++clocks.system) 153 #define sequenceIs(x,y) (clocks.x < clocks.y) 154 155 /* 156 * Linemode support states, in decreasing order of importance 157 */ 158 #define REAL_LINEMODE 0x02 159 #define KLUDGE_LINEMODE 0x01 160 #define NO_LINEMODE 0x00 161 162 /* 163 * Structures of information for each special character function. 164 */ 165 typedef struct { 166 unsigned char flag; /* the flags for this function */ 167 cc_t val; /* the value of the special character */ 168 } slcent, *Slcent; 169 170 typedef struct { 171 slcent defset; /* the default settings */ 172 slcent current; /* the current settings */ 173 cc_t *sptr; /* a pointer to the char in */ 174 /* system data structures */ 175 } slcfun, *Slcfun; 176 177 #ifdef DIAGNOSTICS 178 /* 179 * Diagnostics capabilities 180 */ 181 #define TD_REPORT 0x01 /* Report operations to client */ 182 #define TD_EXERCISE 0x02 /* Exercise client's implementation */ 183 #define TD_NETDATA 0x04 /* Display received data stream */ 184 #define TD_PTYDATA 0x08 /* Display data passed to pty */ 185 #define TD_OPTIONS 0x10 /* Report just telnet options */ 186 #endif /* DIAGNOSTICS */ 187 188 /* 189 * We keep track of each side of the option negotiation. 190 */ 191 192 #define MY_STATE_WILL 0x01 193 #define MY_WANT_STATE_WILL 0x02 194 #define MY_STATE_DO 0x04 195 #define MY_WANT_STATE_DO 0x08 196 197 /* 198 * Macros to check the current state of things 199 */ 200 201 #define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 202 #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 203 #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 204 #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 205 206 #define my_state_is_dont(opt) (!my_state_is_do(opt)) 207 #define my_state_is_wont(opt) (!my_state_is_will(opt)) 208 #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 209 #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 210 211 #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO) 212 #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL) 213 #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO) 214 #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL) 215 216 #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO) 217 #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL) 218 #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO) 219 #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL) 220 221 /* 222 * Tricky code here. What we want to know is if the MY_STATE_WILL 223 * and MY_WANT_STATE_WILL bits have the same value. Since the two 224 * bits are adjacent, a little arithmatic will show that by adding 225 * in the lower bit, the upper bit will be set if the two bits were 226 * different, and clear if they were the same. 227 */ 228 #define my_will_wont_is_changing(opt) \ 229 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL) 230 231 #define my_do_dont_is_changing(opt) \ 232 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO) 233 234 /* 235 * Make everything symetrical 236 */ 237 238 #define HIS_STATE_WILL MY_STATE_DO 239 #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 240 #define HIS_STATE_DO MY_STATE_WILL 241 #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 242 243 #define his_state_is_do my_state_is_will 244 #define his_state_is_will my_state_is_do 245 #define his_want_state_is_do my_want_state_is_will 246 #define his_want_state_is_will my_want_state_is_do 247 248 #define his_state_is_dont my_state_is_wont 249 #define his_state_is_wont my_state_is_dont 250 #define his_want_state_is_dont my_want_state_is_wont 251 #define his_want_state_is_wont my_want_state_is_dont 252 253 #define set_his_state_do set_my_state_will 254 #define set_his_state_will set_my_state_do 255 #define set_his_want_state_do set_my_want_state_will 256 #define set_his_want_state_will set_my_want_state_do 257 258 #define set_his_state_dont set_my_state_wont 259 #define set_his_state_wont set_my_state_dont 260 #define set_his_want_state_dont set_my_want_state_wont 261 #define set_his_want_state_wont set_my_want_state_dont 262 263 #define his_will_wont_is_changing my_do_dont_is_changing 264 #define his_do_dont_is_changing my_will_wont_is_changing 265