gote

package module
v0.0.0-...-1405769 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

README

GOTE (go-telnet)

Build Status Go Report Card

GoDoc Go Walker

A net.Conn compatible implementation with telnet support.

This is a drop-in replacement for net.Dial that handles telnet negotiaton and other out-of-band messages transparently.

It currently refuses and/or disables all options in a sane manner, except for binary transmission. It disables the Go-Ahead and and ECHO options as well.

Further work needs to be done to implement other telnet options. This is planned, however I have little motivation to do so at the moment.

Current version requires Go1.8 to utilize the os specific writev functions.

Documentation

Overview

Package gote (go-telnet) provides a net.Conn compatible interface for connection to telnet servers that require telnet option negotiation. Behavior mimics net.Conn behavior wherever possible, exceptions noted.

Index

Examples

Constants

View Source
const (
	IAC  = byte(255)
	DONT = byte(254)
	DO   = byte(253)
	WONT = byte(252)
	WILL = byte(251)
	SB   = byte(250) // Sub Negotiation
	GA   = byte(249) // Go Ahead
	EL   = byte(248) // Erase Line
	EC   = byte(247) // Erase Character
	AYT  = byte(246) // Are You There
	AO   = byte(245) // Abort Operation
	IP   = byte(244) // Interrupt Process
	BRK  = byte(243) // Break
	NOP  = byte(241) // No operation
	SE   = byte(240) // End of Subnegotiation
)

Commands

View Source
const (
	BIN  = byte(0) // Binary Transmission
	ECHO = byte(1)
	REC  = byte(2)  // Reconnect
	SGA  = byte(3)  // Suppress Go Ahead
	LOG  = byte(18) // Logout
	TSP  = byte(32) // Terminal Speed
	RFC  = byte(33) // Remote Flow Control
)

Options

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	// Read the data sent from the server after being processed
	// for telnet options.
	Read(b []byte) (n int, err error)
	// Write the byte buffer to the output stream. Escaping 255 bytes is done
	// automatically, so is not required by the caller. Note that the written
	// count may be off due to the 255 byte escaping.
	Write(b []byte) (n int, err error)
	// Close the connection
	// This is a pass-through method to the underlying net.conn
	// without any processing.
	Close() error
	// LocalAddr returns the LocalAddress of this connection.
	// This is a pass-through method to the underlying net.conn
	// without any processing.
	LocalAddr() net.Addr
	// RemoteAddr returns the RemoteAddress of this connection.
	// This is a pass-through method to the underlying net.conn
	// without any processing.
	RemoteAddr() net.Addr
	// SetDeadline is a pass-through method to the underlying net.conn
	// without any processing.
	SetDeadline(t time.Time) error
	// SetReadDeadline is a pass-through method to the underlying net.conn
	// without any processing.
	SetReadDeadline(t time.Time) error
	// SetWriteDeadline is a pass-through method to the underlying net.conn
	// without any processing.
	SetWriteDeadline(t time.Time) error
}

Connection is a telnet interface which implements net.conn, along with some proposed extended functionality for handling telnet options.

func Dial

func Dial(network, address string) (Connection, error)

Dial connects to a TCP endpoint and returns a Telnet Connection object, which transparently handles telnet options and escaping.

Example
// Dial the telnet server
conn, err := gote.Dial("tcp", "rainmaker.wunderground.com")
if err != nil {
	panic("Unable to connect.")
}
// Read 30 bytes from the stream
buf := make([]byte, 30)
_, err = conn.Read(buf)
if err != nil {
	panic("Unable to read from stream.")
}

// Write 'Hello World' to the stream.
_, err = conn.Write([]byte("Hello world!"))
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL