telnet.v1: maze.io/x/telnet.v1 Index | Files | Directories

package telnet

import "maze.io/x/telnet.v1"

Package telnet implements the telnet protocol.

Index

Package Files

buffer.go client.go conn.go console.go console_linux.go console_unix.go lineflow.go negotiate.go prompt.go server.go server_terminal.go stream.go telnet.go terminal.go

Constants

const (
    LFLOW_OFF byte = iota
    LFLOW_ON
    LFLOW_RESTART_ANY
    LFLOW_RESTART_XON
)
const (
    BINARY              byte = iota // 8-bit data path
    ECHO                            // Echo
    RCP                             // Prepare to reconnect
    SGA                             // Suppress Go Ahead
    NAMS                            // Approximate Message Size
    STATUS                          // Status
    TM                              // Timing Mark
    RCTE                            // Remote Controlled Transmission and Echo
    NAOL                            // Negotiate About Output Line (width)
    NAOP                            // Negotiate About Output Page (size)
    NAOCRD                          // Negotiate About CR Disposition
    NAOHTS                          // Negotiate About Horizontal Tabstops
    NAOHTD                          // Negotiate About Horizontal Tab Disposition
    NAOFFD                          // Negotiate About Formfeed Disposition
    NAOVTS                          // Negotiate About Vertical Tabstops
    NAOVTD                          // Negotiate About Vertial Tab Disposition
    NAOLFD                          // Negotiate About Output LF Disposition
    XASCII                          // Extended ASCII character set
    LOGOUT                          // Force logout
    BM                              // Byte Macro
    DET                             // Data Entry Terminal
    SUPDUP                          // Supdup protocol
    SUPDUPOUTPUT                    // Supdup output
    SNDLOC                          // Send Location
    TTYPE                           // Terminal Type
    EOR                             // End Of Record
    TUID                            // TACAS User Identification
    VT3270REGIME                    // vt3270 regime
    X3PAD                           // X.3 Pad
    NAWS                            // Window Size
    TSPEED                          // Terminal Speed
    LFLOW                           // Remote Flow Control
    LINEMODE                        // Linemode option
    XDISPLOC                        // X Display Location
    ENVIRON                         // Environment Variables
    AUTHENTICATION                  // Authenticate
    ENCRYPT                         // Encrypt
    NEW_ENVIRON                     // Environment Variables (new)
    TN3270E                         // TN3270E
    XAUTH                           // XAuth
    CHARSET                         // Character set
    RSP                             // Remote Serial Port
    COM_PORT_OPTION                 // COM Port Control Option
    SUPPRESS_LOCAL_ECHO             // Telnet Suppress Local Echo
    TLS                             // Telnet StartTLS
    KERMIT                          // Kermit
    SEND_URL                        // Send URL
    FORWARD_X                       // Forward X
    MSDP                byte = 69
    MSSP                byte = 70
    COMPRESS            byte = 85
    COMPRESS2           byte = 86
    MSP                 byte = 90
    MXP                 byte = 91
    MSP2                byte = 92
    ZMP                 byte = 93
)

Telnet protocol options (arpa/telnet.h)

const (
    PRAGMA_LOGON     byte = iota + 138 // Telopt Pragma Logon
    SSPI_LOGON                         // Telopt SSPI Logon
    PRAGMA_HEARTBEAT                   // Telopt Pragma Heartbeat
)
const (
    EOF     byte = iota + 236 // End Of File
    SUSP                      // Suspend
    ABORT                     // Abort
    CMD_EOR                   // End Of Record
    SE                        // Sub-negotiation End
    NOP                       // No-Operation
    DM                        // Data Mark
    BRK                       // Break
    IP                        // Interrupt Process
    AO                        // Abort Output
    AYT                       // Are You There?
    EC                        // Erase Character
    EL                        // Erase Line
    GA                        // Go Ahead
    SB                        // Sub-negotiation Begin
    WILL                      // Will
    WONT                      // Wont
    DO                        // Do
    DONT                      // Dont
    IAC                       // Interpret as Command
)
const (
    TTYPE_IS byte = iota
    TTYPE_SEND
)

TTYPE bytes

const (
    MTTS_ANSI byte = 1 << iota
    MTTS_VT100
    MTTS_UTF8
    MTTS_256_COLORS
    MTTS_MOUSE_TRACKING
    MTTS_OSC_COLOR_PALETTE
    MTTS_SCREEN_READER
    MTTS_PROXY
)

MTTS bytes

const (
    MSSP_VAR byte = 1 + iota
    MSSP_VAL
)

MSSP bytes

const (
    MSDP_VAR byte = 1 + iota
    MSDP_VAL
    MSDP_TABLE_OPEN
    MSDP_TABLE_CLOSE
    MSDP_ARRAY_OPEN
    MSDP_ARRAY_CLOSE
)

MSDP values

const (
    IS  byte = iota
    SEND
    INFO
)

Environment commands (rfc1572)

const (
    VAR byte = iota
    VALUE
    ESC
    USERVAR
)

Environment values (rfc1572)

const (
    REQUEST byte = 1 + iota
    ACCEPTED
    REJECTED
    TTABLE_IS
    TTABLE_REJECTED
    TTABLE_ACK
    TTABLE_NAK
)

Charset commands ()

const NULL byte = 0

NULL is the NULL byte.

Variables

var (
    // DefaultServerOption is a map of telnet options negotiated by a default server.
    DefaultServerOption = map[byte]bool{
        SGA:         true,
        TSPEED:      true,
        TTYPE:       true,
        NAWS:        true,
        NEW_ENVIRON: true,
    }
    DefaultNegotiationTimeout = time.Second * 10
)
var (
    ErrTimeout      = errors.New("telnet: timeout")
    ErrNotConnected = errors.New("telnet: not connected")
    ErrNotSupported = notSupported(true)
)

Common errors

var (
    // DefaultEnvironmentRequest are the default environment variable being requested.
    DefaultEnvironmentRequest = []string{
        "USER", "HOSTNAME", "UID", "TERM", "COLUMNS", "LINES", "DISPLAY", "LANG", "SYSTEMTYPE",
        "ACCT", "JOB", "PRINTER", "SFUTLNTVER", "SFUTLNTMODE", "LC_ALL", "VISUAL", "EDITOR",
        "LC_COLLATE", "LC_CTYPE", "LC_MESSAGES", "LC_MONETARY", "LC_NUMERIC", "LC_TIME",
    }
)

func IsNotSupported Uses

func IsNotSupported(err error) bool

IsNotSupported checks if the error is a not-supported error.

func Prompt Uses

func Prompt(term Terminal, format string) string

Prompt resolves a prompt with format.

'%%'       A single '%'.
'%#'       Prompt character.
'%u'       Username.
'%h'       Hostname.
'%H'       Full hostname.
'%i'       Terminal type.
'%?'       Return code last command processed.
'%E'       Encoding of session.
'%s'       Name of shell.
'%v'       Version of shell.
'%t'       Time of day in 12-hour AM/PM format.
'%T'       Time of day in 24-hour format.
'%p'       Time of day in 12-hour format with seconds, AM/PM format.
'%P'       Time of day in 24-hour format with seconds.
'%d        The weekday in `Day' format.
'%D'       The day in `dd' format.
'%w'       The month in `Mon' format.
'%W'       The month in `mm' format.
'%y'       The year in `yy' format.
'%Y'       The year in `yyyy' format.
'%z'       The timezone in `[-+]NNNN' format.
'%Z'       The timezone name in `TZNAME' format.
'%-'       Reset formatting.
'%b'       Bold formatting.
'%0'..'%7' Foreground color.

type Client Uses

type Client struct {
    net.Conn

    // TermFunc allocates a new terminal for the incoming connection. If left
    // empty a new Virtual terminal will be created.
    TermFunc func(Stream) Terminal

    // StreamFunc allocates a new stream for the incoming connection. If left
    // empty a new telnet Protocol stream.
    StreamFunc func(Conn) Stream
}

Client implements a telnet client.

func Dial Uses

func Dial(network, address string) (*Client, error)

Dial opens a new telnet client connection. Output is sent to standard output and input is read from standard input.

func (*Client) Dial Uses

func (c *Client) Dial(network, address string) error

Dial starts connecting over the network.

func (*Client) Interact Uses

func (c *Client) Interact() (err error)

type Conn Uses

type Conn interface {
    // Conn is the (raw) network connection.
    net.Conn

    // IsClient indicates that the connection is a client connection.
    IsClient() bool

    // IsServer indicates that the connection is a server connection.
    IsServer() bool

    // Terminal is the connected terminal.
    Terminal() Terminal
}

Conn is a telnet connection.

type Console Uses

type Console struct {
    // contains filtered or unexported fields
}

Console implements the Terminal interface using standard output.

func NewConsole Uses

func NewConsole(stream Stream, out, in *os.File) *Console

NewConsole creates a new Terminal tied to a local file descriptor, such as os.Stdout.

func (*Console) FQDN Uses

func (c *Console) FQDN() string

func (*Console) Hostname Uses

func (c *Console) Hostname() string

func (*Console) Info Uses

func (c *Console) Info() *terminfo.Terminfo

func (*Console) Prompt Uses

func (c *Console) Prompt() error

Prompt ...

func (*Console) Read Uses

func (c *Console) Read(p []byte) (n int, err error)

func (*Console) SetSize Uses

func (c *Console) SetSize(_, _ int) error

SetSize is not supported.

func (*Console) SetSpeed Uses

func (c *Console) SetSpeed(_, _ int) error

SetSpeed is not supported.

func (*Console) SetType Uses

func (c *Console) SetType(_ string) error

SetType is not supported.

func (*Console) SetXDisplayLocation Uses

func (c *Console) SetXDisplayLocation(_ string) error

SetXDisplayLocation is not supported.

func (*Console) Size Uses

func (c *Console) Size() (int, int)

Size returns the current terminal size. If the operation is not supported by the operating system, it will default to 80x24.

func (*Console) Speed Uses

func (c *Console) Speed() (int, int)

Speed returns the receive and transmit baudrates of the current output device.

func (*Console) Type Uses

func (c *Console) Type() string

Type returns the current terminal type.

func (*Console) Write Uses

func (c *Console) Write(p []byte) (n int, err error)

func (*Console) XDisplayLocation Uses

func (c *Console) XDisplayLocation() string

XDisplayLocation returns the current X-Display location.

type Protocol Uses

type Protocol struct {
    // Events
    Events chan event.Event

    // IsServer interprets telnet commands in server or client mode.
    IsServer bool
    // contains filtered or unexported fields
}

Protocol implements the telnet protocol and Stream interface.

func NewProtocol Uses

func NewProtocol(conn Conn, isServer bool) *Protocol

NewProtocol starts a new telnet stream on the connection.

func (*Protocol) Conn Uses

func (p *Protocol) Conn() net.Conn

Conn returns the underlying transport.

func (*Protocol) Feed Uses

func (p *Protocol) Feed(buf []byte) error

Feed interprets bytes from remote.

func (*Protocol) Negotiate Uses

func (p *Protocol) Negotiate(timeout time.Duration) (err error)

Negotiate telnet options

func (*Protocol) Next Uses

func (p *Protocol) Next() event.Event

Next event in the channel.

func (*Protocol) Option Uses

func (p *Protocol) Option(opt byte) bool

Option returns the local status.

func (*Protocol) Read Uses

func (p *Protocol) Read(b []byte) (int, error)

Read reads bytes from the internal buffer, it will block if no data is available.

func (*Protocol) ReadByte Uses

func (p *Protocol) ReadByte() (byte, error)

ReadByte reads one byte from the internal buffer, it will block if no data is available.

func (*Protocol) RemoteOption Uses

func (p *Protocol) RemoteOption(opt byte) bool

RemoteOption returns the remote status.

func (*Protocol) SetOption Uses

func (p *Protocol) SetOption(opt byte, enabled bool)

SetOption sets the local status.

func (*Protocol) SubnegotiateMSSP Uses

func (p *Protocol) SubnegotiateMSSP(b []byte) error

SubnegotiateMSSP parses a MUD Server Status Protocol sub-negotiation

func (*Protocol) Write Uses

func (p *Protocol) Write(b []byte) (int, error)

Write transmits in-band data.

func (*Protocol) WriteOOB Uses

func (p *Protocol) WriteOOB(b []byte) (int, error)

WriteOOB transmits out-of-band data.

func (*Protocol) WriteRaw Uses

func (p *Protocol) WriteRaw(b []byte) (int, error)

WriteRaw transmits unescaped, raw data.

type ProtocolState Uses

type ProtocolState uint8

ProtocolState is the current state of the telnet state machine.

func (ProtocolState) String Uses

func (s ProtocolState) String() string

type Server Uses

type Server struct {
    // Server listen address.
    Addr string

    // Banner message which gets sent on-connect. Some formatting strings are
    // allowed, resolved via the Prompt function.
    Banner string

    // Debug messages.
    Debug bool

    // Option is a map of telnet protocol options negotiated with new clients.
    Option map[byte]bool

    // TermFunc allocates a new terminal for the incoming connection. If left
    // empty a new Virtual terminal will be created.
    TermFunc func(Stream) Terminal

    // StreamFunc allocates a new stream for the incoming connection. If left
    // empty a new telnet Protocol stream.
    StreamFunc func(Conn) Stream

    // NegotiationTimeout is the time we allow for the client and server to
    // negotiate telnet options.
    NegotiationTimeout time.Duration
}

func NewServer Uses

func NewServer(addr string) *Server

func (*Server) ListenAndServe Uses

func (s *Server) ListenAndServe() error

type ServerTerminal Uses

type ServerTerminal struct {
    // contains filtered or unexported fields
}

ServerTerminal implements the Terminal interface for a Server connection.

func NewServerTerminal Uses

func NewServerTerminal(stream Stream) *ServerTerminal

func (ServerTerminal) Charset Uses

func (s ServerTerminal) Charset() string

func (ServerTerminal) Environment Uses

func (s ServerTerminal) Environment() map[string]string

func (ServerTerminal) Info Uses

func (s ServerTerminal) Info() *terminfo.Terminfo

func (ServerTerminal) Name Uses

func (s ServerTerminal) Name() string

func (*ServerTerminal) Prompt Uses

func (s *ServerTerminal) Prompt() error

func (ServerTerminal) Read Uses

func (s ServerTerminal) Read(p []byte) (int, error)

func (*ServerTerminal) SetCharset Uses

func (s *ServerTerminal) SetCharset(charsets []string) error

func (*ServerTerminal) SetEnvironment Uses

func (s *ServerTerminal) SetEnvironment(env map[string]string) error

func (*ServerTerminal) SetName Uses

func (s *ServerTerminal) SetName(name string)

func (*ServerTerminal) SetPrompt Uses

func (s *ServerTerminal) SetPrompt(prompt string)

func (ServerTerminal) SetSize Uses

func (s ServerTerminal) SetSize(w, h int) error

func (*ServerTerminal) SetSpeed Uses

func (s *ServerTerminal) SetSpeed(rx, tx int) error

func (*ServerTerminal) SetVersion Uses

func (s *ServerTerminal) SetVersion(version string)

func (*ServerTerminal) Size Uses

func (s *ServerTerminal) Size() (int, int)

func (ServerTerminal) Speed Uses

func (s ServerTerminal) Speed() (int, int)

func (ServerTerminal) Version Uses

func (s ServerTerminal) Version() string

func (ServerTerminal) Write Uses

func (s ServerTerminal) Write(p []byte) (int, error)

type Stream Uses

type Stream interface {
    // Reader implements reading data bytes from the stream.
    io.Reader
    io.ByteReader

    // Writer implements writing to the stream.
    io.Writer

    // WriteRaw writes unescaped bytes.
    WriteRaw([]byte) (int, error)

    // WriteOOB writes out-of-band bytes.
    WriteOOB([]byte) (int, error)

    // Feed raw bytes.
    Feed([]byte) error

    // Option gets a telopt status for local.
    Option(byte) bool

    // SetOption sets a telopt status for local.
    SetOption(byte, bool)

    // RemoteOption gets a telopt status for remote.
    RemoteOption(byte) bool

    // Negotiate telnet options.
    Negotiate(time.Duration) error

    // Next event sent by remote.
    Next() event.Event

    // Conn is the underlying system transport.
    Conn() net.Conn
}

Stream handles raw bytes

type Terminal Uses

type Terminal interface {
    // Writer implements writing to the terminal.
    io.Writer

    // Reader implements reading from the connected stream.
    io.Reader

    // Info returns the terminfo entry (can be nil).
    Info() *terminfo.Terminfo

    // Prompt starts interacting with remote end.
    Prompt() error
}

Terminal implements a Reader/Writer.

type TerminalWithCharset Uses

type TerminalWithCharset interface {
    Charset() string
    SetCharset([]string) error
}

TerminalWithCharset implements a terminal with charset support (rfc2066)

type TerminalWithEnvironment Uses

type TerminalWithEnvironment interface {
    Environment() map[string]string
    SetEnvironment(map[string]string) error
}

TerminalWithEnvironment implements a termina with environment support

type TerminalWithHostname Uses

type TerminalWithHostname interface {
    Hostname() string
    FQDN() string
}

TerminalWithHostname implements a terminal with hostname and FQDN.

type TerminalWithLocation Uses

type TerminalWithLocation interface {
    Location() string
    SetLocation(string) error
}

TerminalWithLocation implements a terminal with send-location support (rfc779)

type TerminalWithLogout Uses

type TerminalWithLogout interface {
    Logout()
}

TerminalWithLogout implements a terminal with logout support

type TerminalWithReturnCode Uses

type TerminalWithReturnCode interface {
    ReturnCode() int
}

TerminalWithReturnCode implements a terminal with return code.

type TerminalWithSize Uses

type TerminalWithSize interface {
    Size() (int, int)
    SetSize(int, int) error
}

TerminalWithSize implements a terminal with window size support (rfc1073)

type TerminalWithSpeed Uses

type TerminalWithSpeed interface {
    Speed() (int, int)
    SetSpeed(int, int) error
}

TerminalWithSpeed implements a terminal with speed support (rfc1079)

type TerminalWithType Uses

type TerminalWithType interface {
    Type() string
    SetType(string) error
}

TerminalWithType implements a terminal with terminal type support (rfc1091)

type TerminalWithUsername Uses

type TerminalWithUsername interface {
    Username() string
}

TerminalWithUsername implements a terminal with username.

type TerminalWithVersion Uses

type TerminalWithVersion interface {
    Name() string
    Version() string
}

TerminalWithVersion implements a terminal with name and version.

type TerminalWithXDisplayLocation Uses

type TerminalWithXDisplayLocation interface {
    XDisplayLocation() string
    SetXDisplayLocation(string) error
}

TerminalWithXDisplayLocation implements a terminal with X-Display location support (rfc1096)

Directories

PathSynopsis
eventPackage event implements types and structures for the telnet out-of-band events.

Package telnet imports 18 packages (graph). Updated 2019-02-22. Refresh now. Tools for package owners.