You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
687 B
33 lines
687 B
package parser
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
)
|
|
|
|
type ICMP struct {
|
|
BaseLayer
|
|
TypeCode uint16
|
|
Checksum uint16
|
|
Id uint16
|
|
Seq uint16
|
|
}
|
|
|
|
func (I *ICMP) LayerType() int {
|
|
return LayerTypeICMP
|
|
}
|
|
|
|
func DecodeICMP(data []byte) (*ICMP, error) {
|
|
icmp := ICMP{}
|
|
if len(data) < 8 {
|
|
return nil, errors.New("ICMP数据包头部少于8字节")
|
|
}
|
|
|
|
icmp.TypeCode = binary.BigEndian.Uint16(data[0:2])
|
|
icmp.Checksum = binary.BigEndian.Uint16(data[2:4])
|
|
icmp.Id = binary.BigEndian.Uint16(data[4:6])
|
|
icmp.Seq = binary.BigEndian.Uint16(data[6:8])
|
|
icmp.BaseLayer = BaseLayer{data[:8], data[8:]}
|
|
|
|
return &icmp, nil
|
|
}
|
|
|