Skip to content

Commit c456201

Browse files
authored
Show NTP version and mode instead of question marks (#3944)
In 1e48e13 NTP switched to dispatch_hook and all the fields including "version" and "mode" moved to the NTP subclasses. This PR adjusts the mysummary method accordingly. With this patch applied tshark() prints something like ``` 17 Ether / IP / UDP / NTP v4, client 18 Ether / IP / UDP / NTP v4, server ``` instead of ``` 17 Ether / IP / UDP / NTP v??, ?? 18 Ether / IP / UDP / NTP v??, ?? ``` It's a follow-up to 1e48e13
1 parent 1714a36 commit c456201

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

scapy/layers/ntp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ def pre_dissect(self, s):
209209
return s
210210

211211
def mysummary(self):
212-
return self.sprintf("NTP v%ir,NTP.version%, %NTP.mode%")
212+
return self.sprintf(
213+
"NTP v%ir,{0}.version%, %{0}.mode%".format(self.__class__.__name__)
214+
)
213215

214216

215217
class _NTPAuthenticatorPaddingField(StrField):
@@ -795,7 +797,7 @@ class NTPControl(NTP):
795797
fields_desc = [
796798
BitField("zeros", 0, 2),
797799
BitField("version", 2, 3),
798-
BitField("mode", 6, 3),
800+
BitEnumField("mode", 6, 3, _ntp_modes),
799801
BitField("response", 0, 1),
800802
BitField("err", 0, 1),
801803
BitField("more", 0, 1),
@@ -1777,7 +1779,7 @@ class NTPPrivate(NTP):
17771779
BitField("response", 0, 1),
17781780
BitField("more", 0, 1),
17791781
BitField("version", 2, 3),
1780-
BitField("mode", 0, 3),
1782+
BitEnumField("mode", 7, 3, _ntp_modes),
17811783
BitField("auth", 0, 1),
17821784
BitField("seq", 0, 7),
17831785
ByteEnumField("implementation", 0, _implementations),

test/scapy/layers/ntp.uts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ assert NTPHeader in p
2424
assert not NTPControl in p
2525
assert not NTPPrivate in p
2626
assert NTP in p
27+
assert p.mysummary() == "NTP v4, client"
2728
p = NTPControl()
2829
assert not NTPHeader in p
2930
assert NTPControl in p
3031
assert not NTPPrivate in p
3132
assert NTP in p
33+
assert p.mysummary() == "NTP v2, NTP control message"
3234
p = NTPPrivate()
3335
assert not NTPHeader in p
3436
assert not NTPControl in p
3537
assert NTPPrivate in p
3638
assert NTP in p
39+
assert p.mysummary() == "NTP v2, reserved for private use"
3740

3841
= NTP - Layers (2)
3942
p = NTPHeader()

0 commit comments

Comments
 (0)