Skip to content

Commit

Permalink
Fix NTP poll and precision data types
Browse files Browse the repository at this point in the history
These fields are 8-bit signed integers, per
https://datatracker.ietf.org/doc/html/rfc5905#page-21 (bottom of the
page).
  • Loading branch information
paulgear committed Aug 15, 2023
1 parent 2fe5cee commit 47d7b77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions scapy/layers/ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ class NTPHeader(NTP):
BitField("version", 4, 3),
BitEnumField("mode", 3, 3, _ntp_modes),
BitField("stratum", 2, 8),
BitField("poll", 0xa, 8),
BitField("precision", 0, 8),
SignedByteField("poll", 0xa),
SignedByteField("precision", 0),
FixedPointField("delay", 0, size=32, frac_bits=16),
FixedPointField("dispersion", 0, size=32, frac_bits=16),
ConditionalField(IPField("id", "127.0.0.1"), lambda p: p.stratum > 1),
Expand Down Expand Up @@ -1120,7 +1120,7 @@ class NTPInfoSys(Packet):
ByteField("peer_mode", 0),
ByteField("leap", 0),
ByteField("stratum", 0),
ByteField("precision", 0),
SignedByteField("precision", 0),
FixedPointField("rootdelay", 0, size=32, frac_bits=16),
FixedPointField("rootdispersion", 0, size=32, frac_bits=16),
IPField("refid", 0),
Expand Down
6 changes: 3 additions & 3 deletions test/scapy/layers/ntp.uts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ assert p.data[0].peer == "127.127.1.0"
assert p.data[0].peer_mode == 3
assert p.data[0].leap == 0
assert p.data[0].stratum == 11
assert p.data[0].precision == 240
assert p.data[0].precision == -16
assert p.data[0].refid == "127.127.1.0"


Expand Down Expand Up @@ -1113,7 +1113,7 @@ assert p.data[0].ifname.startswith(b"lo")

from decimal import Decimal

precision = b"\xec" # 236
precision = b"\xec" # -20
dispersion = b"\x00\x00\xf2\xce" # 0.948455810546875
time_stamp = b"\xe6}gt\x00\x00\x00\x00" # Sat, 16 Jul 2022 16:36:04 +0000

Expand Down Expand Up @@ -1142,7 +1142,7 @@ assert pkt_1.recv.val == time_stamp, pkt_1.recv.val

time_stamp_hex = 0x00000000e67d6774
pkt_2 = NTP(
precision=236,
precision=-20,
dispersion=Decimal('0.948455810546875'),
orig=time_stamp_hex,
sent=time_stamp_hex,
Expand Down

0 comments on commit 47d7b77

Please sign in to comment.