138905Sborman /* 238905Sborman * Copyright (c) 1989 The Regents of the University of California. 338905Sborman * All rights reserved. 438905Sborman * 542673Sbostic * %sccs.include.redist.c% 638905Sborman * 7*46809Sdab * @(#)defs.h 5.10 (Berkeley) 03/01/91 838905Sborman */ 938905Sborman 1038905Sborman /* 1138905Sborman * Telnet server defines 1238905Sborman */ 1338905Sborman #include <sys/types.h> 1438905Sborman #include <sys/param.h> 1538905Sborman 1638905Sborman #ifndef BSD 1738905Sborman # define BSD 43 1838905Sborman #endif 1938905Sborman 2044364Sborman #if defined(CRAY) && !defined(LINEMODE) 2144364Sborman # define SYSV_TERMIO 2244364Sborman # define LINEMODE 2344364Sborman # define KLUDGELINEMODE 2444364Sborman # define DIAGNOSTICS 25*46809Sdab # if defined(UNICOS50) && !defined(UNICOS5) 26*46809Sdab # define UNICOS5 27*46809Sdab # endif 2844364Sborman # if !defined(UNICOS5) 2944364Sborman # define BFTPDAEMON 3044364Sborman # define HAS_IP_TOS 3144364Sborman # endif 3244364Sborman #endif /* CRAY */ 3344364Sborman #if defined(UNICOS5) && !defined(NO_SETSID) 3444364Sborman # define NO_SETSID 3538905Sborman #endif 3638905Sborman 3744364Sborman #if defined(PRINTOPTIONS) && defined(DIAGNOSTICS) 3844364Sborman #define TELOPTS 3944364Sborman #define TELCMDS 40*46809Sdab #define SLC_NAMES 4144364Sborman #endif 4238905Sborman 4344364Sborman #if defined(SYSV_TERMIO) && !defined(USE_TERMIO) 4438905Sborman # define USE_TERMIO 4538905Sborman #endif 4638905Sborman 4738905Sborman #include <sys/socket.h> 4838905Sborman #ifndef CRAY 4938905Sborman #include <sys/wait.h> 5038905Sborman #endif /* CRAY */ 51*46809Sdab #include <fcntl.h> 5238905Sborman #include <sys/file.h> 5338905Sborman #include <sys/stat.h> 5438905Sborman #include <sys/time.h> 5544364Sborman #ifndef FILIO_H 5639503Sborman #include <sys/ioctl.h> 5744364Sborman #else 5844364Sborman #include <sys/filio.h> 5944364Sborman #endif 6038905Sborman 6138905Sborman #include <netinet/in.h> 6238905Sborman 6338905Sborman #include <arpa/telnet.h> 6438905Sborman 6538905Sborman #include <stdio.h> 66*46809Sdab #ifdef __STDC__ 67*46809Sdab #include <stdlib.h> 68*46809Sdab #endif 6938905Sborman #include <signal.h> 7038905Sborman #include <errno.h> 7138905Sborman #include <netdb.h> 7238905Sborman #include <syslog.h> 7340242Sborman #ifndef LOG_DAEMON 7440242Sborman #define LOG_DAEMON 0 7540242Sborman #endif 7640242Sborman #ifndef LOG_ODELAY 7740242Sborman #define LOG_ODELAY 0 7840242Sborman #endif 7938905Sborman #include <ctype.h> 8044364Sborman #ifndef NO_STRING_H 8142029Sbostic #include <string.h> 8244364Sborman #else 8344364Sborman #include <strings.h> 8444364Sborman #endif 8538905Sborman 8638905Sborman #ifndef USE_TERMIO 8738905Sborman #include <sgtty.h> 8838905Sborman #else 8938905Sborman # ifdef SYSV_TERMIO 9038905Sborman # include <termio.h> 9138905Sborman # else 9238905Sborman # include <termios.h> 9338905Sborman # endif 9438905Sborman #endif 9544364Sborman #if !defined(USE_TERMIO) || defined(NO_CC_T) 9644364Sborman typedef unsigned char cc_t; 9744364Sborman #endif 9838905Sborman 99*46809Sdab #ifdef __STDC__ 100*46809Sdab #include <unistd.h> 101*46809Sdab #endif 102*46809Sdab 10345234Sborman #ifndef _POSIX_VDISABLE 10445234Sborman # ifdef VDISABLE 10545234Sborman # define _POSIX_VDISABLE VDISABLE 10645234Sborman # else 10745234Sborman # define _POSIX_VDISABLE ((unsigned char)'\377') 10845234Sborman # endif 10945234Sborman #endif 11045234Sborman 11145234Sborman 11238905Sborman #ifdef CRAY 11338905Sborman # ifdef CRAY1 11438905Sborman # include <sys/pty.h> 11538905Sborman # ifndef FD_ZERO 11638905Sborman # include <sys/select.h> 11738905Sborman # endif /* FD_ZERO */ 11838905Sborman # endif /* CRAY1 */ 11938905Sborman 12038905Sborman #include <memory.h> 12138905Sborman #endif /* CRAY */ 12238905Sborman 12344364Sborman #if !defined(TIOCSCTTY) && defined(TCSETCTTY) 12444364Sborman # define TIOCSCTTY TCSETCTTY 12538905Sborman #endif 12638905Sborman 12738905Sborman #ifndef FD_SET 12840242Sborman #ifndef HAVE_fd_set 12938905Sborman typedef struct fd_set { int fds_bits[1]; } fd_set; 13040242Sborman #endif 13138905Sborman 13238905Sborman #define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n))) 13338905Sborman #define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n))) 13438905Sborman #define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n))) 13538905Sborman #define FD_ZERO(p) ((p)->fds_bits[0] = 0) 13638905Sborman #endif /* FD_SET */ 13738905Sborman 13838905Sborman /* 13938905Sborman * I/O data buffers defines 14038905Sborman */ 14138905Sborman #define NETSLOP 64 14238905Sborman #ifdef CRAY 14338905Sborman #undef BUFSIZ 14438905Sborman #define BUFSIZ 2048 14538905Sborman #endif 14638905Sborman 14738905Sborman #define NIACCUM(c) { *netip++ = c; \ 14838905Sborman ncc++; \ 14938905Sborman } 15038905Sborman 15138905Sborman /* clock manipulations */ 15238905Sborman #define settimer(x) (clocks.x = ++clocks.system) 15338905Sborman #define sequenceIs(x,y) (clocks.x < clocks.y) 15438905Sborman 15538905Sborman /* 15638905Sborman * Linemode support states, in decreasing order of importance 15738905Sborman */ 15838905Sborman #define REAL_LINEMODE 0x02 15938905Sborman #define KLUDGE_LINEMODE 0x01 16038905Sborman #define NO_LINEMODE 0x00 16138905Sborman 16238905Sborman /* 16338905Sborman * Structures of information for each special character function. 16438905Sborman */ 16538905Sborman typedef struct { 16638905Sborman unsigned char flag; /* the flags for this function */ 16740242Sborman cc_t val; /* the value of the special character */ 16838905Sborman } slcent, *Slcent; 16938905Sborman 17038905Sborman typedef struct { 17138905Sborman slcent defset; /* the default settings */ 17238905Sborman slcent current; /* the current settings */ 17340242Sborman cc_t *sptr; /* a pointer to the char in */ 17438905Sborman /* system data structures */ 17538905Sborman } slcfun, *Slcfun; 17644364Sborman 17744364Sborman #ifdef DIAGNOSTICS 17844364Sborman /* 17944364Sborman * Diagnostics capabilities 18044364Sborman */ 18144364Sborman #define TD_REPORT 0x01 /* Report operations to client */ 18244364Sborman #define TD_EXERCISE 0x02 /* Exercise client's implementation */ 18344364Sborman #define TD_NETDATA 0x04 /* Display received data stream */ 18444364Sborman #define TD_PTYDATA 0x08 /* Display data passed to pty */ 18544364Sborman #define TD_OPTIONS 0x10 /* Report just telnet options */ 18644364Sborman #endif /* DIAGNOSTICS */ 18744364Sborman 18844364Sborman /* 18944364Sborman * We keep track of each side of the option negotiation. 19044364Sborman */ 19144364Sborman 19244364Sborman #define MY_STATE_WILL 0x01 19344364Sborman #define MY_WANT_STATE_WILL 0x02 19444364Sborman #define MY_STATE_DO 0x04 19544364Sborman #define MY_WANT_STATE_DO 0x08 19644364Sborman 19744364Sborman /* 19844364Sborman * Macros to check the current state of things 19944364Sborman */ 20044364Sborman 20144364Sborman #define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 20244364Sborman #define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 20344364Sborman #define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 20444364Sborman #define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 20544364Sborman 20644364Sborman #define my_state_is_dont(opt) (!my_state_is_do(opt)) 20744364Sborman #define my_state_is_wont(opt) (!my_state_is_will(opt)) 20844364Sborman #define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 20944364Sborman #define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 21044364Sborman 21144364Sborman #define set_my_state_do(opt) (options[opt] |= MY_STATE_DO) 21244364Sborman #define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL) 21344364Sborman #define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO) 21444364Sborman #define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL) 21544364Sborman 21644364Sborman #define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO) 21744364Sborman #define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL) 21844364Sborman #define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO) 21944364Sborman #define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL) 22044364Sborman 22144364Sborman /* 22244364Sborman * Tricky code here. What we want to know is if the MY_STATE_WILL 22344364Sborman * and MY_WANT_STATE_WILL bits have the same value. Since the two 22444364Sborman * bits are adjacent, a little arithmatic will show that by adding 22544364Sborman * in the lower bit, the upper bit will be set if the two bits were 22644364Sborman * different, and clear if they were the same. 22744364Sborman */ 22844364Sborman #define my_will_wont_is_changing(opt) \ 22944364Sborman ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL) 23044364Sborman 23144364Sborman #define my_do_dont_is_changing(opt) \ 23244364Sborman ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO) 23344364Sborman 23444364Sborman /* 23544364Sborman * Make everything symetrical 23644364Sborman */ 23744364Sborman 23844364Sborman #define HIS_STATE_WILL MY_STATE_DO 23944364Sborman #define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 24044364Sborman #define HIS_STATE_DO MY_STATE_WILL 24144364Sborman #define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 24244364Sborman 24344364Sborman #define his_state_is_do my_state_is_will 24444364Sborman #define his_state_is_will my_state_is_do 24544364Sborman #define his_want_state_is_do my_want_state_is_will 24644364Sborman #define his_want_state_is_will my_want_state_is_do 24744364Sborman 24844364Sborman #define his_state_is_dont my_state_is_wont 24944364Sborman #define his_state_is_wont my_state_is_dont 25044364Sborman #define his_want_state_is_dont my_want_state_is_wont 25144364Sborman #define his_want_state_is_wont my_want_state_is_dont 25244364Sborman 25344364Sborman #define set_his_state_do set_my_state_will 25444364Sborman #define set_his_state_will set_my_state_do 25544364Sborman #define set_his_want_state_do set_my_want_state_will 25644364Sborman #define set_his_want_state_will set_my_want_state_do 25744364Sborman 25844364Sborman #define set_his_state_dont set_my_state_wont 25944364Sborman #define set_his_state_wont set_my_state_dont 26044364Sborman #define set_his_want_state_dont set_my_want_state_wont 26144364Sborman #define set_his_want_state_wont set_my_want_state_dont 26244364Sborman 26344364Sborman #define his_will_wont_is_changing my_do_dont_is_changing 26444364Sborman #define his_do_dont_is_changing my_will_wont_is_changing 265