Skip to content

Commit

Permalink
packetparse: warn on short read
Browse files Browse the repository at this point in the history
  • Loading branch information
jchv committed Jun 25, 2023
1 parent 0b26e1f commit b04dfe0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/packetparse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,18 @@ func main() {

err = restruct.Unpack(packet[2:], binary.LittleEndian, message)
if err != nil {
log.Fatalf("Error parsing packet: %v; partial result: %#v; data: % 02x", err, message, packet)
log.Fatalf("Error parsing packet: %v; partial result: %s; data: % 02x", err, spew.Sdump(message), packet)
}

spew.Dump(message)

sz, err := restruct.SizeOf(message)
if err != nil {
log.Fatalf("Error getting packet size: %v", err)
}

if sz != len(packet[2:]) {
extra := len(packet[2:]) - sz
log.Printf("WARNING: %d (%08x) extra bytes... (%d total, %d parsed)", extra, extra, len(packet[2:]), sz)
}
}

0 comments on commit b04dfe0

Please sign in to comment.