github.com/metacubex/sing-tun@v0.2.7-0.20240512075008-89e7c6208eec/internal/clashtcpip/icmp.go (about) 1 package clashtcpip 2 3 import ( 4 "encoding/binary" 5 ) 6 7 type ICMPType = byte 8 9 const ( 10 ICMPTypePingRequest byte = 0x8 11 ICMPTypePingResponse byte = 0x0 12 ) 13 14 type ICMPPacket []byte 15 16 func (p ICMPPacket) Type() ICMPType { 17 return p[0] 18 } 19 20 func (p ICMPPacket) SetType(v ICMPType) { 21 p[0] = v 22 } 23 24 func (p ICMPPacket) Code() byte { 25 return p[1] 26 } 27 28 func (p ICMPPacket) Checksum() uint16 { 29 return binary.BigEndian.Uint16(p[2:]) 30 } 31 32 func (p ICMPPacket) SetChecksum(sum [2]byte) { 33 p[2] = sum[0] 34 p[3] = sum[1] 35 } 36 37 func (p ICMPPacket) ResetChecksum() { 38 p.SetChecksum(zeroChecksum) 39 p.SetChecksum(Checksum(0, p)) 40 }