mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
icmp: fix error values on message manipulation
Change-Id: If5e0d21f01496cf89d035b07a884073044a4e886 Reviewed-on: https://go-review.googlesource.com/126637 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
var (
|
||||
errInvalidConn = errors.New("invalid connection")
|
||||
errInvalidProtocol = errors.New("invalid protocol")
|
||||
errMessageTooShort = errors.New("message too short")
|
||||
errHeaderTooShort = errors.New("header too short")
|
||||
errBufferTooShort = errors.New("buffer too short")
|
||||
@@ -80,7 +81,7 @@ func (m *Message) Marshal(psh []byte) ([]byte, error) {
|
||||
case ipv6.ICMPType:
|
||||
mtype = int(typ)
|
||||
default:
|
||||
return nil, errInvalidConn
|
||||
return nil, errInvalidProtocol
|
||||
}
|
||||
b := []byte{byte(mtype), byte(m.Code), 0, 0}
|
||||
if m.Type.Protocol() == iana.ProtocolIPv6ICMP && psh != nil {
|
||||
@@ -143,7 +144,7 @@ func ParseMessage(proto int, b []byte) (*Message, error) {
|
||||
case iana.ProtocolIPv6ICMP:
|
||||
m.Type = ipv6.ICMPType(b[0])
|
||||
default:
|
||||
return nil, errInvalidConn
|
||||
return nil, errInvalidProtocol
|
||||
}
|
||||
if fn, ok := parseFns[m.Type]; !ok {
|
||||
m.Body, err = parseDefaultMessageBody(proto, b[4:])
|
||||
|
||||
Reference in New Issue
Block a user