diff --git a/scapy/layers/ntp.py b/scapy/layers/ntp.py index 3a679d3677067a16f973ee6a64435b0df028551c..601dc6e4aecf66a264e72d1354bb5b8786f93c4d 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 21635a54e60ebe17ff47a51d5c548a4249788c0d..b0e48c796679f4019d5d45671abfe9de62090928 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -5631,7 +5631,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) @@ -5649,7 +5649,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) @@ -5695,7 +5695,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) @@ -5720,7 +5720,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) @@ -5738,7 +5738,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) @@ -5753,7 +5753,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) @@ -5768,7 +5768,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) @@ -5783,7 +5783,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')) @@ -5801,7 +5801,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) @@ -5817,7 +5817,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) @@ -5833,7 +5833,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) @@ -5849,7 +5849,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) @@ -5865,7 +5865,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 == '') @@ -5879,7 +5879,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') @@ -5893,7 +5893,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') @@ -5906,7 +5906,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')