diff --git a/scapy/layers/ntp.py b/scapy/layers/ntp.py index 1d7bfd0971ba6c3913ad4f6fb3b4f962c67b0ae5..15c69629517c4507390c8cc073cac2e5bb821d98 100644 --- a/scapy/layers/ntp.py +++ b/scapy/layers/ntp.py @@ -16,8 +16,8 @@ from scapy.packet import Packet, bind_layers from scapy.fields import (BitField, BitEnumField, ByteField, ByteEnumField, \ XByteField, SignedByteField, FlagsField, ShortField, LEShortField, IntField,\ LEIntField, FixedPointField, IPField, StrField, StrFixedLenField,\ -StrFixedLenEnumField, PacketField, PacketLenField, PacketListField,\ -FieldListField, ConditionalField, PadField) +StrFixedLenEnumField, XStrFixedLenField, PacketField, PacketLenField,\ +PacketListField, FieldListField, ConditionalField, PadField) from scapy.layers.inet6 import IP6Field from scapy.layers.inet import UDP from scapy.utils import lhex @@ -55,28 +55,13 @@ _NTP_HASH_SIZE = 128 class XLEShortField(LEShortField): """ - XLEShortField which value is encoded in little endian. + XShortField which value is encoded in little endian. """ def i2repr(self, pkt, x): return lhex(self.i2h(pkt, x)) -class XStrFixedLenField(StrFixedLenField): - """ - StrFixedLenField which value is printed as hexadecimal. - """ - - def i2repr(self, pkt, x): - output = "" - length = len(x) - len_from_val = self.length_from(pkt) - max_idx = length if length < len_from_val else len_from_val - for i in range(0, max_idx): - output += x[i].encode("hex") - return output - - class TimeStampField(FixedPointField): """ This field handles the timestamp fields in the NTP header. @@ -761,7 +746,7 @@ class NTPControlStatusField(PacketField): ret = None association_id = struct.unpack("!H", m[2:4])[0] - if pkt.error == 1: + if pkt.err == 1: ret = NTPErrorStatusPacket(m) # op_code == CTL_OP_READSTAT @@ -869,7 +854,7 @@ class NTPControl(NTP): BitField("version", 2, 3), BitField("mode", 6, 3), BitField("response", 0, 1), - BitField("error", 0, 1), + BitField("err", 0, 1), BitField("more", 0, 1), BitEnumField("op_code", 0, 5, _op_codes), ShortField("sequence", 0), diff --git a/test/regression.uts b/test/regression.uts index 11f7b5a773b20340746718a9615b2e849c88ef8c..e5bb842efd3756dfaec3b218d1475c5d1e71a61f 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -5899,7 +5899,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 0) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 1) assert(p.sequence == 12) @@ -5917,7 +5917,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 1) assert(p.sequence == 12) @@ -5963,7 +5963,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 1) assert(p.op_code == 2) assert(p.sequence == 18) @@ -5988,7 +5988,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 2) assert(p.sequence == 18) @@ -6006,7 +6006,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 0) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 2) assert(len(p.data.load) == 12) @@ -6021,7 +6021,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 1) +assert(p.err == 1) assert(p.more == 0) assert(p.op_code == 2) assert(len(p.data.load) == 0) @@ -6036,7 +6036,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 0) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 3) assert(len(p.data.load) == 12) @@ -6051,7 +6051,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 1) +assert(p.err == 1) assert(p.more == 0) assert(p.op_code == 3) assert(hasattr(p, 'status_word')) @@ -6069,7 +6069,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 0) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 8) assert(p.count == 12) @@ -6085,7 +6085,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 8) assert(p.count == 18) @@ -6101,7 +6101,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 0) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 9) assert(p.count == 15) @@ -6117,7 +6117,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 9) assert(p.count == 42) @@ -6133,7 +6133,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 0) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 12) assert(p.data == '') @@ -6147,7 +6147,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 0) +assert(p.err == 0) assert(p.more == 0) assert(p.op_code == 12) assert(p.data.load == 'nonce=db4186a2e1d9022472e24bc9\r\n') @@ -6161,7 +6161,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 0) -assert(p.error == 0) +assert(p.err == 0) assert(p.op_code == 10) assert(p.count == 40) assert(p.data.load == 'nonce=db4186a2e1d9022472e24bc9, frags=32') @@ -6174,7 +6174,7 @@ assert(isinstance(p, NTPControl)) assert(p.version == 2) assert(p.mode == 6) assert(p.response == 1) -assert(p.error == 0) +assert(p.err == 0) assert(p.op_code == 10) assert(p.count == 233) assert(p.data.load == 'nonce=db4186a2e2073198b93c6419, addr.0=192.168.122.100:123,\r\nfirst.0=0xdb418673.323e1a89, last.0=0xdb418673.323e1a89, ct.0=1,\r\nmv.0=36, rs.0=0x0, WWQ.0=18446744073709509383, now=0xdb4186a2.e20ff8f4,\r\nlast.newest=0xdb418673.323e1a89\r\n\x00\x00\x00')