diff --git a/pcapkit/protocols/internet/ipv4.py b/pcapkit/protocols/internet/ipv4.py index 511996f78a..296d3729f9 100644 --- a/pcapkit/protocols/internet/ipv4.py +++ b/pcapkit/protocols/internet/ipv4.py @@ -887,7 +887,8 @@ def _read_opt_sec(self, schema: 'Schema_SECOption', *, options: 'Option') -> 'Da warn(f'{self.alias}: [OptNo {schema.type}] invalid format: remaining data', ProtocolWarning) if schema.data[-1] & 0x01 == 1: - warn(f'{self.alias}: [OptNo {schema.type}] invalid format: field termination indicator not set', ProtocolWarning) + warn(f'{self.alias}: [OptNo {schema.type}] invalid format: ' + f'field termination indicator set on the final octet: {schema.data[-1]!r}', ProtocolWarning) termination = tuple(bool(byte & 0x01) for byte in schema.data) else: flags = [] diff --git a/tests/protocols/internet/test_ipv4_roundtrip_unit.py b/tests/protocols/internet/test_ipv4_roundtrip_unit.py index d8f1a952d7..ea4050fc32 100644 --- a/tests/protocols/internet/test_ipv4_roundtrip_unit.py +++ b/tests/protocols/internet/test_ipv4_roundtrip_unit.py @@ -156,9 +156,13 @@ def test_sec_termination_indicator_follows_rfc_1108(self) -> None: option = self.parse(header('8204ab90')).info.options[OptionNumber.SEC] self.assertEqual(option.flags, (ProtectionAuthority.GENSER, ProtectionAuthority.NSA)) - # The low-order bit set on the final octet promises another octet. - with self.assertWarnsRegex(ProtocolWarning, 'field termination indicator not set'): + # The low-order bit set on the final octet promises another octet, and + # the warning names the bit that is set rather than one that is not + # (#2295). ``0x91`` is 145. + with self.assertWarns(ProtocolWarning) as caught: self.parse(header('8204ab91')) + self.assertEqual(str(caught.warning), 'IPv4: [OptNo 130] invalid format: ' + 'field termination indicator set on the final octet: 145') def test_timestamp_keeps_the_high_order_bit(self) -> None: from pcapkit.const.ipv4.option_number import OptionNumber diff --git a/tests/protocols/internet/test_ipv4_unit.py b/tests/protocols/internet/test_ipv4_unit.py index a57e1557d0..c9d2cc2eea 100644 --- a/tests/protocols/internet/test_ipv4_unit.py +++ b/tests/protocols/internet/test_ipv4_unit.py @@ -502,9 +502,9 @@ def test_ipv4_make_opt_sec_sets_the_field_termination_indicator(self) -> None: :rfc:`1108` section 2.4(a) makes the low-order bit of each protection authority octet a *field termination indicator*: ``1`` means another octet follows, ``0`` means this is the last. ``_read_opt_sec`` enforces - it, warning ``field termination indicator not set`` when the final octet - has it set. The writer and the reader agree with each other (#537) and - with the RFC (#1321). + it, warning ``field termination indicator set on the final octet`` when + the final octet has it set. The writer and the reader agree with each + other (#537) and with the RFC (#1321). The round trip is asserted through a real datagram and with warnings promoted to errors, because a disagreement's only symptom is a warning.