diff options
Diffstat (limited to 'icmp/dstunreach.go')
-rw-r--r-- | icmp/dstunreach.go | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/icmp/dstunreach.go b/icmp/dstunreach.go index d1905a9..01dc660 100644 --- a/icmp/dstunreach.go +++ b/icmp/dstunreach.go @@ -12,31 +12,30 @@ type DstUnreach struct { } // Len implements the Len method of MessageBody interface. -func (p *DstUnreach) Len() int { +func (p *DstUnreach) Len(proto int) int { if p == nil { return 0 } - return 4 + len(p.Data) + l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions) + return l } // Marshal implements the Marshal method of MessageBody interface. func (p *DstUnreach) Marshal(proto int) ([]byte, error) { - b := make([]byte, 4+len(p.Data)) - copy(b[4:], p.Data) - return b, nil + return marshalMultipartMessageBody(proto, p.Data, p.Extensions) } // parseDstUnreach parses b as an ICMP destination unreachable message // body. func parseDstUnreach(proto int, b []byte) (MessageBody, error) { - bodyLen := len(b) - if bodyLen < 4 { + if len(b) < 4 { return nil, errMessageTooShort } p := &DstUnreach{} - if bodyLen > 4 { - p.Data = make([]byte, bodyLen-4) - copy(p.Data, b[4:]) + var err error + p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b) + if err != nil { + return nil, err } return p, nil } |