Initial revision
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@51 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
111
appl/telnet/telnet/authenc.c
Normal file
111
appl/telnet/telnet/authenc.c
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1991, 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
|
||||||
|
static char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <arpa/telnet.h>
|
||||||
|
#include <libtelnet/encrypt.h>
|
||||||
|
#include <libtelnet/misc.h>
|
||||||
|
|
||||||
|
#include "general.h"
|
||||||
|
#include "ring.h"
|
||||||
|
#include "externs.h"
|
||||||
|
#include "defines.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
net_write(str, len)
|
||||||
|
unsigned char *str;
|
||||||
|
int len;
|
||||||
|
{
|
||||||
|
if (NETROOM() > len) {
|
||||||
|
ring_supply_data(&netoring, str, len);
|
||||||
|
if (str[0] == IAC && str[1] == SE)
|
||||||
|
printsub('>', &str[2], len-2);
|
||||||
|
return(len);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
net_encrypt()
|
||||||
|
{
|
||||||
|
#if defined(ENCRYPTION)
|
||||||
|
if (encrypt_output)
|
||||||
|
ring_encrypt(&netoring, encrypt_output);
|
||||||
|
else
|
||||||
|
ring_clearto(&netoring);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
telnet_spin()
|
||||||
|
{
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
telnet_getenv(val)
|
||||||
|
char *val;
|
||||||
|
{
|
||||||
|
return((char *)env_getvalue((unsigned char *)val));
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
telnet_gets(prompt, result, length, echo)
|
||||||
|
char *prompt;
|
||||||
|
char *result;
|
||||||
|
int length;
|
||||||
|
int echo;
|
||||||
|
{
|
||||||
|
extern char *getpass();
|
||||||
|
extern int globalmode;
|
||||||
|
int om = globalmode;
|
||||||
|
char *res;
|
||||||
|
|
||||||
|
TerminalNewMode(-1);
|
||||||
|
if (echo) {
|
||||||
|
printf("%s", prompt);
|
||||||
|
res = fgets(result, length, stdin);
|
||||||
|
} else if (res = getpass(prompt)) {
|
||||||
|
strncpy(result, res, length);
|
||||||
|
res = result;
|
||||||
|
}
|
||||||
|
TerminalNewMode(om);
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
#endif
|
2939
appl/telnet/telnet/commands.c
Normal file
2939
appl/telnet/telnet/commands.c
Normal file
File diff suppressed because it is too large
Load Diff
177
appl/telnet/telnet/network.c
Normal file
177
appl/telnet/telnet/network.c
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
static char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <arpa/telnet.h>
|
||||||
|
|
||||||
|
#include "ring.h"
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
#include "externs.h"
|
||||||
|
#include "fdset.h"
|
||||||
|
|
||||||
|
Ring netoring, netiring;
|
||||||
|
unsigned char netobuf[2*BUFSIZ], netibuf[BUFSIZ];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize internal network data structures.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
init_network()
|
||||||
|
{
|
||||||
|
if (ring_init(&netoring, netobuf, sizeof netobuf) != 1) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (ring_init(&netiring, netibuf, sizeof netibuf) != 1) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
NetTrace = stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check to see if any out-of-band data exists on a socket (for
|
||||||
|
* Telnet "synch" processing).
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
stilloob()
|
||||||
|
{
|
||||||
|
static struct timeval timeout = { 0 };
|
||||||
|
fd_set excepts;
|
||||||
|
int value;
|
||||||
|
|
||||||
|
do {
|
||||||
|
FD_ZERO(&excepts);
|
||||||
|
FD_SET(net, &excepts);
|
||||||
|
value = select(net+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
|
||||||
|
} while ((value == -1) && (errno == EINTR));
|
||||||
|
|
||||||
|
if (value < 0) {
|
||||||
|
perror("select");
|
||||||
|
(void) quit();
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
if (FD_ISSET(net, &excepts)) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* setneturg()
|
||||||
|
*
|
||||||
|
* Sets "neturg" to the current location.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
setneturg()
|
||||||
|
{
|
||||||
|
ring_mark(&netoring);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* netflush
|
||||||
|
* Send as much data as possible to the network,
|
||||||
|
* handling requests for urgent data.
|
||||||
|
*
|
||||||
|
* The return value indicates whether we did any
|
||||||
|
* useful work.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
netflush()
|
||||||
|
{
|
||||||
|
register int n, n1;
|
||||||
|
|
||||||
|
#if defined(ENCRYPTION)
|
||||||
|
if (encrypt_output)
|
||||||
|
ring_encrypt(&netoring, encrypt_output);
|
||||||
|
#endif
|
||||||
|
if ((n1 = n = ring_full_consecutive(&netoring)) > 0) {
|
||||||
|
if (!ring_at_mark(&netoring)) {
|
||||||
|
n = send(net, (char *)netoring.consume, n, 0); /* normal write */
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* In 4.2 (and 4.3) systems, there is some question about
|
||||||
|
* what byte in a sendOOB operation is the "OOB" data.
|
||||||
|
* To make ourselves compatible, we only send ONE byte
|
||||||
|
* out of band, the one WE THINK should be OOB (though
|
||||||
|
* we really have more the TCP philosophy of urgent data
|
||||||
|
* rather than the Unix philosophy of OOB data).
|
||||||
|
*/
|
||||||
|
n = send(net, (char *)netoring.consume, 1, MSG_OOB);/* URGENT data */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno != ENOBUFS && errno != EWOULDBLOCK) {
|
||||||
|
setcommandmode();
|
||||||
|
perror(hostname);
|
||||||
|
(void)NetClose(net);
|
||||||
|
ring_clear_mark(&netoring);
|
||||||
|
longjmp(peerdied, -1);
|
||||||
|
/*NOTREACHED*/
|
||||||
|
}
|
||||||
|
n = 0;
|
||||||
|
}
|
||||||
|
if (netdata && n) {
|
||||||
|
Dump('>', netoring.consume, n);
|
||||||
|
}
|
||||||
|
if (n) {
|
||||||
|
ring_consumed(&netoring, n);
|
||||||
|
/*
|
||||||
|
* If we sent all, and more to send, then recurse to pick
|
||||||
|
* up the other half.
|
||||||
|
*/
|
||||||
|
if ((n1 == n) && ring_full_consecutive(&netoring)) {
|
||||||
|
(void) netflush();
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
363
appl/telnet/telnet/ring.c
Normal file
363
appl/telnet/telnet/ring.c
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
static char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This defines a structure for a ring buffer.
|
||||||
|
*
|
||||||
|
* The circular buffer has two parts:
|
||||||
|
*(((
|
||||||
|
* full: [consume, supply)
|
||||||
|
* empty: [supply, consume)
|
||||||
|
*]]]
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifdef size_t
|
||||||
|
#undef size_t
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifndef FILIO_H
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include "ring.h"
|
||||||
|
#include "general.h"
|
||||||
|
|
||||||
|
/* Internal macros */
|
||||||
|
|
||||||
|
#if !defined(MIN)
|
||||||
|
#define MIN(a,b) (((a)<(b))? (a):(b))
|
||||||
|
#endif /* !defined(MIN) */
|
||||||
|
|
||||||
|
#define ring_subtract(d,a,b) (((a)-(b) >= 0)? \
|
||||||
|
(a)-(b): (((a)-(b))+(d)->size))
|
||||||
|
|
||||||
|
#define ring_increment(d,a,c) (((a)+(c) < (d)->top)? \
|
||||||
|
(a)+(c) : (((a)+(c))-(d)->size))
|
||||||
|
|
||||||
|
#define ring_decrement(d,a,c) (((a)-(c) >= (d)->bottom)? \
|
||||||
|
(a)-(c) : (((a)-(c))-(d)->size))
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following is a clock, used to determine full, empty, etc.
|
||||||
|
*
|
||||||
|
* There is some trickiness here. Since the ring buffers are initialized
|
||||||
|
* to ZERO on allocation, we need to make sure, when interpreting the
|
||||||
|
* clock, that when the times are EQUAL, then the buffer is FULL.
|
||||||
|
*/
|
||||||
|
static u_long ring_clock = 0;
|
||||||
|
|
||||||
|
|
||||||
|
#define ring_empty(d) (((d)->consume == (d)->supply) && \
|
||||||
|
((d)->consumetime >= (d)->supplytime))
|
||||||
|
#define ring_full(d) (((d)->supply == (d)->consume) && \
|
||||||
|
((d)->supplytime > (d)->consumetime))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Buffer state transition routines */
|
||||||
|
|
||||||
|
ring_init(ring, buffer, count)
|
||||||
|
Ring *ring;
|
||||||
|
unsigned char *buffer;
|
||||||
|
int count;
|
||||||
|
{
|
||||||
|
memset((char *)ring, 0, sizeof *ring);
|
||||||
|
|
||||||
|
ring->size = count;
|
||||||
|
|
||||||
|
ring->supply = ring->consume = ring->bottom = buffer;
|
||||||
|
|
||||||
|
ring->top = ring->bottom+ring->size;
|
||||||
|
|
||||||
|
#if defined(ENCRYPTION)
|
||||||
|
ring->clearto = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mark routines */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mark the most recently supplied byte.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
ring_mark(ring)
|
||||||
|
Ring *ring;
|
||||||
|
{
|
||||||
|
ring->mark = ring_decrement(ring, ring->supply, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Is the ring pointing to the mark?
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
ring_at_mark(ring)
|
||||||
|
Ring *ring;
|
||||||
|
{
|
||||||
|
if (ring->mark == ring->consume) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Clear any mark set on the ring.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
ring_clear_mark(ring)
|
||||||
|
Ring *ring;
|
||||||
|
{
|
||||||
|
ring->mark = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add characters from current segment to ring buffer.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ring_supplied(ring, count)
|
||||||
|
Ring *ring;
|
||||||
|
int count;
|
||||||
|
{
|
||||||
|
ring->supply = ring_increment(ring, ring->supply, count);
|
||||||
|
ring->supplytime = ++ring_clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We have just consumed "c" bytes.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ring_consumed(ring, count)
|
||||||
|
Ring *ring;
|
||||||
|
int count;
|
||||||
|
{
|
||||||
|
if (count == 0) /* don't update anything */
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ring->mark &&
|
||||||
|
(ring_subtract(ring, ring->mark, ring->consume) < count)) {
|
||||||
|
ring->mark = 0;
|
||||||
|
}
|
||||||
|
#if defined(ENCRYPTION)
|
||||||
|
if (ring->consume < ring->clearto &&
|
||||||
|
ring->clearto <= ring->consume + count)
|
||||||
|
ring->clearto = 0;
|
||||||
|
else if (ring->consume + count > ring->top &&
|
||||||
|
ring->bottom <= ring->clearto &&
|
||||||
|
ring->bottom + ((ring->consume + count) - ring->top))
|
||||||
|
ring->clearto = 0;
|
||||||
|
#endif
|
||||||
|
ring->consume = ring_increment(ring, ring->consume, count);
|
||||||
|
ring->consumetime = ++ring_clock;
|
||||||
|
/*
|
||||||
|
* Try to encourage "ring_empty_consecutive()" to be large.
|
||||||
|
*/
|
||||||
|
if (ring_empty(ring)) {
|
||||||
|
ring->consume = ring->supply = ring->bottom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Buffer state query routines */
|
||||||
|
|
||||||
|
|
||||||
|
/* Number of bytes that may be supplied */
|
||||||
|
int
|
||||||
|
ring_empty_count(ring)
|
||||||
|
Ring *ring;
|
||||||
|
{
|
||||||
|
if (ring_empty(ring)) { /* if empty */
|
||||||
|
return ring->size;
|
||||||
|
} else {
|
||||||
|
return ring_subtract(ring, ring->consume, ring->supply);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* number of CONSECUTIVE bytes that may be supplied */
|
||||||
|
int
|
||||||
|
ring_empty_consecutive(ring)
|
||||||
|
Ring *ring;
|
||||||
|
{
|
||||||
|
if ((ring->consume < ring->supply) || ring_empty(ring)) {
|
||||||
|
/*
|
||||||
|
* if consume is "below" supply, or empty, then
|
||||||
|
* return distance to the top
|
||||||
|
*/
|
||||||
|
return ring_subtract(ring, ring->top, ring->supply);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* else, return what we may.
|
||||||
|
*/
|
||||||
|
return ring_subtract(ring, ring->consume, ring->supply);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the number of bytes that are available for consuming
|
||||||
|
* (but don't give more than enough to get to cross over set mark)
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
ring_full_count(ring)
|
||||||
|
Ring *ring;
|
||||||
|
{
|
||||||
|
if ((ring->mark == 0) || (ring->mark == ring->consume)) {
|
||||||
|
if (ring_full(ring)) {
|
||||||
|
return ring->size; /* nothing consumed, but full */
|
||||||
|
} else {
|
||||||
|
return ring_subtract(ring, ring->supply, ring->consume);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ring_subtract(ring, ring->mark, ring->consume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
{
|
||||||
|
if ((ring->mark == 0) || (ring->mark == ring->consume)) {
|
||||||
|
if ((ring->supply < ring->consume) || ring_full(ring)) {
|
||||||
|
return ring_subtract(ring, ring->top, ring->consume);
|
||||||
|
} else {
|
||||||
|
return ring_subtract(ring, ring->supply, ring->consume);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ring->mark < ring->consume) {
|
||||||
|
return ring_subtract(ring, ring->top, ring->consume);
|
||||||
|
} else { /* Else, distance to mark */
|
||||||
|
return ring_subtract(ring, ring->mark, ring->consume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
while (count) {
|
||||||
|
i = MIN(count, ring_empty_consecutive(ring));
|
||||||
|
memmove(ring->supply, buffer, i);
|
||||||
|
ring_supplied(ring, i);
|
||||||
|
count -= i;
|
||||||
|
buffer += i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#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));
|
||||||
|
memmove(buffer, ring->consume, i);
|
||||||
|
ring_consumed(ring, i);
|
||||||
|
count -= i;
|
||||||
|
buffer += i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ENCRYPTION)
|
||||||
|
void
|
||||||
|
ring_encrypt(ring, encryptor)
|
||||||
|
Ring *ring;
|
||||||
|
void (*encryptor)();
|
||||||
|
{
|
||||||
|
unsigned char *s, *c;
|
||||||
|
|
||||||
|
if (ring_empty(ring) || ring->clearto == ring->supply)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!(c = ring->clearto))
|
||||||
|
c = ring->consume;
|
||||||
|
|
||||||
|
s = ring->supply;
|
||||||
|
|
||||||
|
if (s <= c) {
|
||||||
|
(*encryptor)(c, ring->top - c);
|
||||||
|
(*encryptor)(ring->bottom, s - ring->bottom);
|
||||||
|
} else
|
||||||
|
(*encryptor)(c, s - c);
|
||||||
|
|
||||||
|
ring->clearto = ring->supply;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ring_clearto(ring)
|
||||||
|
Ring *ring;
|
||||||
|
{
|
||||||
|
if (!ring_empty(ring))
|
||||||
|
ring->clearto = ring->supply;
|
||||||
|
else
|
||||||
|
ring->clearto = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
1220
appl/telnet/telnet/sys_bsd.c
Normal file
1220
appl/telnet/telnet/sys_bsd.c
Normal file
File diff suppressed because it is too large
Load Diff
2650
appl/telnet/telnet/telnet.c
Normal file
2650
appl/telnet/telnet/telnet.c
Normal file
File diff suppressed because it is too large
Load Diff
240
appl/telnet/telnet/terminal.c
Normal file
240
appl/telnet/telnet/terminal.c
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1988, 1990, 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
|
||||||
|
static char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <arpa/telnet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "ring.h"
|
||||||
|
|
||||||
|
#include "externs.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
Ring ttyoring, ttyiring;
|
||||||
|
unsigned char ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
|
||||||
|
|
||||||
|
int termdata; /* Debugging flag */
|
||||||
|
|
||||||
|
#ifdef USE_TERMIO
|
||||||
|
# ifndef VDISCARD
|
||||||
|
cc_t termFlushChar;
|
||||||
|
# endif
|
||||||
|
# ifndef VLNEXT
|
||||||
|
cc_t termLiteralNextChar;
|
||||||
|
# endif
|
||||||
|
# ifndef VSUSP
|
||||||
|
cc_t termSuspChar;
|
||||||
|
# endif
|
||||||
|
# ifndef VWERASE
|
||||||
|
cc_t termWerasChar;
|
||||||
|
# endif
|
||||||
|
# ifndef VREPRINT
|
||||||
|
cc_t termRprntChar;
|
||||||
|
# endif
|
||||||
|
# ifndef VSTART
|
||||||
|
cc_t termStartChar;
|
||||||
|
# endif
|
||||||
|
# ifndef VSTOP
|
||||||
|
cc_t termStopChar;
|
||||||
|
# endif
|
||||||
|
# ifndef VEOL
|
||||||
|
cc_t termForw1Char;
|
||||||
|
# endif
|
||||||
|
# ifndef VEOL2
|
||||||
|
cc_t termForw2Char;
|
||||||
|
# endif
|
||||||
|
# ifndef VSTATUS
|
||||||
|
cc_t termAytChar;
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
cc_t termForw2Char;
|
||||||
|
cc_t termAytChar;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* initialize the terminal data structures.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
init_terminal()
|
||||||
|
{
|
||||||
|
if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (ring_init(&ttyiring, ttyibuf, sizeof ttyibuf) != 1) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
autoflush = TerminalAutoFlush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send as much data as possible to the terminal.
|
||||||
|
*
|
||||||
|
* Return value:
|
||||||
|
* -1: No useful work done, data waiting to go out.
|
||||||
|
* 0: No data was waiting, so nothing was done.
|
||||||
|
* 1: All waiting data was written out.
|
||||||
|
* n: All data - n was written out.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
ttyflush(drop)
|
||||||
|
int drop;
|
||||||
|
{
|
||||||
|
register int n, n0, n1;
|
||||||
|
|
||||||
|
n0 = ring_full_count(&ttyoring);
|
||||||
|
if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
|
||||||
|
if (drop) {
|
||||||
|
TerminalFlushOutput();
|
||||||
|
/* we leave 'n' alone! */
|
||||||
|
} else {
|
||||||
|
n = TerminalWrite(ttyoring.consume, n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n > 0) {
|
||||||
|
if (termdata && n) {
|
||||||
|
Dump('>', ttyoring.consume, n);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* If we wrote everything, and the full count is
|
||||||
|
* larger than what we wrote, then write the
|
||||||
|
* rest of the buffer.
|
||||||
|
*/
|
||||||
|
if (n1 == n && n0 > n) {
|
||||||
|
n1 = n0 - n;
|
||||||
|
if (!drop)
|
||||||
|
n1 = TerminalWrite(ttyoring.bottom, n1);
|
||||||
|
if (n1 > 0)
|
||||||
|
n += n1;
|
||||||
|
}
|
||||||
|
ring_consumed(&ttyoring, n);
|
||||||
|
}
|
||||||
|
if (n < 0)
|
||||||
|
return -1;
|
||||||
|
if (n == n0) {
|
||||||
|
if (n0)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return n0 - n + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These routines decides on what the mode should be (based on the values
|
||||||
|
* of various global variables).
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
getconnmode()
|
||||||
|
{
|
||||||
|
extern int linemode;
|
||||||
|
int mode = 0;
|
||||||
|
#ifdef KLUDGELINEMODE
|
||||||
|
extern int kludgelinemode;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (In3270)
|
||||||
|
return(MODE_FLOW);
|
||||||
|
|
||||||
|
if (my_want_state_is_dont(TELOPT_ECHO))
|
||||||
|
mode |= MODE_ECHO;
|
||||||
|
|
||||||
|
if (localflow)
|
||||||
|
mode |= MODE_FLOW;
|
||||||
|
|
||||||
|
if (my_want_state_is_will(TELOPT_BINARY))
|
||||||
|
mode |= MODE_INBIN;
|
||||||
|
|
||||||
|
if (his_want_state_is_will(TELOPT_BINARY))
|
||||||
|
mode |= MODE_OUTBIN;
|
||||||
|
|
||||||
|
#ifdef KLUDGELINEMODE
|
||||||
|
if (kludgelinemode) {
|
||||||
|
if (my_want_state_is_dont(TELOPT_SGA)) {
|
||||||
|
mode |= (MODE_TRAPSIG|MODE_EDIT);
|
||||||
|
if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
|
||||||
|
mode &= ~MODE_ECHO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(mode);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (my_want_state_is_will(TELOPT_LINEMODE))
|
||||||
|
mode |= linemode;
|
||||||
|
return(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
setconnmode(force)
|
||||||
|
int force;
|
||||||
|
{
|
||||||
|
#ifdef ENCRYPTION
|
||||||
|
static int enc_passwd = 0;
|
||||||
|
#endif
|
||||||
|
register int newmode;
|
||||||
|
|
||||||
|
newmode = getconnmode()|(force?MODE_FORCE:0);
|
||||||
|
|
||||||
|
TerminalNewMode(newmode);
|
||||||
|
|
||||||
|
#ifdef ENCRYPTION
|
||||||
|
if ((newmode & (MODE_ECHO|MODE_EDIT)) == MODE_EDIT) {
|
||||||
|
if (my_want_state_is_will(TELOPT_ENCRYPT)
|
||||||
|
&& (enc_passwd == 0) && !encrypt_output) {
|
||||||
|
encrypt_request_start(0, 0);
|
||||||
|
enc_passwd = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (enc_passwd) {
|
||||||
|
encrypt_request_end();
|
||||||
|
enc_passwd = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
setcommandmode()
|
||||||
|
{
|
||||||
|
TerminalNewMode(-1);
|
||||||
|
}
|
939
appl/telnet/telnet/utilities.c
Normal file
939
appl/telnet/telnet/utilities.c
Normal file
@@ -0,0 +1,939 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
static char sccsid[] = "@(#)utilities.c 8.3 (Berkeley) 5/30/95";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#define TELOPTS
|
||||||
|
#define TELCMDS
|
||||||
|
#define SLC_NAMES
|
||||||
|
#include <arpa/telnet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "general.h"
|
||||||
|
|
||||||
|
#include "fdset.h"
|
||||||
|
|
||||||
|
#include "ring.h"
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
|
#include "externs.h"
|
||||||
|
|
||||||
|
FILE *NetTrace = 0; /* Not in bss, since needs to stay */
|
||||||
|
int prettydump;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* upcase()
|
||||||
|
*
|
||||||
|
* Upcase (in place) the argument.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
upcase(argument)
|
||||||
|
register char *argument;
|
||||||
|
{
|
||||||
|
register int c;
|
||||||
|
|
||||||
|
while ((c = *argument) != 0) {
|
||||||
|
if (islower(c)) {
|
||||||
|
*argument = toupper(c);
|
||||||
|
}
|
||||||
|
argument++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SetSockOpt()
|
||||||
|
*
|
||||||
|
* Compensate for differences in 4.2 and 4.3 systems.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
SetSockOpt(fd, level, option, yesno)
|
||||||
|
int fd, level, option, 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 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following are routines used to print out debugging information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned char NetTraceFile[256] = "(standard output)";
|
||||||
|
|
||||||
|
void
|
||||||
|
SetNetTrace(file)
|
||||||
|
register char *file;
|
||||||
|
{
|
||||||
|
if (NetTrace && NetTrace != stdout)
|
||||||
|
fclose(NetTrace);
|
||||||
|
if (file && (strcmp(file, "-") != 0)) {
|
||||||
|
NetTrace = fopen(file, "w");
|
||||||
|
if (NetTrace) {
|
||||||
|
strcpy((char *)NetTraceFile, file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "Cannot open %s.\n", file);
|
||||||
|
}
|
||||||
|
NetTrace = stdout;
|
||||||
|
strcpy((char *)NetTraceFile, "(standard output)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Dump(direction, buffer, length)
|
||||||
|
char direction;
|
||||||
|
unsigned char *buffer;
|
||||||
|
int length;
|
||||||
|
{
|
||||||
|
# define BYTES_PER_LINE 32
|
||||||
|
# define min(x,y) ((x<y)? x:y)
|
||||||
|
unsigned char *pThis;
|
||||||
|
int offset;
|
||||||
|
extern pettydump;
|
||||||
|
|
||||||
|
offset = 0;
|
||||||
|
|
||||||
|
while (length) {
|
||||||
|
/* print one line */
|
||||||
|
fprintf(NetTrace, "%c 0x%x\t", direction, offset);
|
||||||
|
pThis = buffer;
|
||||||
|
if (prettydump) {
|
||||||
|
buffer = buffer + min(length, BYTES_PER_LINE/2);
|
||||||
|
while (pThis < buffer) {
|
||||||
|
fprintf(NetTrace, "%c%.2x",
|
||||||
|
(((*pThis)&0xff) == 0xff) ? '*' : ' ',
|
||||||
|
(*pThis)&0xff);
|
||||||
|
pThis++;
|
||||||
|
}
|
||||||
|
length -= BYTES_PER_LINE/2;
|
||||||
|
offset += BYTES_PER_LINE/2;
|
||||||
|
} else {
|
||||||
|
buffer = buffer + min(length, BYTES_PER_LINE);
|
||||||
|
while (pThis < buffer) {
|
||||||
|
fprintf(NetTrace, "%.2x", (*pThis)&0xff);
|
||||||
|
pThis++;
|
||||||
|
}
|
||||||
|
length -= BYTES_PER_LINE;
|
||||||
|
offset += BYTES_PER_LINE;
|
||||||
|
}
|
||||||
|
if (NetTrace == stdout) {
|
||||||
|
fprintf(NetTrace, "\r\n");
|
||||||
|
} else {
|
||||||
|
fprintf(NetTrace, "\n");
|
||||||
|
}
|
||||||
|
if (length < 0) {
|
||||||
|
fflush(NetTrace);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* find next unique line */
|
||||||
|
}
|
||||||
|
fflush(NetTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
printoption(direction, cmd, option)
|
||||||
|
char *direction;
|
||||||
|
int cmd, option;
|
||||||
|
{
|
||||||
|
if (!showoptions)
|
||||||
|
return;
|
||||||
|
if (cmd == IAC) {
|
||||||
|
if (TELCMD_OK(option))
|
||||||
|
fprintf(NetTrace, "%s IAC %s", direction, TELCMD(option));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%s IAC %d", direction, option);
|
||||||
|
} else {
|
||||||
|
register char *fmt;
|
||||||
|
fmt = (cmd == WILL) ? "WILL" : (cmd == WONT) ? "WONT" :
|
||||||
|
(cmd == DO) ? "DO" : (cmd == DONT) ? "DONT" : 0;
|
||||||
|
if (fmt) {
|
||||||
|
fprintf(NetTrace, "%s %s ", direction, fmt);
|
||||||
|
if (TELOPT_OK(option))
|
||||||
|
fprintf(NetTrace, "%s", TELOPT(option));
|
||||||
|
else if (option == TELOPT_EXOPL)
|
||||||
|
fprintf(NetTrace, "EXOPL");
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%d", option);
|
||||||
|
} else
|
||||||
|
fprintf(NetTrace, "%s %d %d", direction, cmd, option);
|
||||||
|
}
|
||||||
|
if (NetTrace == stdout) {
|
||||||
|
fprintf(NetTrace, "\r\n");
|
||||||
|
fflush(NetTrace);
|
||||||
|
} else {
|
||||||
|
fprintf(NetTrace, "\n");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
optionstatus()
|
||||||
|
{
|
||||||
|
register int i;
|
||||||
|
extern char will_wont_resp[], do_dont_resp[];
|
||||||
|
|
||||||
|
for (i = 0; i < 256; i++) {
|
||||||
|
if (do_dont_resp[i]) {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf("resp DO_DONT %s: %d\n", TELOPT(i), do_dont_resp[i]);
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf("resp DO_DONT %s: %d\n", TELCMD(i), do_dont_resp[i]);
|
||||||
|
else
|
||||||
|
printf("resp DO_DONT %d: %d\n", i,
|
||||||
|
do_dont_resp[i]);
|
||||||
|
if (my_want_state_is_do(i)) {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf("want DO %s\n", TELOPT(i));
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf("want DO %s\n", TELCMD(i));
|
||||||
|
else
|
||||||
|
printf("want DO %d\n", i);
|
||||||
|
} else {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf("want DONT %s\n", TELOPT(i));
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf("want DONT %s\n", TELCMD(i));
|
||||||
|
else
|
||||||
|
printf("want DONT %d\n", i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (my_state_is_do(i)) {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf(" DO %s\n", TELOPT(i));
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf(" DO %s\n", TELCMD(i));
|
||||||
|
else
|
||||||
|
printf(" DO %d\n", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (will_wont_resp[i]) {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf("resp WILL_WONT %s: %d\n", TELOPT(i), will_wont_resp[i]);
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf("resp WILL_WONT %s: %d\n", TELCMD(i), will_wont_resp[i]);
|
||||||
|
else
|
||||||
|
printf("resp WILL_WONT %d: %d\n",
|
||||||
|
i, will_wont_resp[i]);
|
||||||
|
if (my_want_state_is_will(i)) {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf("want WILL %s\n", TELOPT(i));
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf("want WILL %s\n", TELCMD(i));
|
||||||
|
else
|
||||||
|
printf("want WILL %d\n", i);
|
||||||
|
} else {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf("want WONT %s\n", TELOPT(i));
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf("want WONT %s\n", TELCMD(i));
|
||||||
|
else
|
||||||
|
printf("want WONT %d\n", i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (my_state_is_will(i)) {
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
printf(" WILL %s\n", TELOPT(i));
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
printf(" WILL %s\n", TELCMD(i));
|
||||||
|
else
|
||||||
|
printf(" WILL %d\n", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
printsub(direction, pointer, length)
|
||||||
|
char direction; /* '<' or '>' */
|
||||||
|
unsigned char *pointer; /* where suboption data sits */
|
||||||
|
int length; /* length of suboption data */
|
||||||
|
{
|
||||||
|
register int i;
|
||||||
|
char buf[512];
|
||||||
|
extern int want_status_response;
|
||||||
|
|
||||||
|
if (showoptions || direction == 0 ||
|
||||||
|
(want_status_response && (pointer[0] == TELOPT_STATUS))) {
|
||||||
|
if (direction) {
|
||||||
|
fprintf(NetTrace, "%s IAC SB ",
|
||||||
|
(direction == '<')? "RCVD":"SENT");
|
||||||
|
if (length >= 3) {
|
||||||
|
register int j;
|
||||||
|
|
||||||
|
i = pointer[length-2];
|
||||||
|
j = pointer[length-1];
|
||||||
|
|
||||||
|
if (i != IAC || j != SE) {
|
||||||
|
fprintf(NetTrace, "(terminated by ");
|
||||||
|
if (TELOPT_OK(i))
|
||||||
|
fprintf(NetTrace, "%s ", TELOPT(i));
|
||||||
|
else if (TELCMD_OK(i))
|
||||||
|
fprintf(NetTrace, "%s ", TELCMD(i));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%d ", i);
|
||||||
|
if (TELOPT_OK(j))
|
||||||
|
fprintf(NetTrace, "%s", TELOPT(j));
|
||||||
|
else if (TELCMD_OK(j))
|
||||||
|
fprintf(NetTrace, "%s", TELCMD(j));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%d", j);
|
||||||
|
fprintf(NetTrace, ", not IAC SE!) ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
length -= 2;
|
||||||
|
}
|
||||||
|
if (length < 1) {
|
||||||
|
fprintf(NetTrace, "(Empty suboption??\?)");
|
||||||
|
if (NetTrace == stdout)
|
||||||
|
fflush(NetTrace);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (pointer[0]) {
|
||||||
|
case TELOPT_TTYPE:
|
||||||
|
fprintf(NetTrace, "TERMINAL-TYPE ");
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case TELQUAL_IS:
|
||||||
|
fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
|
||||||
|
break;
|
||||||
|
case TELQUAL_SEND:
|
||||||
|
fprintf(NetTrace, "SEND");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(NetTrace,
|
||||||
|
"- unknown qualifier %d (0x%x).",
|
||||||
|
pointer[1], pointer[1]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TELOPT_TSPEED:
|
||||||
|
fprintf(NetTrace, "TERMINAL-SPEED");
|
||||||
|
if (length < 2) {
|
||||||
|
fprintf(NetTrace, " (empty suboption??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case TELQUAL_IS:
|
||||||
|
fprintf(NetTrace, " IS ");
|
||||||
|
fprintf(NetTrace, "%.*s", length-2, (char *)pointer+2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (pointer[1] == 1)
|
||||||
|
fprintf(NetTrace, " SEND");
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, " %d (unknown)", pointer[1]);
|
||||||
|
for (i = 2; i < length; i++)
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELOPT_LFLOW:
|
||||||
|
fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
|
||||||
|
if (length < 2) {
|
||||||
|
fprintf(NetTrace, " (empty suboption??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case LFLOW_OFF:
|
||||||
|
fprintf(NetTrace, " OFF"); break;
|
||||||
|
case LFLOW_ON:
|
||||||
|
fprintf(NetTrace, " ON"); break;
|
||||||
|
case LFLOW_RESTART_ANY:
|
||||||
|
fprintf(NetTrace, " RESTART-ANY"); break;
|
||||||
|
case LFLOW_RESTART_XON:
|
||||||
|
fprintf(NetTrace, " RESTART-XON"); break;
|
||||||
|
default:
|
||||||
|
fprintf(NetTrace, " %d (unknown)", pointer[1]);
|
||||||
|
}
|
||||||
|
for (i = 2; i < length; i++)
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[i]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELOPT_NAWS:
|
||||||
|
fprintf(NetTrace, "NAWS");
|
||||||
|
if (length < 2) {
|
||||||
|
fprintf(NetTrace, " (empty suboption??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (length == 2) {
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(NetTrace, " %d %d (%d)",
|
||||||
|
pointer[1], pointer[2],
|
||||||
|
(int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
|
||||||
|
if (length == 4) {
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[3]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(NetTrace, " %d %d (%d)",
|
||||||
|
pointer[3], pointer[4],
|
||||||
|
(int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
|
||||||
|
for (i = 5; i < length; i++)
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[i]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
#if defined(AUTHENTICATION)
|
||||||
|
case TELOPT_AUTHENTICATION:
|
||||||
|
fprintf(NetTrace, "AUTHENTICATION");
|
||||||
|
if (length < 2) {
|
||||||
|
fprintf(NetTrace, " (empty suboption??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case TELQUAL_REPLY:
|
||||||
|
case TELQUAL_IS:
|
||||||
|
fprintf(NetTrace, " %s ", (pointer[1] == TELQUAL_IS) ?
|
||||||
|
"IS" : "REPLY");
|
||||||
|
if (AUTHTYPE_NAME_OK(pointer[2]))
|
||||||
|
fprintf(NetTrace, "%s ", AUTHTYPE_NAME(pointer[2]));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%d ", pointer[2]);
|
||||||
|
if (length < 3) {
|
||||||
|
fprintf(NetTrace, "(partial suboption??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(NetTrace, "%s|%s",
|
||||||
|
((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
|
||||||
|
"CLIENT" : "SERVER",
|
||||||
|
((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
|
||||||
|
"MUTUAL" : "ONE-WAY");
|
||||||
|
|
||||||
|
auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));
|
||||||
|
fprintf(NetTrace, "%s", buf);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELQUAL_SEND:
|
||||||
|
i = 2;
|
||||||
|
fprintf(NetTrace, " SEND ");
|
||||||
|
while (i < length) {
|
||||||
|
if (AUTHTYPE_NAME_OK(pointer[i]))
|
||||||
|
fprintf(NetTrace, "%s ", AUTHTYPE_NAME(pointer[i]));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%d ", pointer[i]);
|
||||||
|
if (++i >= length) {
|
||||||
|
fprintf(NetTrace, "(partial suboption??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(NetTrace, "%s|%s ",
|
||||||
|
((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
|
||||||
|
"CLIENT" : "SERVER",
|
||||||
|
((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
|
||||||
|
"MUTUAL" : "ONE-WAY");
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELQUAL_NAME:
|
||||||
|
i = 2;
|
||||||
|
fprintf(NetTrace, " NAME \"");
|
||||||
|
while (i < length)
|
||||||
|
putc(pointer[i++], NetTrace);
|
||||||
|
putc('"', NetTrace);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
for (i = 2; i < length; i++)
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ENCRYPTION)
|
||||||
|
case TELOPT_ENCRYPT:
|
||||||
|
fprintf(NetTrace, "ENCRYPT");
|
||||||
|
if (length < 2) {
|
||||||
|
fprintf(NetTrace, " (empty suboption?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case ENCRYPT_START:
|
||||||
|
fprintf(NetTrace, " START");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENCRYPT_END:
|
||||||
|
fprintf(NetTrace, " END");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENCRYPT_REQSTART:
|
||||||
|
fprintf(NetTrace, " REQUEST-START");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENCRYPT_REQEND:
|
||||||
|
fprintf(NetTrace, " REQUEST-END");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENCRYPT_IS:
|
||||||
|
case ENCRYPT_REPLY:
|
||||||
|
fprintf(NetTrace, " %s ", (pointer[1] == ENCRYPT_IS) ?
|
||||||
|
"IS" : "REPLY");
|
||||||
|
if (length < 3) {
|
||||||
|
fprintf(NetTrace, " (partial suboption?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ENCTYPE_NAME_OK(pointer[2]))
|
||||||
|
fprintf(NetTrace, "%s ", ENCTYPE_NAME(pointer[2]));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, " %d (unknown)", pointer[2]);
|
||||||
|
|
||||||
|
encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));
|
||||||
|
fprintf(NetTrace, "%s", buf);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENCRYPT_SUPPORT:
|
||||||
|
i = 2;
|
||||||
|
fprintf(NetTrace, " SUPPORT ");
|
||||||
|
while (i < length) {
|
||||||
|
if (ENCTYPE_NAME_OK(pointer[i]))
|
||||||
|
fprintf(NetTrace, "%s ", ENCTYPE_NAME(pointer[i]));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%d ", pointer[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENCRYPT_ENC_KEYID:
|
||||||
|
fprintf(NetTrace, " ENC_KEYID ");
|
||||||
|
goto encommon;
|
||||||
|
|
||||||
|
case ENCRYPT_DEC_KEYID:
|
||||||
|
fprintf(NetTrace, " DEC_KEYID ");
|
||||||
|
goto encommon;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(NetTrace, " %d (unknown)", pointer[1]);
|
||||||
|
encommon:
|
||||||
|
for (i = 2; i < length; i++)
|
||||||
|
fprintf(NetTrace, " %d", pointer[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case TELOPT_LINEMODE:
|
||||||
|
fprintf(NetTrace, "LINEMODE ");
|
||||||
|
if (length < 2) {
|
||||||
|
fprintf(NetTrace, " (empty suboption??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case WILL:
|
||||||
|
fprintf(NetTrace, "WILL ");
|
||||||
|
goto common;
|
||||||
|
case WONT:
|
||||||
|
fprintf(NetTrace, "WONT ");
|
||||||
|
goto common;
|
||||||
|
case DO:
|
||||||
|
fprintf(NetTrace, "DO ");
|
||||||
|
goto common;
|
||||||
|
case DONT:
|
||||||
|
fprintf(NetTrace, "DONT ");
|
||||||
|
common:
|
||||||
|
if (length < 3) {
|
||||||
|
fprintf(NetTrace, "(no option??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (pointer[2]) {
|
||||||
|
case LM_FORWARDMASK:
|
||||||
|
fprintf(NetTrace, "Forward Mask");
|
||||||
|
for (i = 3; i < length; i++)
|
||||||
|
fprintf(NetTrace, " %x", pointer[i]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(NetTrace, "%d (unknown)", pointer[2]);
|
||||||
|
for (i = 3; i < length; i++)
|
||||||
|
fprintf(NetTrace, " %d", pointer[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LM_SLC:
|
||||||
|
fprintf(NetTrace, "SLC");
|
||||||
|
for (i = 2; i < length - 2; i += 3) {
|
||||||
|
if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
|
||||||
|
fprintf(NetTrace, " %s", SLC_NAME(pointer[i+SLC_FUNC]));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, " %d", pointer[i+SLC_FUNC]);
|
||||||
|
switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
|
||||||
|
case SLC_NOSUPPORT:
|
||||||
|
fprintf(NetTrace, " NOSUPPORT"); break;
|
||||||
|
case SLC_CANTCHANGE:
|
||||||
|
fprintf(NetTrace, " CANTCHANGE"); break;
|
||||||
|
case SLC_VARIABLE:
|
||||||
|
fprintf(NetTrace, " VARIABLE"); break;
|
||||||
|
case SLC_DEFAULT:
|
||||||
|
fprintf(NetTrace, " DEFAULT"); break;
|
||||||
|
}
|
||||||
|
fprintf(NetTrace, "%s%s%s",
|
||||||
|
pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
|
||||||
|
pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
|
||||||
|
pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
|
||||||
|
if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
|
||||||
|
SLC_FLUSHOUT| SLC_LEVELBITS))
|
||||||
|
fprintf(NetTrace, "(0x%x)", pointer[i+SLC_FLAGS]);
|
||||||
|
fprintf(NetTrace, " %d;", pointer[i+SLC_VALUE]);
|
||||||
|
if ((pointer[i+SLC_VALUE] == IAC) &&
|
||||||
|
(pointer[i+SLC_VALUE+1] == IAC))
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
for (; i < length; i++)
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[i]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LM_MODE:
|
||||||
|
fprintf(NetTrace, "MODE ");
|
||||||
|
if (length < 3) {
|
||||||
|
fprintf(NetTrace, "(no mode??\?)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
char tbuf[64];
|
||||||
|
sprintf(tbuf, "%s%s%s%s%s",
|
||||||
|
pointer[2]&MODE_EDIT ? "|EDIT" : "",
|
||||||
|
pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
|
||||||
|
pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
|
||||||
|
pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
|
||||||
|
pointer[2]&MODE_ACK ? "|ACK" : "");
|
||||||
|
fprintf(NetTrace, "%s", tbuf[1] ? &tbuf[1] : "0");
|
||||||
|
}
|
||||||
|
if (pointer[2]&~(MODE_MASK))
|
||||||
|
fprintf(NetTrace, " (0x%x)", pointer[2]);
|
||||||
|
for (i = 3; i < length; i++)
|
||||||
|
fprintf(NetTrace, " ?0x%x?", pointer[i]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(NetTrace, "%d (unknown)", pointer[1]);
|
||||||
|
for (i = 2; i < length; i++)
|
||||||
|
fprintf(NetTrace, " %d", pointer[i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELOPT_STATUS: {
|
||||||
|
register char *cp;
|
||||||
|
register int j, k;
|
||||||
|
|
||||||
|
fprintf(NetTrace, "STATUS");
|
||||||
|
|
||||||
|
switch (pointer[1]) {
|
||||||
|
default:
|
||||||
|
if (pointer[1] == TELQUAL_SEND)
|
||||||
|
fprintf(NetTrace, " SEND");
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, " %d (unknown)", pointer[1]);
|
||||||
|
for (i = 2; i < length; i++)
|
||||||
|
fprintf(NetTrace, " ?%d?", pointer[i]);
|
||||||
|
break;
|
||||||
|
case TELQUAL_IS:
|
||||||
|
if (--want_status_response < 0)
|
||||||
|
want_status_response = 0;
|
||||||
|
if (NetTrace == stdout)
|
||||||
|
fprintf(NetTrace, " IS\r\n");
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, " IS\n");
|
||||||
|
|
||||||
|
for (i = 2; i < length; i++) {
|
||||||
|
switch(pointer[i]) {
|
||||||
|
case DO: cp = "DO"; goto common2;
|
||||||
|
case DONT: cp = "DONT"; goto common2;
|
||||||
|
case WILL: cp = "WILL"; goto common2;
|
||||||
|
case WONT: cp = "WONT"; goto common2;
|
||||||
|
common2:
|
||||||
|
i++;
|
||||||
|
if (TELOPT_OK((int)pointer[i]))
|
||||||
|
fprintf(NetTrace, " %s %s", cp, TELOPT(pointer[i]));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, " %s %d", cp, pointer[i]);
|
||||||
|
|
||||||
|
if (NetTrace == stdout)
|
||||||
|
fprintf(NetTrace, "\r\n");
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SB:
|
||||||
|
fprintf(NetTrace, " SB ");
|
||||||
|
i++;
|
||||||
|
j = k = i;
|
||||||
|
while (j < length) {
|
||||||
|
if (pointer[j] == SE) {
|
||||||
|
if (j+1 == length)
|
||||||
|
break;
|
||||||
|
if (pointer[j+1] == SE)
|
||||||
|
j++;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pointer[k++] = pointer[j++];
|
||||||
|
}
|
||||||
|
printsub(0, &pointer[i], k - i);
|
||||||
|
if (i < length) {
|
||||||
|
fprintf(NetTrace, " SE");
|
||||||
|
i = j;
|
||||||
|
} else
|
||||||
|
i = j - 1;
|
||||||
|
|
||||||
|
if (NetTrace == stdout)
|
||||||
|
fprintf(NetTrace, "\r\n");
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "\n");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
fprintf(NetTrace, " %d", pointer[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TELOPT_XDISPLOC:
|
||||||
|
fprintf(NetTrace, "X-DISPLAY-LOCATION ");
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case TELQUAL_IS:
|
||||||
|
fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
|
||||||
|
break;
|
||||||
|
case TELQUAL_SEND:
|
||||||
|
fprintf(NetTrace, "SEND");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(NetTrace, "- unknown qualifier %d (0x%x).",
|
||||||
|
pointer[1], pointer[1]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELOPT_NEW_ENVIRON:
|
||||||
|
fprintf(NetTrace, "NEW-ENVIRON ");
|
||||||
|
#ifdef OLD_ENVIRON
|
||||||
|
goto env_common1;
|
||||||
|
case TELOPT_OLD_ENVIRON:
|
||||||
|
fprintf(NetTrace, "OLD-ENVIRON");
|
||||||
|
env_common1:
|
||||||
|
#endif
|
||||||
|
switch (pointer[1]) {
|
||||||
|
case TELQUAL_IS:
|
||||||
|
fprintf(NetTrace, "IS ");
|
||||||
|
goto env_common;
|
||||||
|
case TELQUAL_SEND:
|
||||||
|
fprintf(NetTrace, "SEND ");
|
||||||
|
goto env_common;
|
||||||
|
case TELQUAL_INFO:
|
||||||
|
fprintf(NetTrace, "INFO ");
|
||||||
|
env_common:
|
||||||
|
{
|
||||||
|
register int noquote = 2;
|
||||||
|
#if defined(ENV_HACK) && defined(OLD_ENVIRON)
|
||||||
|
extern int old_env_var, old_env_value;
|
||||||
|
#endif
|
||||||
|
for (i = 2; i < length; i++ ) {
|
||||||
|
switch (pointer[i]) {
|
||||||
|
case NEW_ENV_VALUE:
|
||||||
|
#ifdef OLD_ENVIRON
|
||||||
|
/* case NEW_ENV_OVAR: */
|
||||||
|
if (pointer[0] == TELOPT_OLD_ENVIRON) {
|
||||||
|
# ifdef ENV_HACK
|
||||||
|
if (old_env_var == OLD_ENV_VALUE)
|
||||||
|
fprintf(NetTrace, "\" (VALUE) " + noquote);
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
fprintf(NetTrace, "\" VAR " + noquote);
|
||||||
|
} else
|
||||||
|
#endif /* OLD_ENVIRON */
|
||||||
|
fprintf(NetTrace, "\" VALUE " + noquote);
|
||||||
|
noquote = 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NEW_ENV_VAR:
|
||||||
|
#ifdef OLD_ENVIRON
|
||||||
|
/* case OLD_ENV_VALUE: */
|
||||||
|
if (pointer[0] == TELOPT_OLD_ENVIRON) {
|
||||||
|
# ifdef ENV_HACK
|
||||||
|
if (old_env_value == OLD_ENV_VAR)
|
||||||
|
fprintf(NetTrace, "\" (VAR) " + noquote);
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
fprintf(NetTrace, "\" VALUE " + noquote);
|
||||||
|
} else
|
||||||
|
#endif /* OLD_ENVIRON */
|
||||||
|
fprintf(NetTrace, "\" VAR " + noquote);
|
||||||
|
noquote = 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENV_ESC:
|
||||||
|
fprintf(NetTrace, "\" ESC " + noquote);
|
||||||
|
noquote = 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENV_USERVAR:
|
||||||
|
fprintf(NetTrace, "\" USERVAR " + noquote);
|
||||||
|
noquote = 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
def_case:
|
||||||
|
if (isprint(pointer[i]) && pointer[i] != '"') {
|
||||||
|
if (noquote) {
|
||||||
|
putc('"', NetTrace);
|
||||||
|
noquote = 0;
|
||||||
|
}
|
||||||
|
putc(pointer[i], NetTrace);
|
||||||
|
} else {
|
||||||
|
fprintf(NetTrace, "\" %03o " + noquote,
|
||||||
|
pointer[i]);
|
||||||
|
noquote = 2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!noquote)
|
||||||
|
putc('"', NetTrace);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (TELOPT_OK(pointer[0]))
|
||||||
|
fprintf(NetTrace, "%s (unknown)", TELOPT(pointer[0]));
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "%d (unknown)", pointer[0]);
|
||||||
|
for (i = 1; i < length; i++)
|
||||||
|
fprintf(NetTrace, " %d", pointer[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (direction) {
|
||||||
|
if (NetTrace == stdout)
|
||||||
|
fprintf(NetTrace, "\r\n");
|
||||||
|
else
|
||||||
|
fprintf(NetTrace, "\n");
|
||||||
|
}
|
||||||
|
if (NetTrace == stdout)
|
||||||
|
fflush(NetTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* EmptyTerminal - called to make sure that the terminal buffer is empty.
|
||||||
|
* Note that we consider the buffer to run all the
|
||||||
|
* way to the kernel (thus the select).
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
EmptyTerminal()
|
||||||
|
{
|
||||||
|
#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()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
{
|
||||||
|
SetForExit();
|
||||||
|
exit(returnCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ExitString(string, returnCode)
|
||||||
|
char *string;
|
||||||
|
int returnCode;
|
||||||
|
{
|
||||||
|
SetForExit();
|
||||||
|
fwrite(string, 1, strlen(string), stderr);
|
||||||
|
exit(returnCode);
|
||||||
|
}
|
Reference in New Issue
Block a user