kbandla / dpkt

fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Other
1.09k stars 270 forks source link

Fix #433: Allow multiple InterfaceDescriptionBlocks with pcapng.Writer #493

Closed powerswitch closed 3 years ago

powerswitch commented 3 years ago

Current version only supports one InterfaceDescriptionBlock, but in general it is allowed to have more then one.

This patch extends the interface so you can provide alternatively a sequence of InterfaceDescriptionBlock instances (or anything which is iterable).

This commit was created by the patch provided as ZIP file by René Liebscher as attachment to the issue.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.01%) to 92.379% when pulling 14386cd24524d09a0d7f98a26e054df62582baeb on powerswitch:fix-#433 into 49c1af0bf863e404af273544eba939d4fc4d453b on kbandla:master.

brifordwylie commented 3 years ago

@powerswitch @rliebscher @obormot So pulling this branch locally, the tests run fine. When I merge master the tests are failing due to the changes pulled in with the merge of #502. So two options: 1) Someone else merges master into this branch and makes sure the test all pass (just run 'tox' at the top level) 2) I'll do it..make a new PR.. and merge...

Also I think I'm going to put some branch protections on master, to avoid stuff like this in future :)

dpkt/pcapng.py::test_writepkt_epb_ts FAILED
dpkt/pcapng.py::test_custom_read_write FAILED

Both tests fail with the same error

dpkt/pcapng.py:376: in __init__
    self._validate_block('idb', idb_, InterfaceDescriptionBlock)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <dpkt.pcapng.Writer object at 0x102f6fd30>, arg_name = 'idb', blk = ('type', 1)
expected_cls = <class 'dpkt.pcapng.InterfaceDescriptionBlock'>

    def _validate_block(self, arg_name, blk, expected_cls):
        """Check a user-defined block for correct type and endianness"""
        if not isinstance(blk, expected_cls):
>           raise ValueError('{0}: expecting class {1}'.format(
                arg_name, expected_cls.__name__))
E           ValueError: idb: expecting class InterfaceDescriptionBlock

dpkt/pcapng.py:397: ValueError
powerswitch commented 3 years ago

Hi @brifordwylie, sorry for the long absence. I'm only capable to work on the project rarely. But now I'm on holidays, so I pick it up again.

I'll merge the latest master onto the branch and run the tox tests again, will fix them and push the changes. Again, sorry for the delay

brifordwylie commented 3 years ago

@powerswitch @rliebscher looks good, thanks a bunch for the contribution... merging now.