Skip to content

Commit

Permalink
Simplify NTP parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
unkaktus authored and gconnell committed May 16, 2017
1 parent c07b1da commit 9cdfdb6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions layers/ntp.go
Expand Up @@ -321,13 +321,13 @@ func (d *NTP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
// above and the section on endian conventions.

// The first few fields are all packed into the first 32 bits. Unpack them.
f := binary.BigEndian.Uint32(data[0:4])
d.LeapIndicator = NTPLeapIndicator((f & 0xC0000000) >> 30)
d.Version = NTPVersion((f & 0x38000000) >> 27)
d.Mode = NTPMode((f & 0x07000000) >> 24)
d.Stratum = NTPStratum((f & 0x00FF0000) >> 16)
d.Poll = NTPLog2Seconds((f & 0x0000FF00) >> 8)
d.Precision = NTPLog2Seconds((f & 0x000000FF) >> 0)
f := data[0]
d.LeapIndicator = NTPLeapIndicator((f & 0xC0) >> 6)
d.Version = NTPVersion((f & 0x38) >> 3)
d.Mode = NTPMode(f & 0x07)
d.Stratum = NTPStratum(data[1])
d.Poll = NTPLog2Seconds(data[2])
d.Precision = NTPLog2Seconds(data[3])

// The remaining fields can just be copied in big endian order.
d.RootDelay = NTPFixed16Seconds(binary.BigEndian.Uint32(data[4:8]))
Expand Down

0 comments on commit 9cdfdb6

Please sign in to comment.