From eddc39723a846554de2b4e24fd30cef4caf04ff3 Mon Sep 17 00:00:00 2001 From: "Matthew R. Wilson" Date: Sat, 26 Dec 2020 01:42:53 -0800 Subject: [PATCH] Add UnNegotiateTelnet() function --- telnet.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/telnet.go b/telnet.go index e9bfde9..957fa3b 100644 --- a/telnet.go +++ b/telnet.go @@ -35,6 +35,18 @@ func NegotiateTelnet(conn net.Conn) error { return nil } +// UnNegotiateTelnet will naively (e.g. not checking client responses) attempt +// to restore the telnet options state to what it was before NegotiateTelnet() +// was called. +func UnNegotiateTelnet(conn net.Conn, timeout time.Duration) error { + conn.Write([]byte{iac, wont, eor, iac, wont, binary}) + conn.Write([]byte{iac, dont, binary}) + conn.Write([]byte{iac, dont, eor}) + conn.Write([]byte{iac, dont, terminalType}) + flushConnection(conn, timeout) + return nil +} + // flushConnection discards all bytes that it can read from conn, allowing up // to the duration timeout for the first byte to be read. func flushConnection(conn net.Conn, timeout time.Duration) error {