/* * Send the window size to the server via the magic escape. * Note: SIGWINCH should be blocked when this is called, lest * winsize change underneath us and chaos result. */ static void sendwindow(void) { char obuf[4 + sizeof (struct winsize)]; struct winsize *wp = (struct winsize *)(void *)(obuf+4); obuf[0] = -1; obuf[1] = -1; obuf[2] = 's'; obuf[3] = 's'; wp->ws_row = htons(winsize.ws_row); wp->ws_col = htons(winsize.ws_col); wp->ws_xpixel = htons(winsize.ws_xpixel); wp->ws_ypixel = htons(winsize.ws_ypixel); if (deswrite(rem, obuf, sizeof (obuf), 0) < 0) prf(gettext("Write error to network: %s"), strerror(errno)); }
static int desrshwrite(int fd, char *buf, int len) { return (deswrite(fd, buf, len, writeiv ? 1 : 0)); }
/* * writer: write to remote: 0 -> line. * ~. terminate * ~^Z suspend rlogin process. * ~^Y suspend rlogin process, but leave reader alone. */ static void writer(void) { char c; int n; boolean_t bol = B_TRUE; /* beginning of line */ boolean_t local = B_FALSE; for (;;) { n = read(STDIN_FILENO, &c, 1); if (n <= 0) { if (n == 0) break; if (errno == EINTR) continue; else { prf(gettext("Read error from terminal: %s"), strerror(errno)); break; } } /* * If we're at the beginning of the line * and recognize a command character, then * we echo locally. Otherwise, characters * are echo'd remotely. If the command * character is doubled, this acts as a * force and local echo is suppressed. */ if (bol && !nocmdchar) { bol = B_FALSE; if (c == cmdchar) { local = B_TRUE; continue; } } else if (local) { local = B_FALSE; if (c == '.' || c == deftc.t_eofc) { echo(c); break; } if (c == defltc.t_suspc || c == defltc.t_dsuspc) { bol = B_TRUE; echo(c); stop(c); continue; } if (c != cmdchar) { if (deswrite(rem, &cmdchar, 1, 0) < 0) { prf(gettext( "Write error to network: %s"), strerror(errno)); break; } } } if ((n = deswrite(rem, &c, 1, 0)) <= 0) { if (n == 0) prf(gettext("line gone")); else prf(gettext("Write error to network: %s"), strerror(errno)); break; } bol = c == defkill || c == deftc.t_eofc || c == deftc.t_intrc || c == defltc.t_suspc || c == '\r' || c == '\n'; } }