-/*
- * Check to see if any out-of-band data exists on a socket (for
- * Telnet "synch" processing).
- */
-
-int
-stilloob(s)
-int s; /* socket number */
-{
- static struct timeval timeout = { 0 };
- fd_set excepts;
- int value;
-
- do {
- FD_ZERO(&excepts);
- FD_SET(s, &excepts);
- value = select(s+1, 0, 0, &excepts, &timeout);
- } while ((value >= 0) || ((value == -1) && (errno = EINTR)));
-
- if (value < 0) {
- perror("select");
- quit();
- }
- if (FD_ISSET(s, &excepts)) {
- return 1;
- } else {
- return 0;
- }
-}
-
-/*
- * Construct a control character sequence
- * for a special character.
- */
-char *
-control(c)
- register int c;
-{
- static char buf[3];
-
- if (c == 0177)
- return ("^?");
- if (c >= 040) {
- buf[0] = c;
- buf[1] = 0;
- } else {
- buf[0] = '^';
- buf[1] = '@'+c;
- buf[2] = 0;
- }
- return (buf);
-}
-
-ttyflush()
-{
- int n;
-
- if ((n = tfrontp - tbackp) > 0) {
- if (!flushing) {
- n = write(tout, tbackp, n);
- } else {
- ioctl(fileno(stdout), TIOCFLUSH, 0);
- }
- }
- if (n < 0) {
- return;
- }
- tbackp += n;
- if (tbackp == tfrontp) {
- tbackp = tfrontp = ttyobuf;
- }
-}
-
-netflush(fd)
-{
- int n;
-
- if ((n = nfrontp - nbackp) > 0) {
- if (!neturg) {
- n = write(fd, nbackp, n); /* normal write */
- } else {
- n = neturg - nbackp;
- /*
- * 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).
- */
- if (n > 1) {
- n = send(fd, nbackp, n-1, 0); /* send URGENT all by itself */
- } else {
- n = send(fd, nbackp, n, MSG_OOB); /* URGENT data */
- }
- }
- }
- if (n < 0) {
- if (errno != ENOBUFS && errno != EWOULDBLOCK) {
- setcommandmode();
- perror(hostname);
- close(fd);
- neturg = 0;
- longjmp(peerdied, -1);
- /*NOTREACHED*/
- }
- n = 0;
- }
- if (netdata && n) {
- Dump('>', nbackp, n);
- }
- nbackp += n;
- if (nbackp >= neturg) {
- neturg = 0;
- }
- if (nbackp == nfrontp) {
- nbackp = nfrontp = netobuf;
- }
-}
-
-static
-Dump(direction, buffer, length)
-char direction;
-char *buffer;
-int length;
-{
-# define BYTES_PER_LINE 32
-# define min(x,y) ((x<y)? x:y)
- char *pThis;
- int offset;
-
- offset = 0;
-
- while (length) {
- /* print one line */
- fprintf(NetTrace, "%c 0x%x\t", direction, offset);
- pThis = buffer;
- buffer = buffer+min(length, BYTES_PER_LINE);
- while (pThis < buffer) {
- fprintf(NetTrace, "%.2x", (*pThis)&0xff);
- pThis++;
- }
- fprintf(NetTrace, "\n");
- length -= BYTES_PER_LINE;
- offset += BYTES_PER_LINE;
- if (length < 0) {
- return;
- }
- /* find next unique line */
- }
-}
-
-
-/*VARARGS*/
-printoption(direction, fmt, option, what)
- char *direction, *fmt;
- int option, what;
-{
- if (!showoptions)
- return;
- printf("%s ", direction);
- if (fmt == doopt)
- fmt = "do";
- else if (fmt == dont)
- fmt = "dont";
- else if (fmt == will)
- fmt = "will";
- else if (fmt == wont)
- fmt = "wont";
- else
- fmt = "???";
- if (option < TELOPT_SUPDUP)
- printf("%s %s", fmt, telopts[option]);
- else
- printf("%s %d", fmt, option);
- if (*direction == '<') {
- printf("\r\n");
- return;
- }
- printf(" (%s)\r\n", what ? "reply" : "don't reply");
-}
-\f