From 0f4e951657c2fc79a49d741a9cb03bf865543bbd Mon Sep 17 00:00:00 2001 From: tobez Date: Mon, 28 Feb 2005 12:46:53 +0000 Subject: [PATCH] Increase usefulness of telnet(1) as a protocol tester. By prepending "+" to the port number, disable option negotiation and allow transferring of data with high bit set. OKed by: markm (maintainer) PR: 52032 Submitted by: Valentin Nechayev MFC After: 2 weeks git-svn-id: http://svn0.us-east.freebsd.org/base/head/contrib/telnet@142790 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- telnet/commands.c | 3 +++ telnet/telnet.1 | 12 ++++++++++-- telnet/telnet.c | 12 ++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/telnet/commands.c b/telnet/commands.c index a8a3a44..a64d763 100644 --- a/telnet/commands.c +++ b/telnet/commands.c @@ -2299,6 +2299,9 @@ tn(int argc, char *argv[]) } else if (*portp == '-') { portp++; telnetport = 1; + } else if (*portp == '+') { + portp++; + telnetport = -1; } else telnetport = 0; diff --git a/telnet/telnet.1 b/telnet/telnet.1 index 06a9274..2e0181c 100644 --- a/telnet/telnet.1 +++ b/telnet/telnet.1 @@ -591,9 +591,10 @@ Prints out help information for the command. .El .It Xo -.Ic open Ar host +.Ic open .Op Fl l Ar user -.Op Oo Fl Oc Ns Ar port +.Op Ar host +.Op Oo Fl /+ Oc Ns Ar port .Xc Open a connection to the named host. If no port number @@ -620,6 +621,13 @@ omits any automatic initiation of options. When the port number is preceded by a minus sign, the initial option negotiation is done. +When, however, the port number +is preceded by a plus sign, +any option negotiation and understanding is prohibited, +making telnet dumb client for POP3/SMTP/NNTP/HTTP-like +protocols with any data including +.Tn TELNET +IAC character (0xff). After establishing a connection, the file .Pa \&.telnetrc in the diff --git a/telnet/telnet.c b/telnet/telnet.c index 82ee464..692fb49 100644 --- a/telnet/telnet.c +++ b/telnet/telnet.c @@ -217,6 +217,8 @@ send_do(int c, int init) set_my_want_state_do(c); do_dont_resp[c]++; } + if (telnetport < 0) + return; NET2ADD(IAC, DO); NETADD(c); printoption("SENT", DO, c); @@ -232,6 +234,8 @@ send_dont(int c, int init) set_my_want_state_dont(c); do_dont_resp[c]++; } + if (telnetport < 0) + return; NET2ADD(IAC, DONT); NETADD(c); printoption("SENT", DONT, c); @@ -247,6 +251,8 @@ send_will(int c, int init) set_my_want_state_will(c); will_wont_resp[c]++; } + if (telnetport < 0) + return; NET2ADD(IAC, WILL); NETADD(c); printoption("SENT", WILL, c); @@ -262,6 +268,8 @@ send_wont(int c, int init) set_my_want_state_wont(c); will_wont_resp[c]++; } + if (telnetport < 0) + return; NET2ADD(IAC, WONT); NETADD(c); printoption("SENT", WONT, c); @@ -1651,7 +1659,7 @@ telrcv(void) /* FALLTHROUGH */ case TS_DATA: - if (c == IAC) { + if (c == IAC && telnetport >= 0) { telrcv_state = TS_IAC; break; } @@ -2069,7 +2077,7 @@ telnet(char *user __unusedhere) } #endif #endif - if (telnetport) { + if (telnetport > 0) { #ifdef AUTHENTICATION if (autologin) send_will(TELOPT_AUTHENTICATION, 1);