google / google/gopacket

For UDP packets, applicationLayer.Payload() is not the same of udpLayer.LayerPayload()

Open
#709 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I am observing a strange behaviour while filtering UDP packets from a .pcap file and getting their payload.

`
for packet := range packetSource.Packets() {

if err := packet.ErrorLayer(); err != nil {
continue
}

udpLayer := packet.Layer(layers.LayerTypeUDP)
if udpLayer == nil {
continue
}

// Condition A
if len(udpLayer.LayerPayload()) == 0 {
continue
}

/* Condition B
appLayer := packet.ApplicationLayer()
if appLayer == nil || len(appLayer.Payload()) == 0 {
continue
}*/
`

With condition A I get 179 packets, with condition B (and A disabled) I get 89 packets. Why?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.