From 57acab063b3ef9760ddafee33cca79b6f179421a Mon Sep 17 00:00:00 2001 From: markm Date: Fri, 30 Nov 2001 22:09:10 +0000 Subject: After running "make unifdef", commit the result. This code is now a complete subset of the crypto (master) code. --- usr.bin/telnet/commands.c | 936 +++++++++++++++++---------------------------- usr.bin/telnet/defines.h | 7 +- usr.bin/telnet/externs.h | 106 +++-- usr.bin/telnet/main.c | 80 +--- usr.bin/telnet/network.c | 30 +- usr.bin/telnet/ring.c | 97 ++--- usr.bin/telnet/ring.h | 5 +- usr.bin/telnet/sys_bsd.c | 275 ++++--------- usr.bin/telnet/telnet.c | 656 +++++++++---------------------- usr.bin/telnet/terminal.c | 42 +- usr.bin/telnet/tn3270.c | 416 -------------------- usr.bin/telnet/utilities.c | 111 ++---- 12 files changed, 782 insertions(+), 1979 deletions(-) delete mode 100644 usr.bin/telnet/tn3270.c diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index 6cba9c3..4418355 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -29,33 +29,32 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint static const char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95"; -#endif /* not lint */ +#endif -#if defined(unix) #include #include #include -#else -#include -#endif /* defined(unix) */ #include #include -#include -#include -#include #include -#include -#include +#include #include -#include +#include +#include +#include +#include #include +#include +#include #include #include @@ -67,11 +66,10 @@ static const char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95"; #include "externs.h" #include "defines.h" #include "types.h" +#include "misc.h" + #include -# if (defined(vax) || defined(tahoe) || defined(hp300)) && !defined(ultrix) -# include -# endif /* vax */ #include #include @@ -79,6 +77,8 @@ static const char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95"; #define MAXHOSTNAMELEN 256 #endif MAXHOSTNAMELEN +typedef int (*intrtn_t)(int, char **); + #if defined(IPPROTO_IP) && defined(IP_TOS) int tos = -1; #endif /* defined(IPPROTO_IP) && defined(IP_TOS) */ @@ -86,22 +86,21 @@ int tos = -1; char *hostname; static char _hostname[MAXHOSTNAMELEN]; -extern char *getenv(); - -extern int isprefix(); -extern char **genget(); -extern int Ambiguous(); - -static int help(int argc, char *argv[]); -static int call(); -static void cmdrc(char *m1, char *m2); -static int switch_af(struct addrinfo **aip); -int quit(void); +static int help(int, char **); +static int call(intrtn_t, ...); +static void cmdrc(char *, char *); +static int switch_af(struct addrinfo **); +static int togglehelp(void); +static int send_tncmd(void (*)(int, int), const char *, char *); +static int setmod(int); +static int clearmode(int); +static int modehelp(void); +static int sourceroute(struct addrinfo *, char *, char **, int *, int *, int *); typedef struct { - char *name; /* command name */ - char *help; /* help string (NULL for no help) */ - int (*handler)(); /* routine which executes command */ + const char *name; /* command name */ + const char *help; /* help string (NULL for no help) */ + int (*handler)(int, char **); /* routine which executes command */ int needconnect; /* Do we need to be connected to execute? */ } Command; @@ -110,19 +109,17 @@ static char saveline[256]; static int margc; static char *margv[20]; -#if defined(OPIE) +#ifdef OPIE #include #define PATH_OPIEKEY "/usr/bin/opiekey" - int -opie_calc(argc, argv) - int argc; - char **argv; +static int +opie_calc(int argc, char *argv[]) { int status; if(argc != 3) { printf("%s sequence challenge\n", argv[0]); - return; + return (0); } switch(fork()) { @@ -136,27 +133,27 @@ opie_calc(argc, argv) (void) wait(&status); if (WIFEXITED(status)) return (WEXITSTATUS(status)); - return (0); } + return (0); } #endif - static void -makeargv() +static void +makeargv(void) { - register char *cp, *cp2, c; - register char **argp = margv; + char *cp, *cp2, c; + char **argp = margv; margc = 0; cp = line; if (*cp == '!') { /* Special case shell escape */ strcpy(saveline, line); /* save for shell command */ - *argp++ = "!"; /* No room in string to get this */ + *argp++ = strdup("!"); /* No room in string to get this */ margc++; cp++; } while ((c = *cp)) { - register int inquote = 0; + int inquote = 0; while (isspace(c)) c = *++cp; if (c == '\0') @@ -198,11 +195,10 @@ makeargv() * Todo: 1. Could take random integers (12, 0x12, 012, 0b1). */ - static int -special(s) - register char *s; +static int +special(char *s) { - register char c; + char c; char b; switch (*s) { @@ -225,9 +221,8 @@ special(s) * Construct a control character sequence * for a special character. */ - static char * -control(c) - register cc_t c; +static const char * +control(cc_t c) { static char buf[5]; /* @@ -237,7 +232,7 @@ control(c) * was to assign "c" to an unsigned int variable... * Arggg.... */ - register unsigned int uic = (unsigned int)c; + unsigned int uic = (unsigned int)c; if (uic == 0x7f) return ("^?"); @@ -261,8 +256,6 @@ control(c) return (buf); } - - /* * The following are data structures and routines for * the "send" command. @@ -270,11 +263,11 @@ control(c) */ struct sendlist { - char *name; /* How user refers to it (case independent) */ - char *help; /* Help information (0 ==> no help) */ + const char *name; /* How user refers to it (case independent) */ + const char *help; /* Help information (0 ==> no help) */ int needconnect; /* Need to be connected */ int narg; /* Number of arguments */ - int (*handler)(); /* Routine to perform (for special ops) */ + int (*handler)(char *, ...); /* Routine to perform (for special ops) */ int nbyte; /* Number of bytes to send this command */ int what; /* Character to be sent (<0 ==> special) */ }; @@ -289,41 +282,39 @@ static int send_wontcmd P((char *)); static struct sendlist Sendlist[] = { - { "ao", "Send Telnet Abort output", 1, 0, 0, 2, AO }, - { "ayt", "Send Telnet 'Are You There'", 1, 0, 0, 2, AYT }, - { "brk", "Send Telnet Break", 1, 0, 0, 2, BREAK }, - { "break", 0, 1, 0, 0, 2, BREAK }, - { "ec", "Send Telnet Erase Character", 1, 0, 0, 2, EC }, - { "el", "Send Telnet Erase Line", 1, 0, 0, 2, EL }, - { "escape", "Send current escape character", 1, 0, send_esc, 1, 0 }, - { "ga", "Send Telnet 'Go Ahead' sequence", 1, 0, 0, 2, GA }, - { "ip", "Send Telnet Interrupt Process", 1, 0, 0, 2, IP }, - { "intp", 0, 1, 0, 0, 2, IP }, - { "interrupt", 0, 1, 0, 0, 2, IP }, - { "intr", 0, 1, 0, 0, 2, IP }, - { "nop", "Send Telnet 'No operation'", 1, 0, 0, 2, NOP }, - { "eor", "Send Telnet 'End of Record'", 1, 0, 0, 2, EOR }, - { "abort", "Send Telnet 'Abort Process'", 1, 0, 0, 2, ABORT }, - { "susp", "Send Telnet 'Suspend Process'", 1, 0, 0, 2, SUSP }, - { "eof", "Send Telnet End of File Character", 1, 0, 0, 2, xEOF }, - { "synch", "Perform Telnet 'Synch operation'", 1, 0, dosynch, 2, 0 }, - { "getstatus", "Send request for STATUS", 1, 0, get_status, 6, 0 }, - { "?", "Display send options", 0, 0, send_help, 0, 0 }, - { "help", 0, 0, 0, send_help, 0, 0 }, - { "do", 0, 0, 1, send_docmd, 3, 0 }, - { "dont", 0, 0, 1, send_dontcmd, 3, 0 }, - { "will", 0, 0, 1, send_willcmd, 3, 0 }, - { "wont", 0, 0, 1, send_wontcmd, 3, 0 }, - { 0 } + { "ao", "Send Telnet Abort output", 1, 0, NULL, 2, AO }, + { "ayt", "Send Telnet 'Are You There'", 1, 0, NULL, 2, AYT }, + { "brk", "Send Telnet Break", 1, 0, NULL, 2, BREAK }, + { "break", NULL, 1, 0, NULL, 2, BREAK }, + { "ec", "Send Telnet Erase Character", 1, 0, NULL, 2, EC }, + { "el", "Send Telnet Erase Line", 1, 0, NULL, 2, EL }, + { "escape", "Send current escape character",1, 0, (int (*)(char *, ...))send_esc, 1, 0 }, + { "ga", "Send Telnet 'Go Ahead' sequence", 1, 0, NULL, 2, GA }, + { "ip", "Send Telnet Interrupt Process",1, 0, NULL, 2, IP }, + { "intp", NULL, 1, 0, NULL, 2, IP }, + { "interrupt", NULL, 1, 0, NULL, 2, IP }, + { "intr", NULL, 1, 0, NULL, 2, IP }, + { "nop", "Send Telnet 'No operation'", 1, 0, NULL, 2, NOP }, + { "eor", "Send Telnet 'End of Record'", 1, 0, NULL, 2, EOR }, + { "abort", "Send Telnet 'Abort Process'", 1, 0, NULL, 2, ABORT }, + { "susp", "Send Telnet 'Suspend Process'",1, 0, NULL, 2, SUSP }, + { "eof", "Send Telnet End of File Character", 1, 0, NULL, 2, xEOF }, + { "synch", "Perform Telnet 'Synch operation'", 1, 0, (int (*)(char *, ...))dosynch, 2, 0 }, + { "getstatus", "Send request for STATUS", 1, 0, (int (*)(char *, ...))get_status, 6, 0 }, + { "?", "Display send options", 0, 0, (int (*)(char *, ...))send_help, 0, 0 }, + { "help", NULL, 0, 0, (int (*)(char *, ...))send_help, 0, 0 }, + { "do", NULL, 0, 1, (int (*)(char *, ...))send_docmd, 3, 0 }, + { "dont", NULL, 0, 1, (int (*)(char *, ...))send_dontcmd, 3, 0 }, + { "will", NULL, 0, 1, (int (*)(char *, ...))send_willcmd, 3, 0 }, + { "wont", NULL, 0, 1, (int (*)(char *, ...))send_wontcmd, 3, 0 }, + { NULL, NULL, 0, 0, NULL, 0, 0 } }; #define GETSEND(name) ((struct sendlist *) genget(name, (char **) Sendlist, \ sizeof(struct sendlist))) - static int -sendcmd(argc, argv) - int argc; - char **argv; +static int +sendcmd(int argc, char *argv[]) { int count; /* how many bytes we are going to need to send */ int i; @@ -349,7 +340,7 @@ sendcmd(argc, argv) printf("Unknown send argument '%s'\n'send ?' for help.\n", argv[i]); return 0; - } else if (Ambiguous(s)) { + } else if (Ambiguous((void *)s)) { printf("Ambiguous send argument '%s'\n'send ?' for help.\n", argv[i]); return 0; @@ -361,7 +352,7 @@ sendcmd(argc, argv) return 0; } count += s->nbyte; - if (s->handler == send_help) { + if ((void *)s->handler == (void *)send_help) { send_help(); return 0; } @@ -387,7 +378,7 @@ sendcmd(argc, argv) for (i = 1; i < argc; i++) { if ((s = GETSEND(argv[i])) == 0) { fprintf(stderr, "Telnet 'send' error - argument disappeared!\n"); - (void) quit(); + quit(); /*NOTREACHED*/ } if (s->handler) { @@ -403,50 +394,47 @@ sendcmd(argc, argv) return (count == success); } - static int -send_esc() +static int +send_esc(void) { NETADD(escape); return 1; } - static int -send_docmd(name) - char *name; +static int +send_docmd(char *name) { return(send_tncmd(send_do, "do", name)); } - static int +static int send_dontcmd(name) char *name; { return(send_tncmd(send_dont, "dont", name)); } - static int -send_willcmd(name) - char *name; + +static int +send_willcmd(char *name) { return(send_tncmd(send_will, "will", name)); } - static int -send_wontcmd(name) - char *name; + +static int +send_wontcmd(char *name) { return(send_tncmd(send_wont, "wont", name)); } - int -send_tncmd(func, cmd, name) - void (*func)(); - char *cmd, *name; +static int +send_tncmd(void (*func)(int, int), const char *cmd, char *name) { char **cpp; extern char *telopts[]; - register int val = 0; + int val = 0; if (isprefix(name, "help") || isprefix(name, "?")) { - register int col, len; + int col, len; printf("Usage: send %s \n", cmd); printf("\"value\" must be from 0 to 255\n"); @@ -474,7 +462,7 @@ send_tncmd(func, cmd, name) if (cpp) { val = cpp - telopts; } else { - register char *cp = name; + char *cp = name; while (*cp >= '0' && *cp <= '9') { val *= 10; @@ -499,8 +487,8 @@ send_tncmd(func, cmd, name) return 1; } - static int -send_help() +static int +send_help(void) { struct sendlist *s; /* pointer to current command */ for (s = Sendlist; s->name; s++) { @@ -515,15 +503,15 @@ send_help() * to by the arguments to the "toggle" command. */ - static int -lclchars() +static int +lclchars(void) { donelclchars = 1; return 1; } - static int -togdebug() +static int +togdebug(void) { #ifndef NOT43 if (net > 0 && @@ -541,8 +529,8 @@ togdebug() } - static int -togcrlf() +static int +togcrlf(void) { if (crlf) { printf("Will send carriage returns as telnet .\n"); @@ -554,9 +542,8 @@ togcrlf() int binmode; - static int -togbinary(val) - int val; +static int +togbinary(int val) { donebinarytoggle = 1; @@ -593,9 +580,8 @@ togbinary(val) return 1; } - static int -togrbinary(val) - int val; +static int +togrbinary(int val) { donebinarytoggle = 1; @@ -620,9 +606,8 @@ togrbinary(val) return 1; } - static int -togxbinary(val) - int val; +static int +togxbinary(int val) { donebinarytoggle = 1; @@ -647,15 +632,12 @@ togxbinary(val) return 1; } - -static int togglehelp P((void)); - struct togglelist { - char *name; /* name of toggle */ - char *help; /* help message */ - int (*handler)(); /* routine to do actual setting */ + const char *name; /* name of toggle */ + const char *help; /* help message */ + int (*handler)(int); /* routine to do actual setting */ int *variable; - char *actionexplanation; + const char *actionexplanation; }; static struct togglelist Togglelist[] = { @@ -691,7 +673,7 @@ static struct togglelist Togglelist[] = { 0 }, { "crlf", "sending carriage returns as telnet ", - togcrlf, + (int (*)(int))togcrlf, &crlf, 0 }, { "crmod", @@ -701,25 +683,13 @@ static struct togglelist Togglelist[] = { "map carriage return on output" }, { "localchars", "local recognition of certain control characters", - lclchars, + (int (*)(int))lclchars, &localchars, "recognize certain control characters" }, - { " ", "", 0 }, /* empty line */ -#if defined(unix) && defined(TN3270) - { "apitrace", - "(debugging) toggle tracing of API transactions", - 0, - &apitrace, - "trace API transactions" }, - { "cursesdata", - "(debugging) toggle printing of hexadecimal curses data", - 0, - &cursesdata, - "print hexadecimal representation of curses data" }, -#endif /* defined(unix) && defined(TN3270) */ + { " ", "", NULL, NULL, NULL }, /* empty line */ { "debug", "debugging", - togdebug, + (int (*)(int))togdebug, &debug, "turn on socket level debugging" }, { "netdata", @@ -737,24 +707,27 @@ static struct togglelist Togglelist[] = { 0, &showoptions, "show option processing" }, -#if defined(unix) { "termdata", "(debugging) toggle printing of hexadecimal terminal data", 0, &termdata, "print hexadecimal representation of terminal traffic" }, -#endif /* defined(unix) */ { "?", - 0, - togglehelp }, + NULL, + (int (*)(int))togglehelp, + NULL, + NULL }, + { NULL, NULL, NULL, NULL, NULL }, { "help", - 0, - togglehelp }, - { 0 } + NULL, + (int (*)(int))togglehelp, + NULL, + NULL }, + { NULL, NULL, NULL, NULL, NULL } }; - static int -togglehelp() +static int +togglehelp(void) { struct togglelist *c; @@ -771,9 +744,8 @@ togglehelp() return 0; } - static void -settogglehelp(set) - int set; +static void +settogglehelp(int set) { struct togglelist *c; @@ -791,10 +763,8 @@ settogglehelp(set) #define GETTOGGLE(name) (struct togglelist *) \ genget(name, (char **) Togglelist, sizeof(struct togglelist)) - static int -toggle(argc, argv) - int argc; - char *argv[]; +static int +toggle(int argc, char *argv[]) { int retval = 1; char *name; @@ -810,7 +780,7 @@ toggle(argc, argv) while (argc--) { name = *argv++; c = GETTOGGLE(name); - if (Ambiguous(c)) { + if (Ambiguous((void *)c)) { fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\n", name); return 0; @@ -839,56 +809,54 @@ toggle(argc, argv) */ #ifdef USE_TERMIO -struct termio new_tc = { 0 }; +struct termio new_tc = { 0, 0, 0, 0, {}, 0, 0 }; #endif struct setlist { - char *name; /* name */ - char *help; /* help information */ - void (*handler)(); + const char *name; /* name */ + const char *help; /* help information */ + void (*handler)(char *); cc_t *charp; /* where it is located at */ }; static struct setlist Setlist[] = { #ifdef KLUDGELINEMODE - { "echo", "character to toggle local echoing on/off", 0, &echoc }, + { "echo", "character to toggle local echoing on/off", NULL, &echoc }, #endif - { "escape", "character to escape back to telnet command mode", 0, &escape }, + { "escape", "character to escape back to telnet command mode", NULL, &escape }, { "rlogin", "rlogin escape character", 0, &rlogin }, { "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile}, - { " ", "" }, - { " ", "The following need 'localchars' to be toggled true", 0, 0 }, - { "flushoutput", "character to cause an Abort Output", 0, termFlushCharp }, - { "interrupt", "character to cause an Interrupt Process", 0, termIntCharp }, - { "quit", "character to cause an Abort process", 0, termQuitCharp }, - { "eof", "character to cause an EOF ", 0, termEofCharp }, - { " ", "" }, - { " ", "The following are for local editing in linemode", 0, 0 }, - { "erase", "character to use to erase a character", 0, termEraseCharp }, - { "kill", "character to use to erase a line", 0, termKillCharp }, - { "lnext", "character to use for literal next", 0, termLiteralNextCharp }, - { "susp", "character to cause a Suspend Process", 0, termSuspCharp }, - { "reprint", "character to use for line reprint", 0, termRprntCharp }, - { "worderase", "character to use to erase a word", 0, termWerasCharp }, - { "start", "character to use for XON", 0, termStartCharp }, - { "stop", "character to use for XOFF", 0, termStopCharp }, - { "forw1", "alternate end of line character", 0, termForw1Charp }, - { "forw2", "alternate end of line character", 0, termForw2Charp }, - { "ayt", "alternate AYT character", 0, termAytCharp }, - { 0 } + { " ", "", NULL, NULL }, + { " ", "The following need 'localchars' to be toggled true", NULL, NULL }, + { "flushoutput", "character to cause an Abort Output", NULL, termFlushCharp }, + { "interrupt", "character to cause an Interrupt Process", NULL, termIntCharp }, + { "quit", "character to cause an Abort process", NULL, termQuitCharp }, + { "eof", "character to cause an EOF ", NULL, termEofCharp }, + { " ", "", NULL, NULL }, + { " ", "The following are for local editing in linemode", NULL, NULL }, + { "erase", "character to use to erase a character", NULL, termEraseCharp }, + { "kill", "character to use to erase a line", NULL, termKillCharp }, + { "lnext", "character to use for literal next", NULL, termLiteralNextCharp }, + { "susp", "character to cause a Suspend Process", NULL, termSuspCharp }, + { "reprint", "character to use for line reprint", NULL, termRprntCharp }, + { "worderase", "character to use to erase a word", NULL, termWerasCharp }, + { "start", "character to use for XON", NULL, termStartCharp }, + { "stop", "character to use for XOFF", NULL, termStopCharp }, + { "forw1", "alternate end of line character", NULL, termForw1Charp }, + { "forw2", "alternate end of line character", NULL, termForw2Charp }, + { "ayt", "alternate AYT character", NULL, termAytCharp }, + { NULL, NULL, NULL, NULL } }; - static struct setlist * -getset(name) - char *name; +static struct setlist * +getset(char *name) { return (struct setlist *) genget(name, (char **) Setlist, sizeof(struct setlist)); } - void -set_escape_char(s) - char *s; +void +set_escape_char(char *s) { if (rlogin != _POSIX_VDISABLE) { rlogin = (s && *s) ? special(s) : _POSIX_VDISABLE; @@ -900,10 +868,8 @@ set_escape_char(s) } } - static int -setcmd(argc, argv) - int argc; - char *argv[]; +static int +setcmd(int argc, char *argv[]) { int value; struct setlist *ct; @@ -929,7 +895,7 @@ setcmd(argc, argv) fprintf(stderr, "'%s': unknown argument ('set ?' for help).\n", argv[1]); return 0; - } else if (Ambiguous(c)) { + } else if (Ambiguous((void *)c)) { fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n", argv[1]); return 0; @@ -953,7 +919,7 @@ setcmd(argc, argv) } else if (argc != 3) { printf("Format is 'set Name Value'\n'set ?' for help.\n"); return 0; - } else if (Ambiguous(ct)) { + } else if (Ambiguous((void *)ct)) { fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n", argv[1]); return 0; @@ -973,14 +939,12 @@ setcmd(argc, argv) return 1; } - static int -unsetcmd(argc, argv) - int argc; - char *argv[]; +static int +unsetcmd(int argc, char *argv[]) { struct setlist *ct; struct togglelist *c; - register char *name; + char *name; if (argc < 2) { fprintf(stderr, @@ -1007,7 +971,7 @@ unsetcmd(argc, argv) fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\n", name); return 0; - } else if (Ambiguous(c)) { + } else if (Ambiguous((void *)c)) { fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n", name); return 0; @@ -1021,7 +985,7 @@ unsetcmd(argc, argv) } if (c->handler) (*c->handler)(0); - } else if (Ambiguous(ct)) { + } else if (Ambiguous((void *)ct)) { fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n", name); return 0; @@ -1043,8 +1007,8 @@ unsetcmd(argc, argv) #ifdef KLUDGELINEMODE extern int kludgelinemode; - static int -dokludgemode() +static int +dokludgemode(void) { kludgelinemode = 1; send_wont(TELOPT_LINEMODE, 1); @@ -1054,8 +1018,8 @@ dokludgemode() } #endif - static int -dolinemode() +static int +dolinemode(void) { #ifdef KLUDGELINEMODE if (kludgelinemode) @@ -1066,8 +1030,8 @@ dolinemode() return 1; } - static int -docharmode() +static int +docharmode(void) { #ifdef KLUDGELINEMODE if (kludgelinemode) @@ -1079,9 +1043,8 @@ docharmode() return 1; } - static int -dolmmode(bit, on) - int bit, on; +static int +dolmmode(int bit, int on) { unsigned char c; extern int linemode; @@ -1100,39 +1063,37 @@ dolmmode(bit, on) return 1; } - int -setmod(bit) +static int +setmod(int bit) { return dolmmode(bit, 1); } - int -clearmode(bit) +static int +clearmode(int bit) { return dolmmode(bit, 0); } struct modelist { - char *name; /* command name */ - char *help; /* help string */ - int (*handler)(); /* routine which executes command */ + const char *name; /* command name */ + const char *help; /* help string */ + int (*handler)(int);/* routine which executes command */ int needconnect; /* Do we need to be connected to execute? */ int arg1; }; -extern int modehelp(); - static struct modelist ModeList[] = { - { "character", "Disable LINEMODE option", docharmode, 1 }, + { "character", "Disable LINEMODE option", (int (*)(int))docharmode, 1, 0 }, #ifdef KLUDGELINEMODE - { "", "(or disable obsolete line-by-line mode)", 0 }, + { "", "(or disable obsolete line-by-line mode)", NULL, 0, 0 }, #endif - { "line", "Enable LINEMODE option", dolinemode, 1 }, + { "line", "Enable LINEMODE option", (int (*)(int))dolinemode, 1, 0 }, #ifdef KLUDGELINEMODE - { "", "(or enable obsolete line-by-line mode)", 0 }, + { "", "(or enable obsolete line-by-line mode)", NULL, 0, 0 }, #endif - { "", "", 0 }, - { "", "These require the LINEMODE option to be enabled", 0 }, + { "", "", NULL, 0, 0 }, + { "", "These require the LINEMODE option to be enabled", NULL, 0, 0 }, { "isig", "Enable signal trapping", setmod, 1, MODE_TRAPSIG }, { "+isig", 0, setmod, 1, MODE_TRAPSIG }, { "-isig", "Disable signal trapping", clearmode, 1, MODE_TRAPSIG }, @@ -1145,18 +1106,18 @@ static struct modelist ModeList[] = { { "litecho", "Enable literal character echo", setmod, 1, MODE_LIT_ECHO }, { "+litecho", 0, setmod, 1, MODE_LIT_ECHO }, { "-litecho", "Disable literal character echo", clearmode, 1, MODE_LIT_ECHO }, - { "help", 0, modehelp, 0 }, + { "help", 0, (int (*)(int))modehelp, 0, 0 }, #ifdef KLUDGELINEMODE - { "kludgeline", 0, dokludgemode, 1 }, + { "kludgeline", 0, (int (*)(int))dokludgemode, 1, 0 }, #endif - { "", "", 0 }, - { "?", "Print help information", modehelp, 0 }, - { 0 }, + { "", "", NULL, 0, 0 }, + { "?", "Print help information", (int (*)(int))modehelp, 0, 0 }, + { NULL, NULL, NULL, 0, 0 }, }; - int -modehelp() +static int +modehelp(void) { struct modelist *mt; @@ -1175,10 +1136,8 @@ modehelp() #define GETMODECMD(name) (struct modelist *) \ genget(name, (char **) ModeList, sizeof(struct modelist)) - static int -modecmd(argc, argv) - int argc; - char *argv[]; +static int +modecmd(int argc, char *argv[]) { struct modelist *mt; @@ -1187,7 +1146,7 @@ modecmd(argc, argv) printf("'mode ?' for help.\n"); } else if ((mt = GETMODECMD(argv[1])) == 0) { fprintf(stderr, "Unknown mode '%s' ('mode ?' for help).\n", argv[1]); - } else if (Ambiguous(mt)) { + } else if (Ambiguous((void *)mt)) { fprintf(stderr, "Ambiguous mode '%s' ('mode ?' for help).\n", argv[1]); } else if (mt->needconnect && !connected) { printf("?Need to be connected first.\n"); @@ -1203,10 +1162,8 @@ modecmd(argc, argv) * "display" command. */ - static int -display(argc, argv) - int argc; - char *argv[]; +static int +display(int argc, char *argv[]) { struct togglelist *tl; struct setlist *sl; @@ -1241,7 +1198,7 @@ display(argc, argv) for (i = 1; i < argc; i++) { sl = getset(argv[i]); tl = GETTOGGLE(argv[i]); - if (Ambiguous(sl) || Ambiguous(tl)) { + if (Ambiguous((void *)sl) || Ambiguous((void *)tl)) { printf("?Ambiguous argument '%s'.\n", argv[i]); return 0; } else if (!sl && !tl) { @@ -1271,12 +1228,10 @@ display(argc, argv) /* * Set the escape character. */ - static int -setescape(argc, argv) - int argc; - char *argv[]; +static int +setescape(int argc, char *argv[]) { - register char *arg; + char *arg; char buf[50]; printf( @@ -1291,16 +1246,12 @@ setescape(argc, argv) } if (arg[0] != '\0') escape = arg[0]; - if (!In3270) { - printf("Escape character is '%s'.\n", control(escape)); - } (void) fflush(stdout); return 1; } - /*VARARGS*/ - static int -togcrmod() +static int +togcrmod(void) { crmod = !crmod; printf("Deprecated usage - please use 'toggle crmod' in the future.\n"); @@ -1309,16 +1260,15 @@ togcrmod() return 1; } - /*VARARGS*/ - int -suspend() +static int +suspend(void) { #ifdef SIGTSTP setcommandmode(); { - long oldrows, oldcols, newrows, newcols, err; + long oldrows, oldcols, newrows, newcols, err_; - err = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0; + err_ = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0; (void) kill(0, SIGTSTP); /* * If we didn't get the window size before the SUSPEND, but we @@ -1326,7 +1276,7 @@ suspend() * we are set up for the right window size. */ if (TerminalWindowSize(&newrows, &newcols) && connected && - (err || ((oldrows != newrows) || (oldcols != newcols)))) { + (err_ || ((oldrows != newrows) || (oldcols != newcols)))) { sendnaws(); } } @@ -1339,18 +1289,14 @@ suspend() return 1; } -#if !defined(TN3270) - /*ARGSUSED*/ - int -shell(argc, argv) - int argc; - char *argv[]; +static int +shell(int argc, char *argv[] __unused) { - long oldrows, oldcols, newrows, newcols, err; + long oldrows, oldcols, newrows, newcols, err_; setcommandmode(); - err = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0; + err_ = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0; switch(vfork()) { case -1: perror("Fork failed\n"); @@ -1361,7 +1307,7 @@ shell(argc, argv) /* * Fire up the shell in the child. */ - register char *shellp, *shellname; + const char *shellp, *shellname; shellp = getenv("SHELL"); if (shellp == NULL) @@ -1381,22 +1327,16 @@ shell(argc, argv) (void)wait((int *)0); /* Wait for the shell to complete */ if (TerminalWindowSize(&newrows, &newcols) && connected && - (err || ((oldrows != newrows) || (oldcols != newcols)))) { + (err_ || ((oldrows != newrows) || (oldcols != newcols)))) { sendnaws(); } break; } return 1; } -#else /* !defined(TN3270) */ -extern int shell(); -#endif /* !defined(TN3270) */ - /*VARARGS*/ - static int -bye(argc, argv) - int argc; /* Number of arguments */ - char *argv[]; /* arguments */ +static int +bye(int argc, char *argv[]) { extern int resettermname; @@ -1408,9 +1348,6 @@ bye(argc, argv) resettermname = 1; /* reset options */ tninit(); -#if defined(TN3270) - SetIn3270(); /* Get out of 3270 mode */ -#endif /* defined(TN3270) */ } if ((argc != 2) || (strcmp(argv[1], "fromquit") != 0)) { longjmp(toplevel, 1); @@ -1419,18 +1356,15 @@ bye(argc, argv) return 1; /* Keep lint, etc., happy */ } -/*VARARGS*/ - int -quit() +void +quit(void) { (void) call(bye, "bye", "fromquit", 0); Exit(0); - /*NOTREACHED*/ } -/*VARARGS*/ - int -logout() +static int +logout(void) { send_do(TELOPT_LOGOUT, 1); (void) netflush(); @@ -1443,28 +1377,28 @@ logout() */ struct slclist { - char *name; - char *help; - void (*handler)(); + const char *name; + const char *help; + void (*handler)(int); int arg; }; -static void slc_help(); +static void slc_help(void); struct slclist SlcList[] = { { "export", "Use local special character definitions", - slc_mode_export, 0 }, + (void (*)(int))slc_mode_export, 0 }, { "import", "Use remote special character definitions", slc_mode_import, 1 }, { "check", "Verify remote special character definitions", slc_mode_import, 0 }, - { "help", 0, slc_help, 0 }, - { "?", "Print help information", slc_help, 0 }, - { 0 }, + { "help", NULL, (void (*)(int))slc_help, 0 }, + { "?", "Print help information", (void (*)(int))slc_help, 0 }, + { NULL, NULL, NULL, 0 }, }; - static void -slc_help() +static void +slc_help(void) { struct slclist *c; @@ -1478,18 +1412,15 @@ slc_help() } } - static struct slclist * -getslc(name) - char *name; +static struct slclist * +getslc(char *name) { return (struct slclist *) genget(name, (char **) SlcList, sizeof(struct slclist)); } - static int -slccmd(argc, argv) - int argc; - char *argv[]; +static int +slccmd(int argc, char *argv[]) { struct slclist *c; @@ -1504,7 +1435,7 @@ slccmd(argc, argv) argv[1]); return 0; } - if (Ambiguous(c)) { + if (Ambiguous((void *)c)) { fprintf(stderr, "'%s': ambiguous argument ('slc ?' for help).\n", argv[1]); return 0; @@ -1519,18 +1450,18 @@ slccmd(argc, argv) */ struct envlist { - char *name; - char *help; - void (*handler)(); + const char *name; + const char *help; + void (*handler)(unsigned char *, unsigned char *); int narg; }; extern struct env_lst * - env_define P((unsigned char *, unsigned char *)); + env_define P((const unsigned char *, unsigned char *)); extern void env_undefine P((unsigned char *)), - env_export P((unsigned char *)), - env_unexport P((unsigned char *)), + env_export P((const unsigned char *)), + env_unexport P((const unsigned char *)), env_send P((unsigned char *)), #if defined(OLD_ENVIRON) && defined(ENV_HACK) env_varval P((unsigned char *)), @@ -1541,27 +1472,27 @@ static void struct envlist EnvList[] = { { "define", "Define an environment variable", - (void (*)())env_define, 2 }, + (void (*)(unsigned char *, unsigned char *))env_define, 2 }, { "undefine", "Undefine an environment variable", - env_undefine, 1 }, + (void (*)(unsigned char *, unsigned char *))env_undefine, 1 }, { "export", "Mark an environment variable for automatic export", - env_export, 1 }, + (void (*)(unsigned char *, unsigned char *))env_export, 1 }, { "unexport", "Don't mark an environment variable for automatic export", - env_unexport, 1 }, - { "send", "Send an environment variable", env_send, 1 }, + (void (*)(unsigned char *, unsigned char *))env_unexport, 1 }, + { "send", "Send an environment variable", (void (*)(unsigned char *, unsigned char *))env_send, 1 }, { "list", "List the current environment variables", - env_list, 0 }, + (void (*)(unsigned char *, unsigned char *))env_list, 0 }, #if defined(OLD_ENVIRON) && defined(ENV_HACK) { "varval", "Reverse VAR and VALUE (auto, right, wrong, status)", - env_varval, 1 }, + (void (*)(unsigned char *, unsigned char *))env_varval, 1 }, #endif - { "help", 0, env_help, 0 }, - { "?", "Print help information", env_help, 0 }, - { 0 }, + { "help", NULL, (void (*)(unsigned char *, unsigned char *))env_help, 0 }, + { "?", "Print help information", (void (*)(unsigned char *, unsigned char *))env_help, 0 }, + { NULL, NULL, NULL, 0 }, }; - static void -env_help() +static void +env_help(void) { struct envlist *c; @@ -1575,18 +1506,15 @@ env_help() } } - static struct envlist * -getenvcmd(name) - char *name; +static struct envlist * +getenvcmd(char *name) { return (struct envlist *) genget(name, (char **) EnvList, sizeof(struct envlist)); } - int -env_cmd(argc, argv) - int argc; - char *argv[]; +static int +env_cmd(int argc, char *argv[]) { struct envlist *c; @@ -1601,7 +1529,7 @@ env_cmd(argc, argv) argv[1]); return 0; } - if (Ambiguous(c)) { + if (Ambiguous((void *)c)) { fprintf(stderr, "'%s': ambiguous argument ('environ ?' for help).\n", argv[1]); return 0; @@ -1628,25 +1556,24 @@ struct env_lst { struct env_lst envlisthead; - struct env_lst * -env_find(var) - unsigned char *var; +static struct env_lst * +env_find(const unsigned char *var) { - register struct env_lst *ep; + struct env_lst *ep; for (ep = envlisthead.next; ep; ep = ep->next) { - if (strcmp((char *)ep->var, (char *)var) == 0) + if (strcmp(ep->var, var) == 0) return(ep); } return(NULL); } - void -env_init() +void +env_init(void) { extern char **environ; - register char **epp, *cp; - register struct env_lst *ep; + char **epp, *cp; + struct env_lst *ep; for (epp = environ; *epp; epp++) { if ((cp = strchr(*epp, '='))) { @@ -1681,18 +1608,17 @@ env_init() * don't export the USER variable. */ if ((env_find("USER") == NULL) && (ep = env_find("LOGNAME"))) { - env_define((unsigned char *)"USER", ep->value); - env_unexport((unsigned char *)"USER"); + env_define("USER", ep->value); + env_unexport("USER"); } - env_export((unsigned char *)"DISPLAY"); - env_export((unsigned char *)"PRINTER"); + env_export("DISPLAY"); + env_export("PRINTER"); } - struct env_lst * -env_define(var, value) - unsigned char *var, *value; +struct env_lst * +env_define(const unsigned char *var, unsigned char *value) { - register struct env_lst *ep; + struct env_lst *ep; if ((ep = env_find(var))) { if (ep->var) @@ -1709,16 +1635,15 @@ env_define(var, value) } ep->welldefined = opt_welldefined(var); ep->export = 1; - ep->var = (unsigned char *)strdup((char *)var); - ep->value = (unsigned char *)strdup((char *)value); + ep->var = strdup(var); + ep->value = strdup(value); return(ep); } - void -env_undefine(var) - unsigned char *var; +void +env_undefine(unsigned char *var) { - register struct env_lst *ep; + struct env_lst *ep; if ((ep = env_find(var))) { ep->prev->next = ep->next; @@ -1732,31 +1657,28 @@ env_undefine(var) } } - void -env_export(var) - unsigned char *var; +void +env_export(const unsigned char *var) { - register struct env_lst *ep; + struct env_lst *ep; if ((ep = env_find(var))) ep->export = 1; } - void -env_unexport(var) - unsigned char *var; +void +env_unexport(const unsigned char *var) { - register struct env_lst *ep; + struct env_lst *ep; if ((ep = env_find(var))) ep->export = 0; } - void -env_send(var) - unsigned char *var; +void +env_send(unsigned char *var) { - register struct env_lst *ep; + struct env_lst *ep; if (my_state_is_wont(TELOPT_NEW_ENVIRON) #ifdef OLD_ENVIRON @@ -1779,10 +1701,10 @@ env_send(var) env_opt_end(0); } - void -env_list() +void +env_list(void) { - register struct env_lst *ep; + struct env_lst *ep; for (ep = envlisthead.next; ep; ep = ep->next) { printf("%c %-20s %s\n", ep->export ? '*' : ' ', @@ -1790,9 +1712,8 @@ env_list() } } - unsigned char * -env_default(init, welldefined) - int init; +unsigned char * +env_default(int init, int welldefined) { static struct env_lst *nep = NULL; @@ -1809,11 +1730,10 @@ env_default(init, welldefined) return(NULL); } - unsigned char * -env_getvalue(var) - unsigned char *var; +unsigned char * +env_getvalue(const unsigned char *var) { - register struct env_lst *ep; + struct env_lst *ep; if ((ep = env_find(var))) return(ep->value); @@ -1821,9 +1741,8 @@ env_getvalue(var) } #if defined(OLD_ENVIRON) && defined(ENV_HACK) - void -env_varval(what) - unsigned char *what; +void +env_varval(unsigned char *what) { extern int old_env_var, old_env_value, env_auto; int len = strlen((char *)what); @@ -1860,47 +1779,12 @@ unknown: -#if defined(unix) && defined(TN3270) - static void -filestuff(fd) - int fd; -{ - int res; - -#ifdef F_GETOWN - setconnmode(0); - res = fcntl(fd, F_GETOWN, 0); - setcommandmode(); - - if (res == -1) { - perror("fcntl"); - return; - } - printf("\tOwner is %d.\n", res); -#endif - - setconnmode(0); - res = fcntl(fd, F_GETFL, 0); - setcommandmode(); - - if (res == -1) { - perror("fcntl"); - return; - } -#ifdef notdef - printf("\tFlags are 0x%x: %s\n", res, decodeflags(res)); -#endif -} -#endif /* defined(unix) && defined(TN3270) */ - /* * Print status about the connection. */ - /*ARGSUSED*/ - static int -status(argc, argv) - int argc; - char *argv[]; +/*ARGSUSED*/ +static int +status(int argc, char *argv[]) { if (connected) { printf("Connected to %s.\n", hostname); @@ -1929,37 +1813,8 @@ status(argc, argv) } else { printf("No connection.\n"); } -# if !defined(TN3270) printf("Escape character is '%s'.\n", control(escape)); (void) fflush(stdout); -# else /* !defined(TN3270) */ - if ((!In3270) && ((argc < 2) || strcmp(argv[1], "notmuch"))) { - printf("Escape character is '%s'.\n", control(escape)); - } -# if defined(unix) - if ((argc >= 2) && !strcmp(argv[1], "everything")) { - printf("SIGIO received %d time%s.\n", - sigiocount, (sigiocount == 1)? "":"s"); - if (In3270) { - printf("Process ID %d, process group %d.\n", - getpid(), getpgrp(getpid())); - printf("Terminal input:\n"); - filestuff(tin); - printf("Terminal output:\n"); - filestuff(tout); - printf("Network socket:\n"); - filestuff(net); - } - } - if (In3270 && transcom) { - printf("Transparent mode command is '%s'.\n", transcom); - } -# endif /* defined(unix) */ - (void) fflush(stdout); - if (In3270) { - return 0; - } -# endif /* defined(TN3270) */ return 1; } @@ -1967,16 +1822,15 @@ status(argc, argv) /* * Function that gets called when SIGINFO is received. */ - void -ayt_status() +void +ayt_status(void) { (void) call(status, "status", "notmuch", 0); } #endif static const char * -sockaddr_ntop(sa) - struct sockaddr *sa; +sockaddr_ntop(struct sockaddr *sa) { void *addr; static char addrbuf[INET6_ADDRSTRLEN]; @@ -2002,10 +1856,7 @@ sockaddr_ntop(sa) #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) static int -setpolicy(net, res, policy) - int net; - struct addrinfo *res; - char *policy; +setpolicy(int lnet, struct addrinfo *res, char *policy) { char *buf; int level; @@ -2021,12 +1872,13 @@ setpolicy(net, res, policy) } level = res->ai_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6; optname = res->ai_family == AF_INET ? IP_IPSEC_POLICY : IPV6_IPSEC_POLICY; - if (setsockopt(net, level, optname, buf, ipsec_get_policylen(buf)) < 0){ + if (setsockopt(lnet, level, optname, buf, ipsec_get_policylen(buf)) < 0){ perror("setsockopt"); return -1; } free(buf); + return 0; } #endif @@ -2037,8 +1889,7 @@ setpolicy(net, res, policy) * Return 1, if retry with another af is OK. Else, return 0. */ static int -switch_af(aip) - struct addrinfo **aip; +switch_af(struct addrinfo **aip) { int nextaf; struct addrinfo *ai; @@ -2056,14 +1907,12 @@ switch_af(aip) } #endif - int -tn(argc, argv) - int argc; - char *argv[]; +int +tn(int argc, char *argv[]) { char *srp = 0; int proto, opt; - int sourceroute(), srlen; + int srlen; int srcroute = 0, result; char *cmd, *hostp = 0, *portp = 0, *user = 0; char *src_addr = NULL; @@ -2157,7 +2006,7 @@ tn(argc, argv) memset(&su, 0, sizeof su); su.sun_family = AF_UNIX; strncpy(su.sun_path, hostp, sizeof su.sun_path); - printf("Trying %s...\n", &su.sun_path); + printf("Trying %s...\n", hostp); net = socket(PF_UNIX, SOCK_STREAM, 0); if ( net < 0) { perror("socket"); @@ -2182,7 +2031,7 @@ tn(argc, argv) hostname = hostp; if (!portp) { telnetport = 1; - portp = "telnet"; + portp = strdup("telnet"); } else if (*portp == '-') { portp++; telnetport = 1; @@ -2363,8 +2212,8 @@ tn(argc, argv) } } if (user) { - env_define((unsigned char *)"USER", (unsigned char *)user); - env_export((unsigned char *)"USER"); + env_define("USER", user); + env_export("USER"); } (void) call(status, "status", "notmuch", 0); if (setjmp(peerdied) == 0) @@ -2395,13 +2244,8 @@ static char togglestring[] ="toggle operating parameters ('toggle ?' for more)", slchelp[] = "change state of special charaters ('slc ?' for more)", displayhelp[] = "display operating parameters", -#if defined(TN3270) && defined(unix) - transcomhelp[] = "specify Unix command for transparent mode pipe", -#endif /* defined(TN3270) && defined(unix) */ -#if defined(unix) zhelp[] = "suspend telnet", -#endif /* defined(unix) */ -#if defined(OPIE) +#ifdef OPIE opiehelp[] = "compute response to OPIE challenge", #endif shellhelp[] = "invoke a subshell", @@ -2410,35 +2254,26 @@ static char static Command cmdtab[] = { { "close", closehelp, bye, 1 }, - { "logout", logouthelp, logout, 1 }, + { "logout", logouthelp, (int (*)(int, char **))logout, 1 }, { "display", displayhelp, display, 0 }, { "mode", modestring, modecmd, 0 }, { "telnet", openhelp, tn, 0 }, { "open", openhelp, tn, 0 }, - { "quit", quithelp, quit, 0 }, + { "quit", quithelp, (int (*)(int, char **))quit, 0 }, { "send", sendhelp, sendcmd, 0 }, { "set", sethelp, setcmd, 0 }, { "unset", unsethelp, unsetcmd, 0 }, { "status", statushelp, status, 0 }, { "toggle", togglestring, toggle, 0 }, { "slc", slchelp, slccmd, 0 }, -#if defined(TN3270) && defined(unix) - { "transcom", transcomhelp, settranscom, 0 }, -#endif /* defined(TN3270) && defined(unix) */ -#if defined(unix) - { "z", zhelp, suspend, 0 }, -#endif /* defined(unix) */ -#if defined(TN3270) + { "z", zhelp, (int (*)(int, char **))suspend, 0 }, { "!", shellhelp, shell, 1 }, -#else - { "!", shellhelp, shell, 0 }, -#endif { "environ", envhelp, env_cmd, 0 }, { "?", helphelp, help, 0 }, -#if defined(OPIE) +#ifdef OPIE { "opie", opiehelp, opie_calc, 0 }, #endif - { 0, 0, 0, 0 } + { NULL, NULL, NULL, 0 } }; static char crmodhelp[] = "deprecated command -- use 'toggle crmod' instead"; @@ -2447,8 +2282,8 @@ static char escapehelp[] = "deprecated command -- use 'set escape' instead"; static Command cmdtab2[] = { { "help", 0, help, 0 }, { "escape", escapehelp, setescape, 0 }, - { "crmod", crmodhelp, togcrmod, 0 }, - { 0, 0, 0, 0 } + { "crmod", crmodhelp, (int (*)(int, char **))togcrmod, 0 }, + { NULL, NULL, NULL, 0 } }; @@ -2456,30 +2291,22 @@ static Command cmdtab2[] = { * Call routine with argc, argv set from args (terminated by 0). */ - /*VARARGS1*/ - static int -call(va_alist) - va_dcl +static int +call(intrtn_t routine, ...) { va_list ap; - typedef int (*intrtn_t)(); - intrtn_t routine; char *args[100]; int argno = 0; - va_start(ap); - routine = (va_arg(ap, intrtn_t)); - while ((args[argno++] = va_arg(ap, char *)) != 0) { - ; - } + va_start(ap, routine); + while ((args[argno++] = va_arg(ap, char *)) != 0); va_end(ap); return (*routine)(argno-1, args); } - static Command * -getcmd(name) - char *name; +static Command * +getcmd(char *name) { Command *cm; @@ -2488,28 +2315,23 @@ getcmd(name) return (Command *) genget(name, (char **) cmdtab2, sizeof(Command)); } - void -command(top, tbuf, cnt) - int top; - char *tbuf; - int cnt; +void +command(int top, const char *tbuf, int cnt) { - register Command *c; + Command *c; setcommandmode(); if (!top) { putchar('\n'); -#if defined(unix) } else { (void) signal(SIGINT, SIG_DFL); (void) signal(SIGQUIT, SIG_DFL); -#endif /* defined(unix) */ } for (;;) { if (rlogin == _POSIX_VDISABLE) printf("%s> ", prompt); if (tbuf) { - register char *cp; + char *cp; cp = line; while (cnt > 0 && (*cp++ = *tbuf++) != '\n') cnt--; @@ -2538,7 +2360,7 @@ command(top, tbuf, cnt) break; } c = getcmd(margv[0]); - if (Ambiguous(c)) { + if (Ambiguous((void *)c)) { printf("?Ambiguous command\n"); continue; } @@ -2559,25 +2381,17 @@ command(top, tbuf, cnt) longjmp(toplevel, 1); /*NOTREACHED*/ } -#if defined(TN3270) - if (shell_active == 0) { - setconnmode(0); - } -#else /* defined(TN3270) */ setconnmode(0); -#endif /* defined(TN3270) */ } } /* * Help command. */ - static int -help(argc, argv) - int argc; - char *argv[]; +static int +help(int argc, char *argv[]) { - register Command *c; + Command *c; if (argc == 1) { printf("Commands may be abbreviated. Commands are:\n\n"); @@ -2589,10 +2403,10 @@ help(argc, argv) return 0; } else while (--argc > 0) { - register char *arg; + char *arg; arg = *++argv; c = getcmd(arg); - if (Ambiguous(c)) + if (Ambiguous((void *)c)) printf("?Ambiguous help command %s\n", arg); else if (c == (Command *)0) printf("?Invalid help command %s\n", arg); @@ -2605,11 +2419,10 @@ help(argc, argv) static char *rcname = 0; static char rcbuf[128]; - void -cmdrc(m1, m2) - char *m1, *m2; +void +cmdrc(char *m1, char *m2) { - register Command *c; + Command *c; FILE *rcfile; int gotmachine = 0; int l1 = strlen(m1); @@ -2666,7 +2479,7 @@ cmdrc(m1, m2) if (margv[0] == 0) continue; c = getcmd(margv[0]); - if (Ambiguous(c)) { + if (Ambiguous((void *)c)) { printf("?Ambiguous command: %s\n", margv[0]); continue; } @@ -2743,27 +2556,17 @@ cmdrc(m1, m2) * *optp: This will be filled in with appropriate option for * setsockopt, as socket protocol family. */ -int -sourceroute(ai, arg, cpp, lenp, protop, optp) - struct addrinfo *ai; - char *arg; - char **cpp; - int *lenp; - int *protop; - int *optp; +static int +sourceroute(struct addrinfo *ai, char *arg, char **cpp, int *lenp, int *protop, int *optp) { static char buf[1024 + ALIGNBYTES]; /*XXX*/ struct cmsghdr *cmsg; -#ifdef sysV88 - static IOPTN ipopt; -#endif char *cp, *cp2, *lsrp, *ep; - register int tmp; - struct sockaddr_in *sin; + struct sockaddr_in *_sin; struct sockaddr_in6 *sin6; struct addrinfo hints, *res; int error; - register char c; + char c; /* * Verify the arguments, and make sure we have @@ -2779,7 +2582,7 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) break; #ifdef INET6 case AF_INET6: - if (*lenp < CMSG_SPACE(sizeof(struct ip6_rthdr) + + if (*lenp < (int)CMSG_SPACE(sizeof(struct ip6_rthdr) + sizeof(struct in6_addr))) return -1; break; @@ -2815,27 +2618,17 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) * route or a strict source route, and fill in * the begining of the option. */ -#ifndef sysV88 if (*cp == '!') { cp++; *lsrp++ = IPOPT_SSRR; } else *lsrp++ = IPOPT_LSRR; -#else - if (*cp == '!') { - cp++; - ipopt.io_type = IPOPT_SSRR; - } else - ipopt.io_type = IPOPT_LSRR; -#endif if (*cp != '@') return -1; -#ifndef sysV88 lsrp++; /* skip over length, we'll fill it in later */ *lsrp++ = 4; -#endif *protop = IPPROTO_IP; *optp = IP_OPTIONS; } @@ -2893,8 +2686,8 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) } else #endif { - sin = (struct sockaddr_in *)res->ai_addr; - memcpy(lsrp, (char *)&sin->sin_addr, 4); + _sin = (struct sockaddr_in *)res->ai_addr; + memcpy(lsrp, (char *)&_sin->sin_addr, 4); lsrp += 4; } if (cp2) @@ -2924,7 +2717,6 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) } else #endif { -#ifndef sysV88 if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) { *cpp = 0; *lenp = 0; @@ -2932,16 +2724,6 @@ sourceroute(ai, arg, cpp, lenp, protop, optp) } *lsrp++ = IPOPT_NOP; /* 32 bit word align it */ *lenp = lsrp - *cpp; -#else - ipopt.io_len = lsrp - *cpp; - if (ipopt.io_len <= 5) { /* Is 3 better ? */ - *cpp = 0; - *lenp = 0; - return -1; - } - *lenp = sizeof(ipopt); - *cpp = (char *) &ipopt; -#endif } freeaddrinfo(res); return 1; diff --git a/usr.bin/telnet/defines.h b/usr.bin/telnet/defines.h index 0978173..840666d 100644 --- a/usr.bin/telnet/defines.h +++ b/usr.bin/telnet/defines.h @@ -31,16 +31,11 @@ * SUCH DAMAGE. * * @(#)defines.h 8.1 (Berkeley) 6/6/93 + * $FreeBSD$ */ #define settimer(x) clocks.x = clocks.system++ -#if !defined(TN3270) - -#define SetIn3270() - -#endif /* !defined(TN3270) */ - #define NETADD(c) { *netoring.supply = c; ring_supplied(&netoring, 1); } #define NET2ADD(c1,c2) { NETADD(c1); NETADD(c2); } #define NETBYTES() (ring_full_count(&netoring)) diff --git a/usr.bin/telnet/externs.h b/usr.bin/telnet/externs.h index d70dfd7..33da93c 100644 --- a/usr.bin/telnet/externs.h +++ b/usr.bin/telnet/externs.h @@ -53,21 +53,13 @@ #include #include -#ifndef FILIO_H #include -#else -#include -#endif -# include +#include #ifdef USE_TERMIO # ifndef VINTR -# ifdef SYSV_TERMIO -# include -# else -# include -# define termio termios -# endif +# include # endif +# define termio termios #endif #if defined(NO_CC_T) || !defined(USE_TERMIO) # if !defined(USE_TERMIO) @@ -77,11 +69,7 @@ typedef unsigned char cc_t; # endif #endif -#ifndef NO_STRING_H #include -#else -#include -#endif #if defined(IPSEC) #include @@ -120,7 +108,6 @@ extern int flushout, /* flush output */ connected, /* Are we connected to the other side? */ globalmode, /* Mode tty should be in */ - In3270, /* Are we in 3270 mode? */ telnetport, /* Are we connected to the telnet port? */ localflow, /* Flow control handled locally */ restartany, /* If flow control, restart output on any character */ @@ -139,13 +126,7 @@ extern int crmod, netdata, /* Print out network data flow */ prettydump, /* Print "netdata" output in user readable format */ -#if defined(unix) -#if defined(TN3270) - cursesdata, /* Print out curses data flow */ - apitrace, /* Trace API transactions */ -#endif /* defined(TN3270) */ termdata, /* Print out terminal data flow */ -#endif /* defined(unix) */ debug, /* Debug level */ doaddrlookup, /* do a reverse lookup? */ clienteof; /* Client received EOF */ @@ -229,6 +210,16 @@ extern char #define set_his_want_state_dont set_my_want_state_wont #define set_his_want_state_wont set_my_want_state_dont +#if defined(USE_TERMIO) +#define SIG_FUNC_RET void +#else +#define SIG_FUNC_RET int +#endif + +#ifdef SIGINFO +extern SIG_FUNC_RET + ayt_status P((void)); +#endif extern FILE *NetTrace; /* Where debugging output goes */ @@ -242,23 +233,40 @@ extern jmp_buf toplevel; /* For error conditions. */ extern void - command P((int, char *, int)), - Dump P((int, unsigned char *, int)), - ExitString P((char *, int)), - init_3270 P((void)), - printoption P((char *, int, int)), - printsub P((int, unsigned char *, int)), + command P((int, const char *, int)), + Dump P((char, unsigned char *, int)), + env_init P((void)), + Exit P((int)), + ExitString P((const char *, int)), + init_network P((void)), + init_sys P((void)), + init_telnet P((void)), + init_terminal P((void)), + intp P((void)), + optionstatus P((void)), + printoption P((const char *, int, int)), + printsub P((char, unsigned char *, int)), + quit P((void)), + sendabort P((void)), + sendbrk P((void)), + sendeof P((void)), + sendsusp P((void)), sendnaws P((void)), + sendayt P((void)), setconnmode P((int)), setcommandmode P((void)), + set_escape_char P((char *s)), setneturg P((void)), sys_telnet_init P((void)), telnet P((char *)), tel_enter_binary P((int)), + tel_leave_binary P((int)), TerminalFlushOutput P((void)), TerminalNewMode P((int)), TerminalRestoreState P((void)), TerminalSaveState P((void)), + TerminalDefaultChars P((void)), + TerminalSpeeds P((long *, long *)), tninit P((void)), upcase P((char *)), willoption P((int)), @@ -287,16 +295,25 @@ extern void slc P((unsigned char *, int)), slc_check P((void)), slc_start_reply P((void)), - slc_add_reply P((int, int, int)), + slc_add_reply P((unsigned char, unsigned char, cc_t)), slc_end_reply P((void)); extern int + getconnmode P((void)), + opt_welldefined P((const char *)), NetClose P((int)), netflush P((void)), + process_rings P((int, int, int, int, int, int)), + rlogin_susp P((void)), SetSockOpt P((int, int, int, int)), slc_update P((void)), + stilloob P((void)), telrcv P((void)), + TerminalRead P((char *, int)), TerminalWrite P((char *, int)), TerminalAutoFlush P((void)), + TerminalWindowSize P((long *, long *)), + TerminalSpecialChars P((int)), + tn P((int, char **)), ttyflush P((int)); extern void @@ -308,11 +325,11 @@ extern void extern unsigned char *env_default P((int, int)), - *env_getvalue P((unsigned char *)); + *env_getvalue P((const unsigned char *)); extern int - get_status P((void)), - dosynch P((void)); + get_status P((char *)), + dosynch P((char *)); extern cc_t *tcval P((int)); @@ -464,26 +481,7 @@ extern Ring ttyoring, ttyiring; -/* Tn3270 section */ -#if defined(TN3270) - -extern int - HaveInput, /* Whether an asynchronous I/O indication came in */ - noasynchtty, /* Don't do signals on I/O (SIGURG, SIGIO) */ - noasynchnet, /* Don't do signals on I/O (SIGURG, SIGIO) */ - sigiocount, /* Count of SIGIO receptions */ - shell_active; /* Subshell is active */ - -extern char - *Ibackp, /* Oldest byte of 3270 data */ - Ibuf[], /* 3270 buffer */ - *Ifrontp, /* Where next 3270 byte goes */ - tline[], - *transcom; /* Transparent command */ - -extern int - settranscom P((int, char**)); - extern void - inputAvailable P((int)); -#endif /* defined(TN3270) */ + xmitAO P((void)), + xmitEC P((void)), + xmitEL P((void)); diff --git a/usr.bin/telnet/main.c b/usr.bin/telnet/main.c index d91fa78..5c73664 100644 --- a/usr.bin/telnet/main.c +++ b/usr.bin/telnet/main.c @@ -29,19 +29,15 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1988, 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ +#include + +__FBSDID("$FreeBSD$"); #ifndef lint static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95"; -#endif /* not lint */ +#endif #include #include @@ -53,6 +49,7 @@ static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95"; #include "externs.h" #include "defines.h" + /* These values need to be the same as defined in libtelnet/kerberos5.c */ /* Either define them in both places, or put in some common header file. */ #define OPTS_FORWARD_CREDS 0x00000002 @@ -62,12 +59,6 @@ static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95"; #define FORWARD #endif -void init_terminal(void); -void init_network(void); -void init_telnet(void); -void init_sys(void); -void init_3270(void); - #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) char *ipsec_policy_in = NULL; char *ipsec_policy_out = NULL; @@ -78,8 +69,8 @@ int family = AF_UNSPEC; /* * Initialize variables. */ - void -tninit() +void +tninit(void) { init_terminal(); @@ -88,25 +79,16 @@ tninit() init_telnet(); init_sys(); - -#if defined(TN3270) - init_3270(); -#endif } - void -usage() +static void +usage(void) { fprintf(stderr, "Usage: %s %s%s%s%s\n", prompt, "[-4] [-6] [-8] [-E] [-L] [-N] [-S tos] [-c] [-d]", "\n\t[-e char] [-l user] [-n tracefile] ", -#if defined(TN3270) && defined(unix) - "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t" - "[-s src_addr] [-t transcom] ", -#else "[-r] [-s src_addr] [-u] ", -#endif #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) "[-P policy] " #endif @@ -119,10 +101,8 @@ usage() * main. Parse arguments, invoke the protocol or command parser. */ - int -main(argc, argv) - int argc; - char *argv[]; +int +main(int argc, char *argv[]) { int ch; char *user; @@ -145,6 +125,7 @@ main(argc, argv) rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE; autologin = -1; + #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) #define IPSECOPT "P:" #else @@ -228,19 +209,6 @@ main(argc, argv) user = optarg; break; case 'n': -#if defined(TN3270) && defined(unix) - /* distinguish between "-n oasynch" and "-noasynch" */ - if (argv[optind - 1][0] == '-' && argv[optind - 1][1] - == 'n' && argv[optind - 1][2] == 'o') { - if (!strcmp(optarg, "oasynch")) { - noasynchtty = 1; - noasynchnet = 1; - } else if (!strcmp(optarg, "oasynchtty")) - noasynchtty = 1; - else if (!strcmp(optarg, "oasynchnet")) - noasynchnet = 1; - } else -#endif /* defined(TN3270) && defined(unix) */ SetNetTrace(optarg); break; case 'r': @@ -249,16 +217,6 @@ main(argc, argv) case 's': src_addr = optarg; break; - case 't': -#if defined(TN3270) && defined(unix) - (void)strlcpy(tline, optarg, sizeof(tline)); - transcom = tline; -#else - fprintf(stderr, - "%s: Warning: -t ignored, no TN3270 support.\n", - prompt); -#endif - break; case 'u': family = AF_UNIX; break; @@ -267,6 +225,11 @@ main(argc, argv) "%s: Warning: -x ignored, no ENCRYPT support.\n", prompt); break; + case 'y': + fprintf(stderr, + "%s: Warning: -y ignored, no ENCRYPT support.\n", + prompt); + break; #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) case 'P': if (!strncmp("in", optarg, 2)) @@ -296,11 +259,11 @@ main(argc, argv) usage(); *argp++ = prompt; if (user) { - *argp++ = "-l"; + *argp++ = strdup("-l"); *argp++ = user; } if (src_addr) { - *argp++ = "-s"; + *argp++ = strdup("-s"); *argp++ = src_addr; } *argp++ = argv[0]; /* host */ @@ -317,11 +280,6 @@ main(argc, argv) } (void)setjmp(toplevel); for (;;) { -#ifdef TN3270 - if (shell_active) - shell_continue(); - else -#endif command(1, 0, 0); } return 0; diff --git a/usr.bin/telnet/network.c b/usr.bin/telnet/network.c index 5c9b0c5..554db4f 100644 --- a/usr.bin/telnet/network.c +++ b/usr.bin/telnet/network.c @@ -31,14 +31,13 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93"; -#else -static const char rcsid[] = - "$FreeBSD$"; #endif -#endif /* not lint */ #include #include @@ -62,8 +61,8 @@ unsigned char netobuf[2*BUFSIZ], netibuf[BUFSIZ]; * Initialize internal network data structures. */ - void -init_network() +void +init_network(void) { if (ring_init(&netoring, netobuf, sizeof netobuf) != 1) { exit(1); @@ -80,10 +79,10 @@ init_network() * Telnet "synch" processing). */ - int -stilloob() +int +stilloob(void) { - static struct timeval timeout = { 0 }; + static struct timeval timeout = { 0, 0 }; fd_set excepts; int value; @@ -112,8 +111,8 @@ stilloob() * Sets "neturg" to the current location. */ - void -setneturg() +void +setneturg(void) { ring_mark(&netoring); } @@ -128,11 +127,10 @@ setneturg() * useful work. */ - - int -netflush() +int +netflush(void) { - register int n, n1; + int n, n1; if ((n1 = n = ring_full_consecutive(&netoring)) > 0) { if (!ring_at_mark(&netoring)) { diff --git a/usr.bin/telnet/ring.c b/usr.bin/telnet/ring.c index b414d16..ac415a9 100644 --- a/usr.bin/telnet/ring.c +++ b/usr.bin/telnet/ring.c @@ -31,14 +31,13 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95"; -#else -static const char rcsid[] = - "$FreeBSD$"; #endif -#endif /* not lint */ /* * This defines a structure for a ring buffer. @@ -99,17 +98,10 @@ static u_long ring_clock = 0; #define ring_full(d) (((d)->supply == (d)->consume) && \ ((d)->supplytime > (d)->consumetime)) - - - - /* Buffer state transition routines */ - int -ring_init(ring, buffer, count) - Ring *ring; - unsigned char *buffer; - int count; +int +ring_init(Ring *ring, unsigned char *buffer, int count) { memset((char *)ring, 0, sizeof *ring); @@ -129,9 +121,8 @@ ring_init(ring, buffer, count) * Mark the most recently supplied byte. */ - void -ring_mark(ring) - Ring *ring; +void +ring_mark(Ring *ring) { ring->mark = ring_decrement(ring, ring->supply, 1); } @@ -140,9 +131,8 @@ ring_mark(ring) * Is the ring pointing to the mark? */ - int -ring_at_mark(ring) - Ring *ring; +int +ring_at_mark(Ring *ring) { if (ring->mark == ring->consume) { return 1; @@ -155,9 +145,8 @@ ring_at_mark(ring) * Clear any mark set on the ring. */ - void -ring_clear_mark(ring) - Ring *ring; +void +ring_clear_mark(Ring *ring) { ring->mark = 0; } @@ -165,10 +154,8 @@ ring_clear_mark(ring) /* * Add characters from current segment to ring buffer. */ - void -ring_supplied(ring, count) - Ring *ring; - int count; +void +ring_supplied(Ring *ring, int count) { ring->supply = ring_increment(ring, ring->supply, count); ring->supplytime = ++ring_clock; @@ -177,10 +164,8 @@ ring_supplied(ring, count) /* * We have just consumed "c" bytes. */ - void -ring_consumed(ring, count) - Ring *ring; - int count; +void +ring_consumed(Ring *ring, int count) { if (count == 0) /* don't update anything */ return; @@ -205,9 +190,8 @@ ring_consumed(ring, count) /* Number of bytes that may be supplied */ - int -ring_empty_count(ring) - Ring *ring; +int +ring_empty_count(Ring *ring) { if (ring_empty(ring)) { /* if empty */ return ring->size; @@ -217,9 +201,8 @@ ring_empty_count(ring) } /* number of CONSECUTIVE bytes that may be supplied */ - int -ring_empty_consecutive(ring) - Ring *ring; +int +ring_empty_consecutive(Ring *ring) { if ((ring->consume < ring->supply) || ring_empty(ring)) { /* @@ -239,9 +222,8 @@ ring_empty_consecutive(ring) * (but don't give more than enough to get to cross over set mark) */ - int -ring_full_count(ring) - Ring *ring; +int +ring_full_count(Ring *ring) { if ((ring->mark == 0) || (ring->mark == ring->consume)) { if (ring_full(ring)) { @@ -258,9 +240,8 @@ ring_full_count(ring) * Return the number of CONSECUTIVE bytes available for consuming. * However, don't return more than enough to cross over set mark. */ - int -ring_full_consecutive(ring) - Ring *ring; +int +ring_full_consecutive(Ring *ring) { if ((ring->mark == 0) || (ring->mark == ring->consume)) { if ((ring->supply < ring->consume) || ring_full(ring)) { @@ -280,11 +261,8 @@ ring_full_consecutive(ring) /* * Move data into the "supply" portion of of the ring buffer. */ - void -ring_supply_data(ring, buffer, count) - Ring *ring; - unsigned char *buffer; - int count; +void +ring_supply_data(Ring *ring, unsigned char *buffer, int count) { int i; @@ -297,26 +275,3 @@ ring_supply_data(ring, buffer, count) } } -#ifdef notdef - -/* - * Move data from the "consume" portion of the ring buffer - */ - void -ring_consume_data(ring, buffer, count) - Ring *ring; - unsigned char *buffer; - int count; -{ - int i; - - while (count) { - i = MIN(count, ring_full_consecutive(ring)); - memcpy(buffer, ring->consume, i); - ring_consumed(ring, i); - count -= i; - buffer += i; - } -} -#endif - diff --git a/usr.bin/telnet/ring.h b/usr.bin/telnet/ring.h index 480d0b3..d2d1d30 100644 --- a/usr.bin/telnet/ring.h +++ b/usr.bin/telnet/ring.h @@ -86,6 +86,7 @@ extern void /* Buffer state query routines */ extern int + ring_at_mark P((Ring *)), ring_empty_count P((Ring *ring)), ring_empty_consecutive P((Ring *ring)), ring_full_count P((Ring *ring)), @@ -93,5 +94,5 @@ extern int extern void - ring_clear_mark P((Ring *)), - ring_mark P((Ring *)); + ring_clear_mark P((Ring *)), + ring_mark P((Ring *)); diff --git a/usr.bin/telnet/sys_bsd.c b/usr.bin/telnet/sys_bsd.c index 7935821..bcb302c 100644 --- a/usr.bin/telnet/sys_bsd.c +++ b/usr.bin/telnet/sys_bsd.c @@ -31,48 +31,34 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95"; -#else -static const char rcsid[] = - "$FreeBSD$"; #endif -#endif /* not lint */ /* * The following routines try to encapsulate what is system dependent * (at least between 4.x and dos) which is used in telnet.c. */ - -#include #include -#include #include -#include +#include #include -#include +#include +#include #include +#include #include "ring.h" - #include "fdset.h" - #include "defines.h" #include "externs.h" #include "types.h" -#if defined(USE_TERMIO) && !defined(SYSV_TERMIO) -#define SIG_FUNC_RET void -#else -#define SIG_FUNC_RET int -#endif - -#ifdef SIGINFO -extern SIG_FUNC_RET ayt_status(); -#endif - int tout, /* Output file descriptor */ tin, /* Input file descriptor */ @@ -88,8 +74,7 @@ int olmode = 0; # define old_tc ottyb #else /* USE_TERMIO */ -struct termio old_tc = { 0 }; -extern struct termio new_tc; +struct termio old_tc = { 0, 0, 0, 0, {}, 0, 0 }; # ifndef TCSANOW # ifdef TCSETS @@ -122,9 +107,21 @@ extern struct termio new_tc; static fd_set ibits, obits, xbits; +#ifdef SIGINT +static SIG_FUNC_RET intr(int); +#endif /* SIGINT */ +#ifdef SIGQUIT +static SIG_FUNC_RET intr2(int); +#endif /* SIGQUIT */ +#ifdef SIGTSTP +static SIG_FUNC_RET susp(int); +#endif /* SIGTSTP */ +#ifdef SIGINFO +static SIG_FUNC_RET ayt(int); +#endif - void -init_sys() +void +init_sys(void) { tout = fileno(stdout); tin = fileno(stdin); @@ -135,19 +132,14 @@ init_sys() errno = 0; } - - int -TerminalWrite(buf, n) - char *buf; - int n; +int +TerminalWrite(char *buf, int n) { return write(tout, buf, n); } - int -TerminalRead(buf, n) - char *buf; - int n; +int +TerminalRead(char *buf, int n) { return read(tin, buf, n); } @@ -156,8 +148,8 @@ TerminalRead(buf, n) * */ - int -TerminalAutoFlush() +int +TerminalAutoFlush(void) { #if defined(LNOFLSH) int flush; @@ -184,11 +176,8 @@ extern int kludgelinemode; * 1 Do add this character */ -extern void xmitAO(), xmitEL(), xmitEC(), intp(), sendbrk(); - - int -TerminalSpecialChars(c) - int c; +int +TerminalSpecialChars(int c) { if (c == termIntChar) { intp(); @@ -230,8 +219,8 @@ TerminalSpecialChars(c) * Flush output to the terminal */ - void -TerminalFlushOutput() +void +TerminalFlushOutput(void) { #ifdef TIOCFLUSH (void) ioctl(fileno(stdout), TIOCFLUSH, (char *) 0); @@ -240,8 +229,8 @@ TerminalFlushOutput() #endif } - void -TerminalSaveState() +void +TerminalSaveState(void) { #ifndef USE_TERMIO ioctl(0, TIOCGETP, (char *)&ottyb); @@ -282,9 +271,8 @@ TerminalSaveState() #endif /* USE_TERMIO */ } - cc_t * -tcval(func) - register int func; +cc_t * +tcval(int func) { switch(func) { case SLC_IP: return(&termIntChar); @@ -325,8 +313,8 @@ tcval(func) } } - void -TerminalDefaultChars() +void +TerminalDefaultChars(void) { #ifndef USE_TERMIO ntc = otc; @@ -359,13 +347,6 @@ TerminalDefaultChars() #endif /* USE_TERMIO */ } -#ifdef notdef -void -TerminalRestoreState() -{ -} -#endif - /* * TerminalNewMode - set up terminal to a specific mode. * MODE_ECHO: do local terminal echo @@ -388,10 +369,8 @@ TerminalRestoreState() * local/no signal mapping */ - - void -TerminalNewMode(f) - register int f; +void +TerminalNewMode(int f) { static int prevmode = 0; #ifndef USE_TERMIO @@ -466,10 +445,6 @@ TerminalNewMode(f) #else tmp_tc.c_lflag &= ~ECHO; tmp_tc.c_oflag &= ~ONLCR; -# ifdef notdef - if (crlf) - tmp_tc.c_iflag &= ~ICRNL; -# endif #endif } @@ -616,19 +591,6 @@ TerminalNewMode(f) } if (f != -1) { -#ifdef SIGINT - SIG_FUNC_RET intr(); -#endif /* SIGINT */ -#ifdef SIGQUIT - SIG_FUNC_RET intr2(); -#endif /* SIGQUIT */ -#ifdef SIGTSTP - SIG_FUNC_RET susp(); -#endif /* SIGTSTP */ -#ifdef SIGINFO - SIG_FUNC_RET ayt(); -#endif - #ifdef SIGINT (void) signal(SIGINT, intr); #endif @@ -681,9 +643,7 @@ TerminalNewMode(f) #endif } else { #ifdef SIGINFO - SIG_FUNC_RET ayt_status(); - - (void) signal(SIGINFO, ayt_status); + (void) signal(SIGINFO, (void (*)(int))ayt_status); #endif #ifdef SIGINT (void) signal(SIGINT, SIG_DFL); @@ -718,17 +678,8 @@ TerminalNewMode(f) tcsetattr(tin, TCSANOW, &tmp_tc); #endif -#if (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR)) -# if !defined(sysV88) ioctl(tin, FIONBIO, (char *)&onoff); ioctl(tout, FIONBIO, (char *)&onoff); -# endif -#endif /* (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR)) */ -#if defined(TN3270) - if (noasynchtty == 0) { - ioctl(tin, FIOASYNC, (char *)&onoff); - } -#endif /* defined(TN3270) */ } @@ -797,15 +748,13 @@ struct termspeeds { }; #endif /* DECODE_BAUD */ - void -TerminalSpeeds(ispeed, ospeed) - long *ispeed; - long *ospeed; +void +TerminalSpeeds(long *ispeed, long *ospeed) { #ifdef DECODE_BAUD - register struct termspeeds *tp; + struct termspeeds *tp; #endif /* DECODE_BAUD */ - register long in, out; + long in, out; out = cfgetospeed(&old_tc); in = cfgetispeed(&old_tc); @@ -828,9 +777,8 @@ TerminalSpeeds(ispeed, ospeed) #endif /* DECODE_BAUD */ } - int -TerminalWindowSize(rows, cols) - long *rows, *cols; +int +TerminalWindowSize(long *rows, long *cols) { #ifdef TIOCGWINSZ struct winsize ws; @@ -844,59 +792,34 @@ TerminalWindowSize(rows, cols) return 0; } - int -NetClose(fd) - int fd; +int +NetClose(int fd) { return close(fd); } - - void -NetNonblockingIO(fd, onoff) - int fd; - int onoff; +static void +NetNonblockingIO(int fd, int onoff) { ioctl(fd, FIONBIO, (char *)&onoff); } -#if defined(TN3270) - void -NetSigIO(fd, onoff) - int fd; - int onoff; -{ - ioctl(fd, FIOASYNC, (char *)&onoff); /* hear about input */ -} - - void -NetSetPgrp(fd) - int fd; -{ - int myPid; - - myPid = getpid(); - fcntl(fd, F_SETOWN, myPid); -} -#endif /*defined(TN3270)*/ /* * Various signal handling routines. */ - /* ARGSUSED */ - SIG_FUNC_RET -deadpeer(sig) - int sig; +/* ARGSUSED */ +static SIG_FUNC_RET +deadpeer(int sig __unused) { setcommandmode(); longjmp(peerdied, -1); } - /* ARGSUSED */ - SIG_FUNC_RET -intr(sig) - int sig; +/* ARGSUSED */ +SIG_FUNC_RET +intr(int sig __unused) { if (localchars) { intp(); @@ -906,10 +829,9 @@ intr(sig) longjmp(toplevel, -1); } - /* ARGSUSED */ - SIG_FUNC_RET -intr2(sig) - int sig; +/* ARGSUSED */ +SIG_FUNC_RET +intr2(int sig __unused) { if (localchars) { #ifdef KLUDGELINEMODE @@ -923,10 +845,9 @@ intr2(sig) } #ifdef SIGTSTP - /* ARGSUSED */ - SIG_FUNC_RET -susp(sig) - int sig; +/* ARGSUSED */ +SIG_FUNC_RET +susp(int sig __unused) { if ((rlogin != _POSIX_VDISABLE) && rlogin_susp()) return; @@ -936,10 +857,9 @@ susp(sig) #endif #ifdef SIGWINCH - /* ARGSUSED */ - SIG_FUNC_RET -sendwin(sig) - int sig; +/* ARGSUSED */ +static SIG_FUNC_RET +sendwin(int sig __unused) { if (connected) { sendnaws(); @@ -948,10 +868,9 @@ sendwin(sig) #endif #ifdef SIGINFO - /* ARGSUSED */ - SIG_FUNC_RET -ayt(sig) - int sig; +/* ARGSUSED */ +SIG_FUNC_RET +ayt(int sig __unused) { if (connected) sendayt(); @@ -961,8 +880,8 @@ ayt(sig) #endif - void -sys_telnet_init() +void +sys_telnet_init(void) { (void) signal(SIGINT, intr); (void) signal(SIGQUIT, intr2); @@ -981,13 +900,6 @@ sys_telnet_init() NetNonblockingIO(net, 1); -#if defined(TN3270) - if (noasynchnet == 0) { /* DBX can't handle! */ - NetSigIO(net, 1); - NetSetPgrp(net); - } -#endif /* defined(TN3270) */ - #if defined(SO_OOBINLINE) if (SetSockOpt(net, SOL_SOCKET, SO_OOBINLINE, 1) == -1) { perror("SetSockOpt"); @@ -1006,18 +918,12 @@ sys_telnet_init() * The return value is 1 if something happened, 0 if not. */ - int -process_rings(netin, netout, netex, ttyin, ttyout, poll) - int poll; /* If 0, then block until something to do */ +int +process_rings(int netin, int netout, int netex, int ttyin, int ttyout, int poll) { - register int c; - /* One wants to be a bit careful about setting returnValue - * to one, since a one implies we did some useful work, - * and therefore probably won't be called to block next - * time (TN3270 mode only). - */ + int c; int returnValue = 0; - static struct timeval TimeValue = { 0 }; + static struct timeval TimeValue = { 0, 0 }; if (netout) { FD_SET(net, &obits); @@ -1025,24 +931,12 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll) if (ttyout) { FD_SET(tout, &obits); } -#if defined(TN3270) if (ttyin) { FD_SET(tin, &ibits); } -#else /* defined(TN3270) */ - if (ttyin) { - FD_SET(tin, &ibits); - } -#endif /* defined(TN3270) */ -#if defined(TN3270) - if (netin) { - FD_SET(net, &ibits); - } -# else /* !defined(TN3270) */ if (netin) { FD_SET(net, &ibits); } -# endif /* !defined(TN3270) */ if (netex) { FD_SET(net, &xbits); } @@ -1057,23 +951,6 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll) if (errno == EINTR) { return 0; } -# if defined(TN3270) - /* - * we can get EBADF if we were in transparent - * mode, and the transcom process died. - */ - if (errno == EBADF) { - /* - * zero the bits (even though kernel does it) - * to make sure we are selecting on the right - * ones. - */ - FD_ZERO(&ibits); - FD_ZERO(&obits); - FD_ZERO(&xbits); - return 0; - } -# endif /* defined(TN3270) */ /* I don't like this, does it ever happen? */ printf("sleep(5) from telnet, after select: %s\r\n", strerror(errno)); sleep(5); diff --git a/usr.bin/telnet/telnet.c b/usr.bin/telnet/telnet.c index ee2c31f..a570a86 100644 --- a/usr.bin/telnet/telnet.c +++ b/usr.bin/telnet/telnet.c @@ -29,33 +29,30 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95"; -#else -static const char rcsid[] = - "$FreeBSD$"; #endif -#endif /* not lint */ #include -#if defined(unix) -#include /* By the way, we need to include curses.h before telnet.h since, * among other things, telnet.h #defines 'DO', which is a variable * declared in curses.h. */ -#endif /* defined(unix) */ -#include #include +#include +#include #include +#include #include +#include #include "ring.h" @@ -64,6 +61,7 @@ static const char rcsid[] = #include "types.h" #include "general.h" +#include #define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x)) @@ -90,17 +88,11 @@ int skiprc = 0, connected, showoptions, - In3270, /* Are we in 3270 mode? */ ISend, /* trying to send network data in */ debug = 0, crmod, netdata, /* Print out network data flow */ crlf, /* Should '\r' be mapped to (or )? */ -#if defined(TN3270) - noasynchtty = 0,/* User specified "-noasynch" on command line */ - noasynchnet = 0,/* User specified "-noasynch" on command line */ - askedSGA = 0, /* We have talked about suppress go ahead */ -#endif /* defined(TN3270) */ telnetport, SYNCHing, /* we are in TELNET SYNCH mode */ flushout, /* flush output */ @@ -144,7 +136,7 @@ unsigned char telopt_environ = TELOPT_NEW_ENVIRON; # define telopt_environ TELOPT_NEW_ENVIRON #endif -jmp_buf toplevel = { 0 }; +jmp_buf toplevel; jmp_buf peerdied; int flushline; @@ -154,6 +146,8 @@ int linemode; int kludgelinemode = 1; #endif +static int is_unique(char *, char **, char **); + /* * The following are some clocks used to decide how to interpret * the relationship between various variables. @@ -161,32 +155,19 @@ int kludgelinemode = 1; Clocks clocks; -#ifdef notdef -Modelist modelist[] = { - { "telnet command mode", COMMAND_LINE }, - { "character-at-a-time mode", 0 }, - { "character-at-a-time mode (local echo)", LOCAL_ECHO|LOCAL_CHARS }, - { "line-by-line mode (remote echo)", LINE | LOCAL_CHARS }, - { "line-by-line mode", LINE | LOCAL_ECHO | LOCAL_CHARS }, - { "line-by-line mode (local echoing suppressed)", LINE | LOCAL_CHARS }, - { "3270 mode", 0 }, -}; -#endif - - /* * Initialize telnet environment. */ - void -init_telnet() +void +init_telnet(void) { env_init(); SB_CLEAR(); ClearArray(options); - connected = In3270 = ISend = localflow = donebinarytoggle = 0; + connected = ISend = localflow = donebinarytoggle = 0; restartany = -1; SYNCHing = 0; @@ -204,56 +185,6 @@ init_telnet() } -#ifdef notdef -#include - - /*VARARGS*/ - static void -printring(va_alist) - va_dcl -{ - va_list ap; - char buffer[100]; /* where things go */ - char *ptr; - char *format; - char *string; - Ring *ring; - int i; - - va_start(ap); - - ring = va_arg(ap, Ring *); - format = va_arg(ap, char *); - ptr = buffer; - - while ((i = *format++) != 0) { - if (i == '%') { - i = *format++; - switch (i) { - case 'c': - *ptr++ = va_arg(ap, int); - break; - case 's': - string = va_arg(ap, char *); - ring_supply_data(ring, buffer, ptr-buffer); - ring_supply_data(ring, string, strlen(string)); - ptr = buffer; - break; - case 0: - ExitString("printring: trailing %%.\n", 1); - /*NOTREACHED*/ - default: - ExitString("printring: unknown format character.\n", 1); - /*NOTREACHED*/ - } - } else { - *ptr++ = i; - } - } - ring_supply_data(ring, buffer, ptr-buffer); -} -#endif - /* * These routines are in charge of sending option negotiations * to the other side. @@ -262,9 +193,8 @@ printring(va_alist) * is in disagreement as to what the current state should be. */ - void -send_do(c, init) - register int c, init; +void +send_do(int c, int init) { if (init) { if (((do_dont_resp[c] == 0) && my_state_is_do(c)) || @@ -278,9 +208,8 @@ send_do(c, init) printoption("SENT", DO, c); } - void -send_dont(c, init) - register int c, init; +void +send_dont(int c, int init) { if (init) { if (((do_dont_resp[c] == 0) && my_state_is_dont(c)) || @@ -294,9 +223,8 @@ send_dont(c, init) printoption("SENT", DONT, c); } - void -send_will(c, init) - register int c, init; +void +send_will(int c, int init) { if (init) { if (((will_wont_resp[c] == 0) && my_state_is_will(c)) || @@ -310,9 +238,8 @@ send_will(c, init) printoption("SENT", WILL, c); } - void -send_wont(c, init) - register int c, init; +void +send_wont(int c, int init) { if (init) { if (((will_wont_resp[c] == 0) && my_state_is_wont(c)) || @@ -326,10 +253,8 @@ send_wont(c, init) printoption("SENT", WONT, c); } - - void -willoption(option) - int option; +void +willoption(int option) { int new_state_ok = 0; @@ -344,30 +269,6 @@ willoption(option) switch (option) { case TELOPT_ECHO: -# if defined(TN3270) - /* - * The following is a pain in the rear-end. - * Various IBM servers (some versions of Wiscnet, - * possibly Fibronics/Spartacus, and who knows who - * else) will NOT allow us to send "DO SGA" too early - * in the setup proceedings. On the other hand, - * 4.2 servers (telnetd) won't set SGA correctly. - * So, we are stuck. Empirically (but, based on - * a VERY small sample), the IBM servers don't send - * out anything about ECHO, so we postpone our sending - * "DO SGA" until we see "WILL ECHO" (which 4.2 servers - * DO send). - */ - { - if (askedSGA == 0) { - askedSGA = 1; - if (my_want_state_is_dont(TELOPT_SGA)) - send_do(TELOPT_SGA, 1); - } - } - /* Fall through */ - case TELOPT_EOR: -#endif /* defined(TN3270) */ case TELOPT_BINARY: case TELOPT_SGA: settimer(modenegotiated); @@ -404,9 +305,8 @@ willoption(option) set_my_state_do(option); } - void -wontoption(option) - int option; +void +wontoption(int option) { if (do_dont_resp[option]) { --do_dont_resp[option]; @@ -453,9 +353,8 @@ wontoption(option) set_my_state_dont(option); } - static void -dooption(option) - int option; +static void +dooption(int option) { int new_state_ok = 0; @@ -480,9 +379,6 @@ dooption(option) set_my_state_wont(TELOPT_TM); return; -# if defined(TN3270) - case TELOPT_EOR: /* end of record */ -# endif /* defined(TN3270) */ case TELOPT_BINARY: /* binary mode */ case TELOPT_NAWS: /* window size */ case TELOPT_TSPEED: /* terminal speed */ @@ -508,7 +404,7 @@ dooption(option) case TELOPT_XDISPLOC: /* X Display location */ - if (env_getvalue((unsigned char *)"DISPLAY")) + if (env_getvalue("DISPLAY")) new_state_ok = 1; break; @@ -557,9 +453,8 @@ dooption(option) set_my_state_will(option); } - static void -dontoption(option) - int option; +static void +dontoption(int option) { if (will_wont_resp[option]) { @@ -600,15 +495,14 @@ dontoption(option) * duplicate, or verbose names (names with spaces). */ -static char *name_unknown = "UNKNOWN"; -static char *unknown[] = { 0, 0 }; +static const char *name_unknown = "UNKNOWN"; +static const char *unknown[] = { NULL, NULL }; - char ** -mklist(buf, name) - char *buf, *name; +static const char ** +mklist(char *buf, char *name) { - register int n; - register char c, *cp, **argvp, *cp2, **argv, **avt; + int n; + char c, *cp, **argvp, *cp2, **argv, **avt; if (name) { if (strlen(name) > 40) { @@ -709,17 +603,16 @@ mklist(buf, name) } } if (*argv) - return(argv); + return((const char **)argv); else return(unknown); } - int -is_unique(name, as, ae) - register char *name, **as, **ae; +static int +is_unique(char *name, char **as, char **ae) { - register char **ap; - register int n; + char **ap; + int n; n = strlen(name) + 1; for (ap = as; ap < ae; ap++) @@ -731,11 +624,9 @@ is_unique(name, as, ae) #ifdef TERMCAP char termbuf[1024]; - /*ARGSUSED*/ - int -setupterm(tname, fd, errp) - char *tname; - int fd, *errp; +/*ARGSUSED*/ +static int +setupterm(char *tname, int fd, int *errp) { if (tgetent(termbuf, tname) == 1) { termbuf[1023] = '\0'; @@ -754,19 +645,19 @@ extern char ttytype[]; int resettermname = 1; - char * -gettermname() +static const char * +gettermname(void) { char *tname; - static char **tnamep = 0; - static char **next; + static const char **tnamep = 0; + static const char **next; int err; if (resettermname) { resettermname = 0; if (tnamep && tnamep != unknown) free(tnamep); - if ((tname = (char *)env_getvalue((unsigned char *)"TERM")) && + if ((tname = env_getvalue("TERM")) && (setupterm(tname, 1, &err) == 0)) { tnamep = mklist(termbuf, tname); } else { @@ -797,8 +688,8 @@ gettermname() * Linemode */ - static void -suboption() +static void +suboption(void) { unsigned char subchar; @@ -810,19 +701,14 @@ suboption() if (SB_EOF() || SB_GET() != TELQUAL_SEND) { return; } else { - char *name; + const char *name; unsigned char temp[50]; int len; -#if defined(TN3270) - if (tn3270_ttype()) { - return; - } -#endif /* defined(TN3270) */ name = gettermname(); len = strlen(name) + 4 + 2; if (len < NETROOM()) { - sprintf((char *)temp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE, + sprintf(temp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_IS, name, IAC, SE); ring_supply_data(&netoring, temp, len); printsub('>', &temp[2], len-2); @@ -941,7 +827,7 @@ suboption() unsigned char temp[50], *dp; int len; - if ((dp = env_getvalue((unsigned char *)"DISPLAY")) == NULL || + if ((dp = env_getvalue("DISPLAY")) == NULL || strlen(dp) > sizeof(temp) - 7) { /* * Something happened, we no longer have a DISPLAY @@ -950,7 +836,7 @@ suboption() send_wont(TELOPT_XDISPLOC, 1); break; } - snprintf((char *)temp, sizeof(temp), "%c%c%c%c%s%c%c", IAC, SB, + snprintf(temp, sizeof(temp), "%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC, TELQUAL_IS, dp, IAC, SE); len = strlen((char *)temp+4) + 4; /* temp[3] is 0 ... */ @@ -969,10 +855,8 @@ suboption() static unsigned char str_lm[] = { IAC, SB, TELOPT_LINEMODE, 0, 0, IAC, SE }; - void -lm_will(cmd, len) - unsigned char *cmd; - int len; +void +lm_will(unsigned char *cmd, int len) { if (len < 1) { /*@*/ printf("lm_will: no command!!!\n"); /* Should not happen... */ @@ -983,7 +867,7 @@ lm_will(cmd, len) default: str_lm[3] = DONT; str_lm[4] = cmd[0]; - if (NETROOM() > sizeof(str_lm)) { + if (NETROOM() > (int)sizeof(str_lm)) { ring_supply_data(&netoring, str_lm, sizeof(str_lm)); printsub('>', &str_lm[2], sizeof(str_lm)-2); } @@ -992,10 +876,8 @@ lm_will(cmd, len) } } - void -lm_wont(cmd, len) - unsigned char *cmd; - int len; +void +lm_wont(unsigned char *cmd, int len) { if (len < 1) { /*@*/ printf("lm_wont: no command!!!\n"); /* Should not happen... */ @@ -1009,10 +891,8 @@ lm_wont(cmd, len) } } - void -lm_do(cmd, len) - unsigned char *cmd; - int len; +void +lm_do(unsigned char *cmd, int len) { if (len < 1) { /*@*/ printf("lm_do: no command!!!\n"); /* Should not happen... */ @@ -1023,7 +903,7 @@ lm_do(cmd, len) default: str_lm[3] = WONT; str_lm[4] = cmd[0]; - if (NETROOM() > sizeof(str_lm)) { + if (NETROOM() > (int)sizeof(str_lm)) { ring_supply_data(&netoring, str_lm, sizeof(str_lm)); printsub('>', &str_lm[2], sizeof(str_lm)-2); } @@ -1032,10 +912,8 @@ lm_do(cmd, len) } } - void -lm_dont(cmd, len) - unsigned char *cmd; - int len; +void +lm_dont(unsigned char *cmd, int len) { if (len < 1) { /*@*/ printf("lm_dont: no command!!!\n"); /* Should not happen... */ @@ -1053,10 +931,8 @@ static unsigned char str_lm_mode[] = { IAC, SB, TELOPT_LINEMODE, LM_MODE, 0, IAC, SE }; - void -lm_mode(cmd, len, init) - unsigned char *cmd; - int len, init; +void +lm_mode(unsigned char *cmd, int len, int init) { if (len != 1) return; @@ -1068,7 +944,7 @@ lm_mode(cmd, len, init) str_lm_mode[4] = linemode; if (!init) str_lm_mode[4] |= MODE_ACK; - if (NETROOM() > sizeof(str_lm_mode)) { + if (NETROOM() > (int)sizeof(str_lm_mode)) { ring_supply_data(&netoring, str_lm_mode, sizeof(str_lm_mode)); printsub('>', &str_lm_mode[2], sizeof(str_lm_mode)-2); } @@ -1095,10 +971,10 @@ struct spc { #define SLC_RVALUE 2 static int slc_mode = SLC_EXPORT; - void -slc_init() +void +slc_init(void) { - register struct spc *spcp; + struct spc *spcp; localchars = 1; for (spcp = spc_data; spcp < &spc_data[NSLC+1]; spcp++) { @@ -1157,8 +1033,8 @@ slc_init() } - void -slcstate() +void +slcstate(void) { printf("Special characters are %s values\n", slc_mode == SLC_IMPORT ? "remote default" : @@ -1166,17 +1042,16 @@ slcstate() "remote"); } - void -slc_mode_export() +void +slc_mode_export(void) { slc_mode = SLC_EXPORT; if (my_state_is_will(TELOPT_LINEMODE)) slc_export(); } - void -slc_mode_import(def) - int def; +void +slc_mode_import(int def) { slc_mode = def ? SLC_IMPORT : SLC_RVALUE; if (my_state_is_will(TELOPT_LINEMODE)) @@ -1190,11 +1065,10 @@ unsigned char slc_import_def[] = { IAC, SB, TELOPT_LINEMODE, LM_SLC, 0, SLC_DEFAULT, 0, IAC, SE }; - void -slc_import(def) - int def; +void +slc_import(int def) { - if (NETROOM() > sizeof(slc_import_val)) { + if (NETROOM() > (int)sizeof(slc_import_val)) { if (def) { ring_supply_data(&netoring, slc_import_def, sizeof(slc_import_def)); printsub('>', &slc_import_def[2], sizeof(slc_import_def)-2); @@ -1206,10 +1080,10 @@ slc_import(def) /*@*/ else printf("slc_import: not enough room\n"); } - void -slc_export() +void +slc_export(void) { - register struct spc *spcp; + struct spc *spcp; TerminalDefaultChars(); @@ -1230,13 +1104,11 @@ slc_export() setconnmode(1); /* Make sure the character values are set */ } - void -slc(cp, len) - register unsigned char *cp; - int len; +void +slc(unsigned char *cp, int len) { - register struct spc *spcp; - register int func,level; + struct spc *spcp; + int func,level; slc_start_reply(); @@ -1300,10 +1172,10 @@ slc(cp, len) setconnmode(1); /* set the new character values */ } - void -slc_check() +void +slc_check(void) { - register struct spc *spcp; + struct spc *spcp; slc_start_reply(); for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) { @@ -1320,12 +1192,11 @@ slc_check() setconnmode(1); } - unsigned char slc_reply[128]; unsigned char *slc_replyp; - void -slc_start_reply() +void +slc_start_reply(void) { slc_replyp = slc_reply; *slc_replyp++ = IAC; @@ -1334,11 +1205,8 @@ slc_start_reply() *slc_replyp++ = LM_SLC; } - void -slc_add_reply(func, flags, value) - unsigned char func; - unsigned char flags; - cc_t value; +void +slc_add_reply(unsigned char func, unsigned char flags, cc_t value) { if ((*slc_replyp++ = func) == IAC) *slc_replyp++ = IAC; @@ -1348,10 +1216,10 @@ slc_add_reply(func, flags, value) *slc_replyp++ = IAC; } - void -slc_end_reply() +void +slc_end_reply(void) { - register int len; + int len; *slc_replyp++ = IAC; *slc_replyp++ = SE; @@ -1365,10 +1233,10 @@ slc_end_reply() /*@*/else printf("slc_end_reply: not enough room\n"); } - int -slc_update() +int +slc_update(void) { - register struct spc *spcp; + struct spc *spcp; int need_update = 0; for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) { @@ -1403,13 +1271,11 @@ int old_env_value = OLD_ENV_VALUE; # endif #endif - void -env_opt(buf, len) - register unsigned char *buf; - register int len; +void +env_opt(unsigned char *buf, int len) { - register unsigned char *ep = 0, *epc = 0; - register int i; + unsigned char *ep = 0, *epc = 0; + int i; switch(buf[0]&0xff) { case TELQUAL_SEND: @@ -1477,8 +1343,8 @@ unsigned char *opt_reply; unsigned char *opt_replyp; unsigned char *opt_replyend; - void -env_opt_start() +void +env_opt_start(void) { if (opt_reply) opt_reply = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE); @@ -1497,19 +1363,18 @@ env_opt_start() *opt_replyp++ = TELQUAL_IS; } - void -env_opt_start_info() +void +env_opt_start_info(void) { env_opt_start(); if (opt_replyp) opt_replyp[-1] = TELQUAL_INFO; } - void -env_opt_add(ep) - register unsigned char *ep; +void +env_opt_add(unsigned char *ep) { - register unsigned char *vp, c; + unsigned char *vp, c; if (opt_reply == NULL) /*XXX*/ return; /*XXX*/ @@ -1530,7 +1395,7 @@ env_opt_add(ep) if (opt_replyp + (vp ? strlen((char *)vp) : 0) + strlen((char *)ep) + 6 > opt_replyend) { - register int len; + int len; opt_replyend += OPT_REPLY_SIZE; len = opt_replyend - opt_reply; opt_reply = (unsigned char *)realloc(opt_reply, len); @@ -1579,9 +1444,8 @@ env_opt_add(ep) } } - int -opt_welldefined(ep) - char *ep; +int +opt_welldefined(const char *ep) { if ((strcmp(ep, "USER") == 0) || (strcmp(ep, "DISPLAY") == 0) || @@ -1592,11 +1456,11 @@ opt_welldefined(ep) return(1); return(0); } - void -env_opt_end(emptyok) - register int emptyok; + +void +env_opt_end(int emptyok) { - register int len; + int len; len = opt_replyp - opt_reply + 2; if (emptyok || len > 6) { @@ -1616,12 +1480,12 @@ env_opt_end(emptyok) - int -telrcv() +int +telrcv(void) { - register int c; - register int scc; - register unsigned char *sbp; + int c; + int scc; + unsigned char *sbp; int count; int returnValue = 0; @@ -1662,19 +1526,6 @@ telrcv() telrcv_state = TS_IAC; break; } -# if defined(TN3270) - if (In3270) { - *Ifrontp++ = c; - while (scc > 0) { - c = *sbp++ & 0377, scc--; count++; - if (c == IAC) { - telrcv_state = TS_IAC; - break; - } - *Ifrontp++ = c; - } - } else -# endif /* defined(TN3270) */ /* * The 'crmod' hack (see following) is needed * since we can't * set CRMOD on output only. @@ -1750,31 +1601,8 @@ process_iac: telrcv_state = TS_SB; continue; -# if defined(TN3270) - case EOR: - if (In3270) { - if (Ibackp == Ifrontp) { - Ibackp = Ifrontp = Ibuf; - ISend = 0; /* should have been! */ - } else { - Ibackp += DataFromNetwork(Ibackp, Ifrontp-Ibackp, 1); - ISend = 1; - } - } - printoption("RCVD", IAC, EOR); - break; -# endif /* defined(TN3270) */ - case IAC: -# if !defined(TN3270) TTYADD(IAC); -# else /* !defined(TN3270) */ - if (In3270) { - *Ifrontp++ = IAC; - } else { - TTYADD(IAC); - } -# endif /* !defined(TN3270) */ break; case NOP: @@ -1789,21 +1617,18 @@ process_iac: case TS_WILL: printoption("RCVD", WILL, c); willoption(c); - SetIn3270(); telrcv_state = TS_DATA; continue; case TS_WONT: printoption("RCVD", WONT, c); wontoption(c); - SetIn3270(); telrcv_state = TS_DATA; continue; case TS_DO: printoption("RCVD", DO, c); dooption(c); - SetIn3270(); if (c == TELOPT_NAWS) { sendnaws(); } else if (c == TELOPT_LFLOW) { @@ -1819,7 +1644,6 @@ process_iac: dontoption(c); flushline = 1; setconnmode(0); /* set new tty mode (maybe) */ - SetIn3270(); telrcv_state = TS_DATA; continue; @@ -1853,7 +1677,6 @@ process_iac: printoption("In SUBOPTION processing, RCVD", IAC, c); suboption(); /* handle sub-option */ - SetIn3270(); telrcv_state = TS_IAC; goto process_iac; } @@ -1865,7 +1688,6 @@ process_iac: subpointer -= 2; SB_TERM(); suboption(); /* handle sub-option */ - SetIn3270(); telrcv_state = TS_DATA; } } @@ -1877,8 +1699,8 @@ process_iac: static int bol = 1, local = 0; - int -rlogin_susp() +int +rlogin_susp(void) { if (local) { local = 0; @@ -1889,8 +1711,8 @@ rlogin_susp() return(0); } - static int -telsnd() +static int +telsnd(void) { int tcc; int count; @@ -1900,8 +1722,8 @@ telsnd() tcc = 0; count = 0; while (NETROOM() > 2) { - register int sc; - register int c; + int sc; + int c; if (tcc == 0) { if (count) { @@ -1936,7 +1758,7 @@ telsnd() continue; } if (sc == escape) { - command(0, (char *)tbp, tcc); + command(0, tbp, tcc); bol = 1; count += tcc; tcc = 0; @@ -2039,15 +1861,12 @@ telsnd() * */ - - int -Scheduler(block) - int block; /* should we block in the select ? */ +static int +Scheduler(int block) { /* One wants to be a bit careful about setting returnValue * to one, since a one implies we did some useful work, * and therefore probably won't be called to block next - * time (TN3270 mode only). */ int returnValue; int netin, netout, netex, ttyin, ttyout; @@ -2064,28 +1883,12 @@ Scheduler(block) my_want_state_is_will(TELOPT_BINARY)); ttyout = ring_full_count(&ttyoring); -#if defined(TN3270) - ttyin = ring_empty_count(&ttyiring) && (clienteof == 0) && (shell_active == 0); -#else /* defined(TN3270) */ ttyin = ring_empty_count(&ttyiring) && (clienteof == 0); -#endif /* defined(TN3270) */ -#if defined(TN3270) - netin = ring_empty_count(&netiring); -# else /* !defined(TN3270) */ netin = !ISend && ring_empty_count(&netiring); -# endif /* !defined(TN3270) */ netex = !SYNCHing; - /* If we have seen a signal recently, reset things */ -# if defined(TN3270) && defined(unix) - if (HaveInput) { - HaveInput = 0; - (void) signal(SIGIO, inputAvailable); - } -#endif /* defined(TN3270) && defined(unix) */ - /* Call to system code to process rings */ returnValue = process_rings(netin, netout, netex, ttyin, ttyout, !block); @@ -2093,44 +1896,24 @@ Scheduler(block) /* Now, look at the input rings, looking for work to do. */ if (ring_full_count(&ttyiring)) { -# if defined(TN3270) - if (In3270) { - int c; - - c = DataFromTerminal(ttyiring.consume, - ring_full_consecutive(&ttyiring)); - if (c) { - returnValue = 1; - ring_consumed(&ttyiring, c); - } - } else { -# endif /* defined(TN3270) */ returnValue |= telsnd(); -# if defined(TN3270) - } -# endif /* defined(TN3270) */ } if (ring_full_count(&netiring)) { -# if !defined(TN3270) returnValue |= telrcv(); -# else /* !defined(TN3270) */ - returnValue = Push3270(); -# endif /* !defined(TN3270) */ } return returnValue; } +#define __unusedhere __unused /* * Select from tty and network... */ - void -telnet(user) - char *user; +void +telnet(char *user __unusedhere) { sys_telnet_init(); -# if !defined(TN3270) if (telnetport) { send_do(TELOPT_SGA, 1); send_will(TELOPT_TTYPE, 1); @@ -2140,14 +1923,12 @@ telnet(user) send_will(TELOPT_LINEMODE, 1); send_will(TELOPT_NEW_ENVIRON, 1); send_do(TELOPT_STATUS, 1); - if (env_getvalue((unsigned char *)"DISPLAY")) + if (env_getvalue("DISPLAY")) send_will(TELOPT_XDISPLOC, 1); if (eight) tel_enter_binary(eight); } -# endif /* !defined(TN3270) */ -# if !defined(TN3270) for (;;) { int schedValue; @@ -2163,45 +1944,6 @@ telnet(user) return; } } -# else /* !defined(TN3270) */ - for (;;) { - int schedValue; - - while (!In3270 && !shell_active) { - if (Scheduler(1) == -1) { - setcommandmode(); - return; - } - } - - while ((schedValue = Scheduler(0)) != 0) { - if (schedValue == -1) { - setcommandmode(); - return; - } - } - /* If there is data waiting to go out to terminal, don't - * schedule any more data for the terminal. - */ - if (ring_full_count(&ttyoring)) { - schedValue = 1; - } else { - if (shell_active) { - if (shell_continue() == 0) { - ConnectScreen(); - } - } else if (In3270) { - schedValue = DoTerminalOutput(); - } - } - if (schedValue && (shell_active == 0)) { - if (Scheduler(1) == -1) { - setcommandmode(); - return; - } - } - } -# endif /* !defined(TN3270) */ } #if 0 /* XXX - this not being in is a bug */ @@ -2216,9 +1958,8 @@ telnet(user) * character. */ - static char * -nextitem(current) - char *current; +static char * +nextitem(char *current) { if ((*current&0xff) != IAC) { return current+1; @@ -2231,7 +1972,7 @@ nextitem(current) return current+3; case SB: /* loop forever looking for the SE */ { - register char *look = current+2; + char *look = current+2; for (;;) { if ((*look++&0xff) == IAC) { @@ -2264,51 +2005,18 @@ nextitem(current) * us in any case. */ - static void -netclear() +static void +netclear(void) { -#if 0 /* XXX */ - register char *thisitem, *next; - char *good; -#define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \ - ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)) - - thisitem = netobuf; - - while ((next = nextitem(thisitem)) <= netobuf.send) { - thisitem = next; - } - - /* Now, thisitem is first before/at boundary. */ - - good = netobuf; /* where the good bytes go */ - - while (netoring.add > thisitem) { - if (wewant(thisitem)) { - int length; - - next = thisitem; - do { - next = nextitem(next); - } while (wewant(next) && (nfrontp > next)); - length = next-thisitem; - memcpy(good, thisitem, length); - good += length; - thisitem = next; - } else { - thisitem = nextitem(thisitem); - } - } - -#endif /* 0 */ + /* Deleted */ } /* * These routines add various telnet commands to the data stream. */ - static void -doflush() +static void +doflush(void) { NET2ADD(IAC, DO); NETADD(TELOPT_TM); @@ -2319,8 +2027,8 @@ doflush() printoption("SENT", DO, TELOPT_TM); } - void -xmitAO() +void +xmitAO(void) { NET2ADD(IAC, AO); printoption("SENT", IAC, AO); @@ -2329,24 +2037,22 @@ xmitAO() } } - - void -xmitEL() +void +xmitEL(void) { NET2ADD(IAC, EL); printoption("SENT", IAC, EL); } - void -xmitEC() +void +xmitEC(void) { NET2ADD(IAC, EC); printoption("SENT", IAC, EC); } - - int -dosynch() +int +dosynch(char *ch __unused) { netclear(); /* clear the path to the network */ NETADD(IAC); @@ -2358,11 +2064,11 @@ dosynch() int want_status_response = 0; - int -get_status() +int +get_status(char *ch __unused) { unsigned char tmp[16]; - register unsigned char *cp; + unsigned char *cp; if (my_want_state_is_dont(TELOPT_STATUS)) { printf("Remote side does not support STATUS option\n"); @@ -2384,8 +2090,8 @@ get_status() return 1; } - void -intp() +void +intp(void) { NET2ADD(IAC, IP); printoption("SENT", IAC, IP); @@ -2394,12 +2100,12 @@ intp() doflush(); } if (autosynch) { - dosynch(); + dosynch(NULL); } } - void -sendbrk() +void +sendbrk(void) { NET2ADD(IAC, BREAK); printoption("SENT", IAC, BREAK); @@ -2408,12 +2114,12 @@ sendbrk() doflush(); } if (autosynch) { - dosynch(); + dosynch(NULL); } } - void -sendabort() +void +sendabort(void) { NET2ADD(IAC, ABORT); printoption("SENT", IAC, ABORT); @@ -2422,12 +2128,12 @@ sendabort() doflush(); } if (autosynch) { - dosynch(); + dosynch(NULL); } } - void -sendsusp() +void +sendsusp(void) { NET2ADD(IAC, SUSP); printoption("SENT", IAC, SUSP); @@ -2436,19 +2142,19 @@ sendsusp() doflush(); } if (autosynch) { - dosynch(); + dosynch(NULL); } } - void -sendeof() +void +sendeof(void) { NET2ADD(IAC, xEOF); printoption("SENT", IAC, xEOF); } - void -sendayt() +void +sendayt(void) { NET2ADD(IAC, AYT); printoption("SENT", IAC, AYT); @@ -2458,12 +2164,12 @@ sendayt() * Send a window size update to the remote system. */ - void -sendnaws() +void +sendnaws(void) { long rows, cols; unsigned char tmp[16]; - register unsigned char *cp; + unsigned char *cp; if (my_state_is_wont(TELOPT_NAWS)) return; @@ -2490,9 +2196,8 @@ sendnaws() } } - void -tel_enter_binary(rw) - int rw; +void +tel_enter_binary(int rw) { if (rw&1) send_do(TELOPT_BINARY, 1); @@ -2500,9 +2205,8 @@ tel_enter_binary(rw) send_will(TELOPT_BINARY, 1); } - void -tel_leave_binary(rw) - int rw; +void +tel_leave_binary(int rw) { if (rw&1) send_dont(TELOPT_BINARY, 1); diff --git a/usr.bin/telnet/terminal.c b/usr.bin/telnet/terminal.c index 4464681..14eb0ff 100644 --- a/usr.bin/telnet/terminal.c +++ b/usr.bin/telnet/terminal.c @@ -31,14 +31,13 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95"; -#else -static const char rcsid[] = - "$FreeBSD$"; #endif -#endif /* not lint */ #include #include @@ -48,6 +47,7 @@ static const char rcsid[] = #include "externs.h" #include "types.h" + Ring ttyoring, ttyiring; unsigned char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ]; @@ -93,8 +93,8 @@ cc_t termAytChar; * initialize the terminal data structures. */ - void -init_terminal() +void +init_terminal(void) { if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) { exit(1); @@ -105,7 +105,6 @@ init_terminal() autoflush = TerminalAutoFlush(); } - /* * Send as much data as possible to the terminal. * @@ -116,12 +115,10 @@ init_terminal() * n: All data - n was written out. */ - - int -ttyflush(drop) - int drop; +int +ttyflush(int drop) { - register int n, n0, n1; + int n, n0, n1; n0 = ring_full_count(&ttyoring); if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) { @@ -167,8 +164,8 @@ ttyflush(drop) */ - int -getconnmode() +int +getconnmode(void) { extern int linemode; int mode = 0; @@ -176,9 +173,6 @@ getconnmode() extern int kludgelinemode; #endif - if (In3270) - return(MODE_FLOW); - if (my_want_state_is_dont(TELOPT_ECHO)) mode |= MODE_ECHO; @@ -207,11 +201,10 @@ getconnmode() return(mode); } - void -setconnmode(force) - int force; +void +setconnmode(int force) { - register int newmode; + int newmode; newmode = getconnmode()|(force?MODE_FORCE:0); @@ -220,9 +213,8 @@ setconnmode(force) } - - void -setcommandmode() +void +setcommandmode(void) { TerminalNewMode(-1); } diff --git a/usr.bin/telnet/tn3270.c b/usr.bin/telnet/tn3270.c deleted file mode 100644 index 92219b7..0000000 --- a/usr.bin/telnet/tn3270.c +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static const char sccsid[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95"; -#else -static const char rcsid[] = - "$FreeBSD$"; -#endif -#endif /* not lint */ - -#include -#include - -#include "general.h" - -#include "defines.h" -#include "ring.h" -#include "externs.h" -#include "fdset.h" - -#if defined(TN3270) - -#include "../ctlr/screen.h" -#include "../general/globals.h" - -#include "../sys_curses/telextrn.h" -#include "../ctlr/externs.h" - -#if defined(unix) -int - HaveInput, /* There is input available to scan */ - cursesdata, /* Do we dump curses data? */ - sigiocount; /* Number of times we got a SIGIO */ - -char tline[200]; -char *transcom = 0; /* transparent mode command (default: none) */ -#endif /* defined(unix) */ - -char Ibuf[8*BUFSIZ], *Ifrontp, *Ibackp; - -static char sb_terminal[] = { IAC, SB, - TELOPT_TTYPE, TELQUAL_IS, - 'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2', - IAC, SE }; -#define SBTERMMODEL 13 - -static int - Sent3270TerminalType; /* Have we said we are a 3270? */ - -#endif /* defined(TN3270) */ - - - void -init_3270() -{ -#if defined(TN3270) -#if defined(unix) - HaveInput = 0; - sigiocount = 0; -#endif /* defined(unix) */ - Sent3270TerminalType = 0; - Ifrontp = Ibackp = Ibuf; - init_ctlr(); /* Initialize some things */ - init_keyboard(); - init_screen(); - init_system(); -#endif /* defined(TN3270) */ -} - - -#if defined(TN3270) - -/* - * DataToNetwork - queue up some data to go to network. If "done" is set, - * then when last byte is queued, we add on an IAC EOR sequence (so, - * don't call us with "done" until you want that done...) - * - * We actually do send all the data to the network buffer, since our - * only client needs for us to do that. - */ - - int -DataToNetwork(buffer, count, done) - register char *buffer; /* where the data is */ - register int count; /* how much to send */ - int done; /* is this the last of a logical block */ -{ - register int loop, c; - int origCount; - - origCount = count; - - while (count) { - /* If not enough room for EORs, IACs, etc., wait */ - if (NETROOM() < 6) { - fd_set o; - - FD_ZERO(&o); - netflush(); - while (NETROOM() < 6) { - FD_SET(net, &o); - (void) select(net+1, (fd_set *) 0, &o, (fd_set *) 0, - (struct timeval *) 0); - netflush(); - } - } - c = ring_empty_count(&netoring); - if (c > count) { - c = count; - } - loop = c; - while (loop) { - if (((unsigned char)*buffer) == IAC) { - break; - } - buffer++; - loop--; - } - if ((c = c-loop)) { - ring_supply_data(&netoring, buffer-c, c); - count -= c; - } - if (loop) { - NET2ADD(IAC, IAC); - count--; - buffer++; - } - } - - if (done) { - NET2ADD(IAC, EOR); - netflush(); /* try to move along as quickly as ... */ - } - return(origCount - count); -} - - -#if defined(unix) - void -inputAvailable(signo) - int signo; -{ - HaveInput = 1; - sigiocount++; -} -#endif /* defined(unix) */ - - void -outputPurge() -{ - (void) ttyflush(1); -} - - -/* - * The following routines are places where the various tn3270 - * routines make calls into telnet.c. - */ - -/* - * DataToTerminal - queue up some data to go to terminal. - * - * Note: there are people who call us and depend on our processing - * *all* the data at one time (thus the select). - */ - - int -DataToTerminal(buffer, count) - register char *buffer; /* where the data is */ - register int count; /* how much to send */ -{ - register int c; - int origCount; - - origCount = count; - - while (count) { - if (TTYROOM() == 0) { -#if defined(unix) - fd_set o; - - FD_ZERO(&o); -#endif /* defined(unix) */ - (void) ttyflush(0); - while (TTYROOM() == 0) { -#if defined(unix) - FD_SET(tout, &o); - (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0, - (struct timeval *) 0); -#endif /* defined(unix) */ - (void) ttyflush(0); - } - } - c = TTYROOM(); - if (c > count) { - c = count; - } - ring_supply_data(&ttyoring, buffer, c); - count -= c; - buffer += c; - } - return(origCount); -} - - -/* - * Push3270 - Try to send data along the 3270 output (to screen) direction. - */ - - int -Push3270() -{ - int save = ring_full_count(&netiring); - - if (save) { - if (Ifrontp+save > Ibuf+sizeof Ibuf) { - if (Ibackp != Ibuf) { - memmove(Ibuf, Ibackp, Ifrontp-Ibackp); - Ifrontp -= (Ibackp-Ibuf); - Ibackp = Ibuf; - } - } - if (Ifrontp+save < Ibuf+sizeof Ibuf) { - (void)telrcv(); - } - } - return save != ring_full_count(&netiring); -} - - -/* - * Finish3270 - get the last dregs of 3270 data out to the terminal - * before quitting. - */ - - void -Finish3270() -{ - while (Push3270() || !DoTerminalOutput()) { -#if defined(unix) - HaveInput = 0; -#endif /* defined(unix) */ - ; - } -} - - -/* StringToTerminal - output a null terminated string to the terminal */ - - void -StringToTerminal(s) - char *s; -{ - int count; - - count = strlen(s); - if (count) { - (void) DataToTerminal(s, count); /* we know it always goes... */ - } -} - - -#if ((!defined(NOT43)) || defined(PUTCHAR)) -/* _putchar - output a single character to the terminal. This name is so that - * curses(3x) can call us to send out data. - */ - - void -_putchar(c) - char c; -{ -#if defined(sun) /* SunOS 4.0 bug */ - c &= 0x7f; -#endif /* defined(sun) */ - if (cursesdata) { - Dump('>', &c, 1); - } - if (!TTYROOM()) { - (void) DataToTerminal(&c, 1); - } else { - TTYADD(c); - } -} -#endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */ - - void -SetIn3270() -{ - if (Sent3270TerminalType && my_want_state_is_will(TELOPT_BINARY) - && my_want_state_is_do(TELOPT_BINARY) && !donebinarytoggle) { - if (!In3270) { - In3270 = 1; - Init3270(); /* Initialize 3270 functions */ - /* initialize terminal key mapping */ - InitTerminal(); /* Start terminal going */ - setconnmode(0); - } - } else { - if (In3270) { - StopScreen(1); - In3270 = 0; - Stop3270(); /* Tell 3270 we aren't here anymore */ - setconnmode(0); - } - } -} - -/* - * tn3270_ttype() - * - * Send a response to a terminal type negotiation. - * - * Return '0' if no more responses to send; '1' if a response sent. - */ - - int -tn3270_ttype() -{ - /* - * Try to send a 3270 type terminal name. Decide which one based - * on the format of our screen, and (in the future) color - * capaiblities. - */ - InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */ - if ((MaxNumberLines >= 24) && (MaxNumberColumns >= 80)) { - Sent3270TerminalType = 1; - if ((MaxNumberLines >= 27) && (MaxNumberColumns >= 132)) { - MaxNumberLines = 27; - MaxNumberColumns = 132; - sb_terminal[SBTERMMODEL] = '5'; - } else if (MaxNumberLines >= 43) { - MaxNumberLines = 43; - MaxNumberColumns = 80; - sb_terminal[SBTERMMODEL] = '4'; - } else if (MaxNumberLines >= 32) { - MaxNumberLines = 32; - MaxNumberColumns = 80; - sb_terminal[SBTERMMODEL] = '3'; - } else { - MaxNumberLines = 24; - MaxNumberColumns = 80; - sb_terminal[SBTERMMODEL] = '2'; - } - NumberLines = 24; /* before we start out... */ - NumberColumns = 80; - ScreenSize = NumberLines*NumberColumns; - if ((MaxNumberLines*MaxNumberColumns) > MAXSCREENSIZE) { - ExitString("Programming error: MAXSCREENSIZE too small.\n", - 1); - /*NOTREACHED*/ - } - printsub('>', sb_terminal+2, sizeof sb_terminal-2); - ring_supply_data(&netoring, sb_terminal, sizeof sb_terminal); - return 1; - } else { - return 0; - } -} - -#if defined(unix) - int -settranscom(argc, argv) - int argc; - char *argv[]; -{ - int i; - - if (argc == 1 && transcom) { - transcom = 0; - } - if (argc == 1) { - return 1; - } - transcom = tline; - (void) strcpy(transcom, argv[1]); - for (i = 2; i < argc; ++i) { - (void) strcat(transcom, " "); - (void) strcat(transcom, argv[i]); - } - return 1; -} -#endif /* defined(unix) */ - -#endif /* defined(TN3270) */ diff --git a/usr.bin/telnet/utilities.c b/usr.bin/telnet/utilities.c index ff6e1eb..8ea888e 100644 --- a/usr.bin/telnet/utilities.c +++ b/usr.bin/telnet/utilities.c @@ -31,14 +31,13 @@ * SUCH DAMAGE. */ +#include + +__FBSDID("$FreeBSD$"); + #ifndef lint -#if 0 static const char sccsid[] = "@(#)utilities.c 8.3 (Berkeley) 5/30/95"; -#else -static const char rcsid[] = - "$FreeBSD$"; #endif -#endif /* not lint */ #define TELOPTS #define TELCMDS @@ -60,6 +59,7 @@ static const char rcsid[] = #include "externs.h" + FILE *NetTrace = 0; /* Not in bss, since needs to stay */ int prettydump; @@ -69,11 +69,10 @@ int prettydump; * Upcase (in place) the argument. */ - void -upcase(argument) - register char *argument; +void +upcase(char *argument) { - register int c; + int c; while ((c = *argument) != 0) { if (islower(c)) { @@ -89,21 +88,11 @@ upcase(argument) * Compensate for differences in 4.2 and 4.3 systems. */ - int -SetSockOpt(fd, level, option, yesno) - int fd, level, option, yesno; +int +SetSockOpt(int fd, int level, int option, int yesno) { -#ifndef NOT43 return setsockopt(fd, level, option, (char *)&yesno, sizeof yesno); -#else /* NOT43 */ - if (yesno == 0) { /* Can't do that in 4.2! */ - fprintf(stderr, "Error: attempt to turn off an option 0x%x.\n", - option); - return -1; - } - return setsockopt(fd, level, option, 0, 0); -#endif /* NOT43 */ } /* @@ -112,9 +101,8 @@ SetSockOpt(fd, level, option, yesno) unsigned char NetTraceFile[256] = "(standard output)"; - void -SetNetTrace(file) - register char *file; +void +SetNetTrace(char *file) { if (NetTrace && NetTrace != stdout) fclose(NetTrace); @@ -130,11 +118,8 @@ SetNetTrace(file) strcpy((char *)NetTraceFile, "(standard output)"); } - void -Dump(direction, buffer, length) - char direction; - unsigned char *buffer; - int length; +void +Dump(char direction, unsigned char *buffer, int length) { # define BYTES_PER_LINE 32 # define min(x,y) ((x' */ - unsigned char *pointer; /* where suboption data sits */ - int length; /* length of suboption data */ +void +printsub(char direction, unsigned char *pointer, int length) { - register int i; - char buf[512]; + int i; extern int want_status_response; if (showoptions || direction == 0 || @@ -310,7 +289,7 @@ printsub(direction, pointer, length) fprintf(NetTrace, "%s IAC SB ", (direction == '<')? "RCVD":"SENT"); if (length >= 3) { - register int j; + int j; i = pointer[length-2]; j = pointer[length-1]; @@ -525,8 +504,8 @@ printsub(direction, pointer, length) break; case TELOPT_STATUS: { - register char *cp; - register int j, k; + const char *cp; + int j, k; fprintf(NetTrace, "STATUS"); @@ -639,7 +618,7 @@ printsub(direction, pointer, length) fprintf(NetTrace, "INFO "); env_common: { - register int noquote = 2; + int noquote = 2; #if defined(ENV_HACK) && defined(OLD_ENVIRON) extern int old_env_var, old_env_value; #endif @@ -734,72 +713,52 @@ printsub(direction, pointer, length) * way to the kernel (thus the select). */ - void -EmptyTerminal() +static void +EmptyTerminal(void) { -#if defined(unix) fd_set o; FD_ZERO(&o); -#endif /* defined(unix) */ if (TTYBYTES() == 0) { -#if defined(unix) FD_SET(tout, &o); (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0, (struct timeval *) 0); /* wait for TTLOWAT */ -#endif /* defined(unix) */ } else { while (TTYBYTES()) { (void) ttyflush(0); -#if defined(unix) FD_SET(tout, &o); (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0, (struct timeval *) 0); /* wait for TTLOWAT */ -#endif /* defined(unix) */ } } } - void -SetForExit() +static void +SetForExit(void) { setconnmode(0); -#if defined(TN3270) - if (In3270) { - Finish3270(); - } -#else /* defined(TN3270) */ do { (void)telrcv(); /* Process any incoming data */ EmptyTerminal(); } while (ring_full_count(&netiring)); /* While there is any */ -#endif /* defined(TN3270) */ setcommandmode(); fflush(stdout); fflush(stderr); -#if defined(TN3270) - if (In3270) { - StopScreen(1); - } -#endif /* defined(TN3270) */ setconnmode(0); EmptyTerminal(); /* Flush the path to the tty */ setcommandmode(); } - void -Exit(returnCode) - int returnCode; +void +Exit(int returnCode) { SetForExit(); exit(returnCode); } - void -ExitString(string, returnCode) - char *string; - int returnCode; +void +ExitString(const char *string, int returnCode) { SetForExit(); fwrite(string, 1, strlen(string), stderr); -- cgit v1.1