func IPv6PseudoHeader(src, dst net.IP) []byte
IPv6PseudoHeader returns an IPv6 pseudo header for checksum calculation.
func ParseIPv4Header(b []byte) (*ipv4.Header, error)
ParseIPv4Header returns the IPv4 header of the IPv4 packet that triggered an ICMP error message. This is found in the Data field of the ICMP error message body.
The provided b must be in the format used by a raw ICMP socket on the local system. This may differ from the wire format, and the format used by a raw IP socket, depending on the system.
To parse an IPv6 header, use ipv6.ParseHeader.
A DefaultMessageBody represents the default message body.
Deprecated: Use RawBody instead.
type DefaultMessageBody = RawBody
A DstUnreach represents an ICMP destination unreachable message body.
type DstUnreach struct { Data []byte // data, known as original datagram field Extensions []Extension // extensions }
func (p *DstUnreach) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *DstUnreach) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
An Echo represents an ICMP echo request or reply message body.
type Echo struct { ID int // identifier Seq int // sequence number Data []byte // data }
func (p *Echo) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *Echo) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
An ExtendedEchoReply represents an ICMP extended echo reply message body.
type ExtendedEchoReply struct { ID int // identifier Seq int // sequence number State int // 3-bit state working together with Message.Code Active bool // probed interface is active IPv4 bool // probed interface runs IPv4 IPv6 bool // probed interface runs IPv6 }
func (p *ExtendedEchoReply) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *ExtendedEchoReply) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
An ExtendedEchoRequest represents an ICMP extended echo request message body.
type ExtendedEchoRequest struct { ID int // identifier Seq int // sequence number Local bool // must be true when identifying by name or index Extensions []Extension // extensions }
func (p *ExtendedEchoRequest) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *ExtendedEchoRequest) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
An Extension represents an ICMP extension.
type Extension interface { // Len returns the length of ICMP extension. // The provided proto must be either the ICMPv4 or ICMPv6 // protocol number. Len(proto int) int // Marshal returns the binary encoding of ICMP extension. // The provided proto must be either the ICMPv4 or ICMPv6 // protocol number. Marshal(proto int) ([]byte, error) }
An InterfaceIdent represents interface identification.
type InterfaceIdent struct { Class int // extension object class number Type int // extension object sub-type Name string // interface name Index int // interface index AFI int // address family identifier; see address family numbers in IANA registry Addr []byte // address }
func (ifi *InterfaceIdent) Len(_ int) int
Len implements the Len method of Extension interface.
func (ifi *InterfaceIdent) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of Extension interface.
An InterfaceInfo represents interface and next-hop identification.
type InterfaceInfo struct { Class int // extension object class number Type int // extension object sub-type Interface *net.Interface Addr *net.IPAddr }
func (ifi *InterfaceInfo) Len(proto int) int
Len implements the Len method of Extension interface.
func (ifi *InterfaceInfo) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of Extension interface.
MPLSLabel represents an MPLS label stack entry.
type MPLSLabel struct { Label int // label value TC int // traffic class; formerly experimental use S bool // bottom of stack TTL int // time to live }
MPLSLabelStack represents an MPLS label stack.
type MPLSLabelStack struct { Class int // extension object class number Type int // extension object sub-type Labels []MPLSLabel }
func (ls *MPLSLabelStack) Len(proto int) int
Len implements the Len method of Extension interface.
func (ls *MPLSLabelStack) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of Extension interface.
A Message represents an ICMP message.
type Message struct { Type Type // type, either ipv4.ICMPType or ipv6.ICMPType Code int // code Checksum int // checksum Body MessageBody // body }
func ParseMessage(proto int, b []byte) (*Message, error)
ParseMessage parses b as an ICMP message. The provided proto must be either the ICMPv4 or ICMPv6 protocol number.
func (m *Message) Marshal(psh []byte) ([]byte, error)
Marshal returns the binary encoding of the ICMP message m.
For an ICMPv4 message, the returned message always contains the calculated checksum field.
For an ICMPv6 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.
A MessageBody represents an ICMP message body.
type MessageBody interface { // Len returns the length of ICMP message body. // The provided proto must be either the ICMPv4 or ICMPv6 // protocol number. Len(proto int) int // Marshal returns the binary encoding of ICMP message body. // The provided proto must be either the ICMPv4 or ICMPv6 // protocol number. Marshal(proto int) ([]byte, error) }
A PacketConn represents a packet network endpoint that uses either ICMPv4 or ICMPv6.
type PacketConn struct {
// contains filtered or unexported fields
}
▹ Example (NonPrivilegedPing)
func ListenPacket(network, address string) (*PacketConn, error)
ListenPacket listens for incoming ICMP packets addressed to address. See net.Dial for the syntax of address.
For non-privileged datagram-oriented ICMP endpoints, network must be "udp4" or "udp6". The endpoint allows to read, write a few limited ICMP messages such as echo request and echo reply. Currently only Darwin and Linux support this.
Examples:
ListenPacket("udp4", "192.168.0.1") ListenPacket("udp4", "0.0.0.0") ListenPacket("udp6", "fe80::1%en0") ListenPacket("udp6", "::")
For privileged raw ICMP endpoints, network must be "ip4" or "ip6" followed by a colon and an ICMP protocol number or name.
Examples:
ListenPacket("ip4:icmp", "192.168.0.1") ListenPacket("ip4:1", "0.0.0.0") ListenPacket("ip6:ipv6-icmp", "fe80::1%en0") ListenPacket("ip6:58", "::")
func (c *PacketConn) Close() error
Close closes the endpoint.
func (c *PacketConn) IPv4PacketConn() *ipv4.PacketConn
IPv4PacketConn returns the ipv4.PacketConn of c. It returns nil when c is not created as the endpoint for ICMPv4.
func (c *PacketConn) IPv6PacketConn() *ipv6.PacketConn
IPv6PacketConn returns the ipv6.PacketConn of c. It returns nil when c is not created as the endpoint for ICMPv6.
func (c *PacketConn) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (c *PacketConn) ReadFrom(b []byte) (int, net.Addr, error)
ReadFrom reads an ICMP message from the connection.
func (c *PacketConn) SetDeadline(t time.Time) error
SetDeadline sets the read and write deadlines associated with the endpoint.
func (c *PacketConn) SetReadDeadline(t time.Time) error
SetReadDeadline sets the read deadline associated with the endpoint.
func (c *PacketConn) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the write deadline associated with the endpoint.
func (c *PacketConn) WriteTo(b []byte, dst net.Addr) (int, error)
WriteTo writes the ICMP message b to dst. The provided dst must be net.UDPAddr when c is a non-privileged datagram-oriented ICMP endpoint. Otherwise it must be net.IPAddr.
A PacketTooBig represents an ICMP packet too big message body.
type PacketTooBig struct { MTU int // maximum transmission unit of the nexthop link Data []byte // data, known as original datagram field }
func (p *PacketTooBig) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *PacketTooBig) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
A ParamProb represents an ICMP parameter problem message body.
type ParamProb struct { Pointer uintptr // offset within the data where the error was detected Data []byte // data, known as original datagram field Extensions []Extension // extensions }
func (p *ParamProb) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *ParamProb) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
A RawBody represents a raw message body.
A raw message body is excluded from message processing and can be used to construct applications such as protocol conformance testing.
type RawBody struct { Data []byte // data }
func (p *RawBody) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *RawBody) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
A RawExtension represents a raw extension.
A raw extension is excluded from message processing and can be used to construct applications such as protocol conformance testing.
type RawExtension struct { Data []byte // data }
func (p *RawExtension) Len(proto int) int
Len implements the Len method of Extension interface.
func (p *RawExtension) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of Extension interface.
A TimeExceeded represents an ICMP time exceeded message body.
type TimeExceeded struct { Data []byte // data, known as original datagram field Extensions []Extension // extensions }
func (p *TimeExceeded) Len(proto int) int
Len implements the Len method of MessageBody interface.
func (p *TimeExceeded) Marshal(proto int) ([]byte, error)
Marshal implements the Marshal method of MessageBody interface.
A Type represents an ICMP message type.
type Type interface { Protocol() int }
This package is not implemented on JS, NaCl and Plan 9.