Commit c5d01341 authored by Chris Lamb's avatar Chris Lamb 💬

Add support for comparing Pcap files. (Closes: #858867)

Signed-off-by: Chris Lamb's avatarChris Lamb <lamby@debian.org>
parent a7155a87
......@@ -53,6 +53,7 @@ Build-Depends:
sng <!nocheck>,
sqlite3 <!nocheck>,
squashfs-tools <!nocheck>,
tcpdump <!nocheck>,
unzip <!nocheck>,
xxd <!nocheck> | vim-common <!nocheck>,
Standards-Version: 3.9.8
......
......@@ -78,6 +78,7 @@ class ComparatorManager(object):
('git.GitIndexFile',),
('openssh.PublicKeyFile',),
('gif.GifFile',),
('pcap.PcapFile',),
)
_singleton = {}
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2017 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import re
from diffoscope.tools import tool_required
from diffoscope.difference import Difference
from .utils.file import File
from .utils.command import Command
class Tcpdump(Command):
@tool_required('tcpdump')
def cmdline(self):
return (
'tcpdump',
'-X', # Print data and link level header in hex and ASCII
'-nn', # Don't resolve host addresses, etc.
'-tttt', # Print timestamps
'-r', self.path,
)
class PcapFile(File):
RE_FILE_TYPE = re.compile(r'^tcpdump capture file\b')
def compare_details(self, other, source=None):
return [Difference.from_command(
Tcpdump,
self.path,
other.path,
source='tcpdump',
)]
......@@ -192,6 +192,9 @@ EXTERNAL_TOOLS = {
'debian': 'tar',
'arch': 'tar',
},
'tcpdump': {
'debian': 'tcpdump',
},
'unsquashfs': {
'debian': 'squashfs-tools',
'arch': 'squashfs-tools',
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2017 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import pytest
from diffoscope.comparators.pcap import PcapFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist
from utils.nonexisting import assert_non_existing
pcap1 = load_fixture('test1.pcap')
pcap2 = load_fixture('test2.pcap')
def test_identification(pcap1):
assert isinstance(pcap1, PcapFile)
def test_no_differences(pcap1):
difference = pcap1.compare(pcap1)
assert difference is None
@pytest.fixture
def differences(pcap1, pcap2):
return pcap1.compare(pcap2).details
@skip_unless_tools_exist('tcpdump')
def test_diff(differences):
expected_diff = get_data('pcap_expected_diff')
assert differences[0].unified_diff == expected_diff
@skip_unless_tools_exist('tcpdump')
def test_compare_non_existing(monkeypatch, pcap1):
assert_non_existing(monkeypatch, pcap1, has_null_source=False)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment