tftp

package
v0.0.0-...-38b5b46 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeNETASCII = "netascii"
	ModeOctet    = "octet"
)

Variables

View Source
var (
	ErrInputNotNETASCII   = errors.New("input is not valid NETASCII")
	ErrInvalidBlockNumber = errors.New("block number is not valid")
	ErrTooMuchData        = errors.New("data packet contains more than 512 bytes")
	ErrMismatchingOpcode  = errors.New("attempting to unmarshal a packet with mismatching opcode")
)

Functions

This section is empty.

Types

type ACKPacket

type ACKPacket struct {
	// Acknowledged block number. For RRQs, this will be the requested block number and will be acknowledged by the
	// corresponding block being sent in a DATA packet; for WRQs this will be 0
	BlockNumber uint16
}

ACKPacket represents an Acknowledge packet. ACK packets are acknowledged by DATA or ERROR packets.

func (*ACKPacket) Marshal

func (p *ACKPacket) Marshal(w io.Writer) error

func (*ACKPacket) Unmarshal

func (p *ACKPacket) Unmarshal(r io.Reader) error

type DATAPacket

type DATAPacket struct {
	// Block number, starting from 1
	BlockNumber uint16
	// Data being transferred within this packet, with a maximum length of 512.
	// If the length of this field is between 0 and 511, the transfer is considered complete
	Data []byte
}

DATAPacket represents a data packet

func (*DATAPacket) Marshal

func (p *DATAPacket) Marshal(w io.Writer) error

func (*DATAPacket) Unmarshal

func (p *DATAPacket) Unmarshal(r io.Reader) error

type ERRORPacket

type ERRORPacket struct {
	// Error code
	ErrorCode ErrorCode
	// Error message
	ErrorMsg string
}

ERRORPacket represents an Error packet. ERROR packets are sent when to acknowledge any kind of packet which results in an unsuccessful outcome.

func (*ERRORPacket) Marshal

func (p *ERRORPacket) Marshal(w io.Writer) error

func (*ERRORPacket) Unmarshal

func (p *ERRORPacket) Unmarshal(r io.Reader) error

type ErrorCode

type ErrorCode uint16

ErrorCode represents an error code, as defined in the TFTP standard

const (
	ErrorCodeNotDefined        ErrorCode = 0
	ErrorCodeFileNotFound      ErrorCode = 1
	ErrorCodeAccessViolation   ErrorCode = 2
	ErrorCodeDiskFull          ErrorCode = 3
	ErrorCodeIllegalOp         ErrorCode = 4
	ErrorCodeUnknownTransferID ErrorCode = 5
	ErrorCodeFileAlreadyExists ErrorCode = 6
	ErrorCodeNoSuchUser        ErrorCode = 7
)

func (ErrorCode) Error

func (e ErrorCode) Error() string

type IOError

type IOError struct {
	Msg string // High-level description of the error
	Err error  // Original error
}

IOError type encapsulates I/O errors when marshalling or unmarshalling binary packets

func NewIOError

func NewIOError(msg string, err error) IOError

func (IOError) Error

func (err IOError) Error() string

type Mode

type Mode string

Mode type represents a mode, as defined in the TFTP protocol

type Opcode

type Opcode uint16

Opcode type represents a TFTP opcode

const ACK Opcode = 4

ACK is the opcode for the ACK (Acknowledgement) packet

const DATA Opcode = 3

DATA is the opcode for the DATA (Data) packet

const ERROR Opcode = 5

ERROR is the opcode for the ERROR (Error) packet

const RRQ Opcode = 1

RRQ is the opcode for the RRQ (Read Request) packet

const WRQ Opcode = 2

WRQ is the opcode for the WRQ (Write Request) packet

type Packet

type Packet interface {
	Marshal(w io.Writer) error
}

type RRQPacket

type RRQPacket struct {
	// Destination filename. This should only contain NETASCII characters
	Filename string
	// File mode
	Mode Mode
}

RRQPacket represents a Read Request packet

func (*RRQPacket) Marshal

func (p *RRQPacket) Marshal(w io.Writer) error

func (*RRQPacket) Unmarshal

func (p *RRQPacket) Unmarshal(r io.Reader) error

type WRQPacket

type WRQPacket struct {
	// Destination filename. This should only contain NETASCII characters
	Filename string
	// File mode
	Mode Mode
}

WRQPacket represents a Write Request packet

func (*WRQPacket) Marshal

func (p *WRQPacket) Marshal(w io.Writer) error

func (*WRQPacket) Unmarshal

func (p *WRQPacket) Unmarshal(r io.Reader) error

Jump to

Keyboard shortcuts

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