icmp

package
v0.1459.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2016 License: Apache-2.0, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package icmp provides basic functions for the manipulation of ICMP message.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPv6PseudoHeader

func IPv6PseudoHeader(src, dst net.IP) []byte

IPv6PseudoHeader returns an IPv6 pseudo header for checkusm calculation.

Types

type DefaultMessageBody

type DefaultMessageBody struct {
	Data []byte // data
}

A DefaultMessageBody represents the default message body.

func (*DefaultMessageBody) Len

func (p *DefaultMessageBody) Len() int

Len implements the Len method of MessageBody interface.

func (*DefaultMessageBody) Marshal

func (p *DefaultMessageBody) Marshal() ([]byte, error)

Marshal implements the Marshal method of MessageBody interface.

type Echo

type Echo struct {
	ID   int    // identifier
	Seq  int    // sequence number
	Data []byte // data
}

An Echo represenets an ICMP echo request or reply message body.

func (*Echo) Len

func (p *Echo) Len() int

Len implements the Len method of MessageBody interface.

func (*Echo) Marshal

func (p *Echo) Marshal() ([]byte, error)

Marshal implements the Marshal method of MessageBody interface.

type Message

type Message struct {
	Type     Type        // type, either ipv4.ICMPType or ipv6.ICMPType
	Code     int         // code
	Checksum int         // checksum
	Body     MessageBody // body
}

A Message represents an ICMP message.

func ParseMessage

func ParseMessage(proto int, b []byte) (*Message, error)

ParseMessage parses b as an ICMP message. Proto must be iana.ProtocolICMP or iana.ProtocolIPv6ICMP.

func (*Message) Marshal

func (m *Message) Marshal(psh []byte) ([]byte, error)

Marshal returns the binary enconding of the ICMP message m.

For ICMP for IPv4 message, the returned message always contains the calculated checksum field.

For ICMP for IPv6 message, the returned message contains the calculated checksum field when psh is not nil, otherwise the kernel will compute the checksum field during the message transmission. When psh is not nil, it must be the pseudo header for IPv6.

type MessageBody

type MessageBody interface {
	// Len returns the length of ICMP message body.
	Len() int

	// Marshal returns the binary enconding of ICMP message body.
	Marshal() ([]byte, error)
}

A MessageBody represents an ICMP message body.

type Type

type Type interface {
	String() string
}

A Type represents an ICMP message type.

Jump to

Keyboard shortcuts

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