From b5fb589361a7dd1e37da68e16e65ea7b37f00367 Mon Sep 17 00:00:00 2001 From: Pierre Lalet Date: Wed, 15 Dec 2021 16:01:25 +0100 Subject: [PATCH] Tests: fix IPv6 warnings from Scapy --- test/src/all.py | 22 ++++++++++++++++------ test/test_masscanned.py | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/test/src/all.py b/test/src/all.py index f9f2d80..761599e 100644 --- a/test/src/all.py +++ b/test/src/all.py @@ -15,6 +15,7 @@ # along with Masscanned. If not, see . import logging +from socket import AF_INET6 import struct from scapy.compat import raw @@ -29,6 +30,7 @@ from scapy.layers.inet6 import ( IPv6, ) from scapy.layers.l2 import ARP, Ether +from scapy.pton_ntop import inet_pton from scapy.packet import Raw from scapy.volatile import RandInt @@ -815,9 +817,12 @@ def test_ipv6_udp_stun(iface): assert ( tid == b"\x00" * 12 ), "expected tid 0x000000000000000000000000, got {:x}".format(tid) - assert data == bytes.fromhex("000100140002") + struct.pack( - ">H", sport - ) + bytes.fromhex("00000000" * 4), "unexpected data: {}".format(data) + expected_data = ( + bytes.fromhex("000100140002") + + struct.pack(">H", sport) + + inet_pton(AF_INET6, "2001:41d0::1234:5678") + ) + assert data == expected_data, "unexpected data: {}".format(data) @test @@ -898,9 +903,14 @@ def test_ipv6_udp_stun_change_port(iface): assert tid == bytes.fromhex("03a3b9464dd8eb75e19481474293845c"), ( "expected tid 0x03a3b9464dd8eb75e19481474293845c, got %r" % tid ) - assert data == bytes.fromhex("000100140002") + struct.pack( - ">H", sport - ) + bytes.fromhex("00000000" * 4) + expected_data = ( + bytes.fromhex("000100140002") + + struct.pack(">H", sport) + + inet_pton(AF_INET6, "2001:41d0::1234:5678") + ) + assert ( + data == expected_data + ), f"unexpected data {data!r} != {expected_data!r}" @test diff --git a/test/test_masscanned.py b/test/test_masscanned.py index 2697e46..a902cd9 100755 --- a/test/test_masscanned.py +++ b/test/test_masscanned.py @@ -68,9 +68,11 @@ conf.iface = resolve_iface(IFACE) # set interface subprocess.check_call(["ip", "addr", "add", "dev", IFACE, "192.0.0.0/31"]) +subprocess.check_call(["ip", "addr", "add", "dev", IFACE, "2001:41d0::1234:5678/96"]) subprocess.check_call(["ip", "link", "set", IFACE, "up"]) subprocess.check_call(["ip", "route", "add", "1.2.3.4/32", "via", IPV4_ADDR]) conf.route.resync() +conf.route6.resync() # start capture if TCPDUMP: