|
|
@ -47,6 +47,7 @@ var icmpRequestDecode = ParsedPacket{
|
|
|
|
dataofs: 24,
|
|
|
|
dataofs: 24,
|
|
|
|
length: len(icmpRequestBuffer),
|
|
|
|
length: len(icmpRequestBuffer),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IPVersion: 4,
|
|
|
|
IPProto: ICMP,
|
|
|
|
IPProto: ICMP,
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
@ -72,6 +73,7 @@ var icmpReplyDecode = ParsedPacket{
|
|
|
|
dataofs: 24,
|
|
|
|
dataofs: 24,
|
|
|
|
length: len(icmpReplyBuffer),
|
|
|
|
length: len(icmpReplyBuffer),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IPVersion: 4,
|
|
|
|
IPProto: ICMP,
|
|
|
|
IPProto: ICMP,
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
@ -91,7 +93,8 @@ var ipv6PacketBuffer = []byte{
|
|
|
|
|
|
|
|
|
|
|
|
var ipv6PacketDecode = ParsedPacket{
|
|
|
|
var ipv6PacketDecode = ParsedPacket{
|
|
|
|
b: ipv6PacketBuffer,
|
|
|
|
b: ipv6PacketBuffer,
|
|
|
|
IPProto: IPv6,
|
|
|
|
IPVersion: 6,
|
|
|
|
|
|
|
|
IPProto: ICMPv6,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This is a malformed IPv4 packet.
|
|
|
|
// This is a malformed IPv4 packet.
|
|
|
@ -102,6 +105,7 @@ var unknownPacketBuffer = []byte{
|
|
|
|
|
|
|
|
|
|
|
|
var unknownPacketDecode = ParsedPacket{
|
|
|
|
var unknownPacketDecode = ParsedPacket{
|
|
|
|
b: unknownPacketBuffer,
|
|
|
|
b: unknownPacketBuffer,
|
|
|
|
|
|
|
|
IPVersion: 0,
|
|
|
|
IPProto: Unknown,
|
|
|
|
IPProto: Unknown,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -125,6 +129,7 @@ var tcpPacketDecode = ParsedPacket{
|
|
|
|
dataofs: 40,
|
|
|
|
dataofs: 40,
|
|
|
|
length: len(tcpPacketBuffer),
|
|
|
|
length: len(tcpPacketBuffer),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IPVersion: 4,
|
|
|
|
IPProto: TCP,
|
|
|
|
IPProto: TCP,
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
@ -152,6 +157,7 @@ var udpRequestDecode = ParsedPacket{
|
|
|
|
dataofs: 28,
|
|
|
|
dataofs: 28,
|
|
|
|
length: len(udpRequestBuffer),
|
|
|
|
length: len(udpRequestBuffer),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IPVersion: 4,
|
|
|
|
IPProto: UDP,
|
|
|
|
IPProto: UDP,
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
SrcIP: NewIP(net.ParseIP("1.2.3.4")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
|
DstIP: NewIP(net.ParseIP("5.6.7.8")),
|
|
|
@ -234,7 +240,7 @@ func TestDecode(t *testing.T) {
|
|
|
|
var got ParsedPacket
|
|
|
|
var got ParsedPacket
|
|
|
|
got.Decode(tt.buf)
|
|
|
|
got.Decode(tt.buf)
|
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("got %v; want %v", got, tt.want)
|
|
|
|
t.Errorf("mismatch\n got: %#v\nwant: %#v", got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|