129088Smarkm/* 229088Smarkm * Copyright (c) 1989, 1993 329088Smarkm * The Regents of the University of California. All rights reserved. 429088Smarkm * 529088Smarkm * Redistribution and use in source and binary forms, with or without 629088Smarkm * modification, are permitted provided that the following conditions 729088Smarkm * are met: 829088Smarkm * 1. Redistributions of source code must retain the above copyright 929088Smarkm * notice, this list of conditions and the following disclaimer. 1029088Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1129088Smarkm * notice, this list of conditions and the following disclaimer in the 1229088Smarkm * documentation and/or other materials provided with the distribution. 1329088Smarkm * 3. All advertising materials mentioning features or use of this software 1429088Smarkm * must display the following acknowledgement: 1529088Smarkm * This product includes software developed by the University of 1629088Smarkm * California, Berkeley and its contributors. 1729088Smarkm * 4. Neither the name of the University nor the names of its contributors 1829088Smarkm * may be used to endorse or promote products derived from this software 1929088Smarkm * without specific prior written permission. 2029088Smarkm * 2129088Smarkm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2229088Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2329088Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2429088Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2529088Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2629088Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2729088Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2829088Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2929088Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3029088Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3129088Smarkm * SUCH DAMAGE. 3229088Smarkm * 3329088Smarkm * @(#)defs.h 8.1 (Berkeley) 6/4/93 3482497Smarkm * $FreeBSD$ 3529088Smarkm */ 3629088Smarkm 3729088Smarkm/* 3829088Smarkm * Telnet server defines 3929088Smarkm */ 4029088Smarkm#include <sys/types.h> 4129088Smarkm#include <sys/param.h> 4229088Smarkm 4329088Smarkm#ifndef BSD 4429088Smarkm# define BSD 43 4529088Smarkm#endif 4629088Smarkm 4729088Smarkm#if defined(PRINTOPTIONS) && defined(DIAGNOSTICS) 4829088Smarkm#define TELOPTS 4929088Smarkm#define TELCMDS 5029088Smarkm#define SLC_NAMES 5129088Smarkm#endif 5229088Smarkm 5329088Smarkm#if defined(SYSV_TERMIO) && !defined(USE_TERMIO) 5429088Smarkm# define USE_TERMIO 5529088Smarkm#endif 5629088Smarkm 5729088Smarkm#include <sys/socket.h> 5829088Smarkm#include <sys/wait.h> 5929088Smarkm#include <fcntl.h> 6029088Smarkm#include <sys/file.h> 6129088Smarkm#include <sys/stat.h> 6229088Smarkm#include <sys/time.h> 6329088Smarkm#ifndef FILIO_H 6429088Smarkm#include <sys/ioctl.h> 6529088Smarkm#else 6629088Smarkm#include <sys/filio.h> 6729088Smarkm#endif 6829088Smarkm 6929088Smarkm#include <netinet/in.h> 7029088Smarkm 7129088Smarkm#include <arpa/telnet.h> 7229088Smarkm 7329088Smarkm#include <stdio.h> 7429088Smarkm#ifdef __STDC__ 7529088Smarkm#include <stdlib.h> 7629088Smarkm#endif 7729088Smarkm#include <signal.h> 7829088Smarkm#include <errno.h> 7929088Smarkm#include <netdb.h> 8029088Smarkm#include <syslog.h> 8129088Smarkm#ifndef LOG_DAEMON 8229088Smarkm#define LOG_DAEMON 0 8329088Smarkm#endif 8429088Smarkm#ifndef LOG_ODELAY 8529088Smarkm#define LOG_ODELAY 0 8629088Smarkm#endif 8729088Smarkm#include <ctype.h> 8829088Smarkm#ifndef NO_STRING_H 8929088Smarkm#include <string.h> 9029088Smarkm#else 9129088Smarkm#include <strings.h> 9229088Smarkm#endif 9329088Smarkm 9429088Smarkm#ifndef USE_TERMIO 9529088Smarkm#include <sgtty.h> 9629088Smarkm#else 9729088Smarkm# ifdef SYSV_TERMIO 9829088Smarkm# include <termio.h> 9929088Smarkm# else 10029088Smarkm# include <termios.h> 10129088Smarkm# endif 10229088Smarkm#endif 10329088Smarkm#if !defined(USE_TERMIO) || defined(NO_CC_T) 10429088Smarkmtypedef unsigned char cc_t; 10529088Smarkm#endif 10629088Smarkm 10729088Smarkm#ifdef __STDC__ 10829088Smarkm#include <unistd.h> 10929088Smarkm#endif 11029088Smarkm 11129088Smarkm#ifndef _POSIX_VDISABLE 11229088Smarkm# ifdef VDISABLE 11329088Smarkm# define _POSIX_VDISABLE VDISABLE 11429088Smarkm# else 11529088Smarkm# define _POSIX_VDISABLE ((unsigned char)'\377') 11629088Smarkm# endif 11729088Smarkm#endif 11829088Smarkm 11929088Smarkm#if !defined(TIOCSCTTY) && defined(TCSETCTTY) 12029088Smarkm# define TIOCSCTTY TCSETCTTY 12129088Smarkm#endif 12229088Smarkm 12329088Smarkm#ifndef FD_SET 12429088Smarkm#ifndef HAVE_fd_set 12529088Smarkmtypedef struct fd_set { int fds_bits[1]; } fd_set; 12629088Smarkm#endif 12729088Smarkm 12829088Smarkm#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n))) 12929088Smarkm#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n))) 13029088Smarkm#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n))) 13129088Smarkm#define FD_ZERO(p) ((p)->fds_bits[0] = 0) 13229088Smarkm#endif /* FD_SET */ 13329088Smarkm 13429088Smarkm/* 13529088Smarkm * I/O data buffers defines 13629088Smarkm */ 13729088Smarkm#define NETSLOP 64 13829088Smarkm 13929088Smarkm#define NIACCUM(c) { *netip++ = c; \ 14029088Smarkm ncc++; \ 14129088Smarkm } 14229088Smarkm 14329088Smarkm/* clock manipulations */ 14429088Smarkm#define settimer(x) (clocks.x = ++clocks.system) 14529088Smarkm#define sequenceIs(x,y) (clocks.x < clocks.y) 14629088Smarkm 14729088Smarkm/* 14829088Smarkm * Linemode support states, in decreasing order of importance 14929088Smarkm */ 15029088Smarkm#define REAL_LINEMODE 0x04 15129088Smarkm#define KLUDGE_OK 0x03 15229088Smarkm#define NO_AUTOKLUDGE 0x02 15329088Smarkm#define KLUDGE_LINEMODE 0x01 15429088Smarkm#define NO_LINEMODE 0x00 15529088Smarkm 15629088Smarkm/* 15729088Smarkm * Structures of information for each special character function. 15829088Smarkm */ 15929088Smarkmtypedef struct { 16029088Smarkm unsigned char flag; /* the flags for this function */ 16129088Smarkm cc_t val; /* the value of the special character */ 16229088Smarkm} slcent, *Slcent; 16329088Smarkm 16429088Smarkmtypedef struct { 16529088Smarkm slcent defset; /* the default settings */ 16629088Smarkm slcent current; /* the current settings */ 16729088Smarkm cc_t *sptr; /* a pointer to the char in */ 16829088Smarkm /* system data structures */ 16929088Smarkm} slcfun, *Slcfun; 17029088Smarkm 17129088Smarkm#ifdef DIAGNOSTICS 17229088Smarkm/* 17329088Smarkm * Diagnostics capabilities 17429088Smarkm */ 17529088Smarkm#define TD_REPORT 0x01 /* Report operations to client */ 17629088Smarkm#define TD_EXERCISE 0x02 /* Exercise client's implementation */ 17729088Smarkm#define TD_NETDATA 0x04 /* Display received data stream */ 17829088Smarkm#define TD_PTYDATA 0x08 /* Display data passed to pty */ 17929088Smarkm#define TD_OPTIONS 0x10 /* Report just telnet options */ 18029088Smarkm#endif /* DIAGNOSTICS */ 18129088Smarkm 18229088Smarkm/* 18329088Smarkm * We keep track of each side of the option negotiation. 18429088Smarkm */ 18529088Smarkm 18629088Smarkm#define MY_STATE_WILL 0x01 18729088Smarkm#define MY_WANT_STATE_WILL 0x02 18829088Smarkm#define MY_STATE_DO 0x04 18929088Smarkm#define MY_WANT_STATE_DO 0x08 19029088Smarkm 19129088Smarkm/* 19229088Smarkm * Macros to check the current state of things 19329088Smarkm */ 19429088Smarkm 19529088Smarkm#define my_state_is_do(opt) (options[opt]&MY_STATE_DO) 19629088Smarkm#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL) 19729088Smarkm#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO) 19829088Smarkm#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL) 19929088Smarkm 20029088Smarkm#define my_state_is_dont(opt) (!my_state_is_do(opt)) 20129088Smarkm#define my_state_is_wont(opt) (!my_state_is_will(opt)) 20229088Smarkm#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) 20329088Smarkm#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) 20429088Smarkm 20529088Smarkm#define set_my_state_do(opt) (options[opt] |= MY_STATE_DO) 20629088Smarkm#define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL) 20729088Smarkm#define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO) 20829088Smarkm#define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL) 20929088Smarkm 21029088Smarkm#define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO) 21129088Smarkm#define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL) 21229088Smarkm#define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO) 21329088Smarkm#define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL) 21429088Smarkm 21529088Smarkm/* 21629088Smarkm * Tricky code here. What we want to know is if the MY_STATE_WILL 21729088Smarkm * and MY_WANT_STATE_WILL bits have the same value. Since the two 21829088Smarkm * bits are adjacent, a little arithmatic will show that by adding 21929088Smarkm * in the lower bit, the upper bit will be set if the two bits were 22029088Smarkm * different, and clear if they were the same. 22129088Smarkm */ 22229088Smarkm#define my_will_wont_is_changing(opt) \ 22329088Smarkm ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL) 22429088Smarkm 22529088Smarkm#define my_do_dont_is_changing(opt) \ 22629088Smarkm ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO) 22729088Smarkm 22829088Smarkm/* 22929088Smarkm * Make everything symetrical 23029088Smarkm */ 23129088Smarkm 23229088Smarkm#define HIS_STATE_WILL MY_STATE_DO 23329088Smarkm#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO 23429088Smarkm#define HIS_STATE_DO MY_STATE_WILL 23529088Smarkm#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL 23629088Smarkm 23729088Smarkm#define his_state_is_do my_state_is_will 23829088Smarkm#define his_state_is_will my_state_is_do 23929088Smarkm#define his_want_state_is_do my_want_state_is_will 24029088Smarkm#define his_want_state_is_will my_want_state_is_do 24129088Smarkm 24229088Smarkm#define his_state_is_dont my_state_is_wont 24329088Smarkm#define his_state_is_wont my_state_is_dont 24429088Smarkm#define his_want_state_is_dont my_want_state_is_wont 24529088Smarkm#define his_want_state_is_wont my_want_state_is_dont 24629088Smarkm 24729088Smarkm#define set_his_state_do set_my_state_will 24829088Smarkm#define set_his_state_will set_my_state_do 24929088Smarkm#define set_his_want_state_do set_my_want_state_will 25029088Smarkm#define set_his_want_state_will set_my_want_state_do 25129088Smarkm 25229088Smarkm#define set_his_state_dont set_my_state_wont 25329088Smarkm#define set_his_state_wont set_my_state_dont 25429088Smarkm#define set_his_want_state_dont set_my_want_state_wont 25529088Smarkm#define set_his_want_state_wont set_my_want_state_dont 25629088Smarkm 25729088Smarkm#define his_will_wont_is_changing my_do_dont_is_changing 25829088Smarkm#define his_do_dont_is_changing my_will_wont_is_changing 259