diff --git a/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c b/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c index c7d6df30c3..a773812763 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c +++ b/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c @@ -422,10 +422,10 @@ int light_get_next_packet(light_pcapng_t *pcapng, light_packet_header *packet_he timestamp = timestamp << 32; timestamp += epb->timestamp_low; uint64_t ticks_per_sec = pcapng->file_info->timestamp_ticks_per_second[epb->interface_id]; - uint64_t packet_secs = timestamp / ticks_per_sec; - uint64_t ticks = timestamp % ticks_per_sec; - if (packet_secs <= MAXIMUM_PACKET_SECONDS_VALUE) + uint64_t packet_secs = (ticks_per_sec != 0 ? timestamp / ticks_per_sec : 0); + if (packet_secs <= MAXIMUM_PACKET_SECONDS_VALUE && packet_secs != 0) { + uint64_t ticks = timestamp % ticks_per_sec; packet_header->timestamp.tv_sec = packet_secs; packet_header->timestamp.tv_nsec = (1000000000ul * ticks) / ticks_per_sec; } diff --git a/ci/run_tests/requirements.txt b/ci/run_tests/requirements.txt index b00a84e7ca..81360b1777 100644 --- a/ci/run_tests/requirements.txt +++ b/ci/run_tests/requirements.txt @@ -1 +1 @@ -netifaces==0.11.0 +scapy==2.5.0 diff --git a/ci/run_tests/run_tests.py b/ci/run_tests/run_tests.py index 43a938e8e0..efb2797675 100644 --- a/ci/run_tests/run_tests.py +++ b/ci/run_tests/run_tests.py @@ -1,7 +1,7 @@ import os import subprocess import argparse -import netifaces as ni +from scapy.all import get_if_addr PCAP_FILE_PATH = os.path.join("Tests", "Pcap++Test", "PcapExamples", "example.pcap") @@ -32,7 +32,8 @@ def main(): ) args = parser.parse_args() - ip_address = ni.ifaddresses(args.interface)[ni.AF_INET][0]["addr"] + ip_address = get_if_addr(args.interface) + print("IP address is: %s" % ip_address) try: diff --git a/ci/run_tests/run_tests_windows.py b/ci/run_tests/run_tests_windows.py index bba46d8ba3..e12d609b29 100644 --- a/ci/run_tests/run_tests_windows.py +++ b/ci/run_tests/run_tests_windows.py @@ -1,7 +1,8 @@ import os import argparse import subprocess -import netifaces as ni +import scapy.arch.windows +from ipaddress import IPv4Address TCPREPLAY_PATH = "tcpreplay-4.4.1-win" PCAP_FILE_PATH = os.path.abspath( @@ -9,6 +10,24 @@ ) +def validate_ipv4_address(address): + try: + IPv4Address(address) + return True + except ValueError: + return False + + +def get_ip_by_guid(guid): + interfaces = scapy.arch.windows.get_windows_if_list() + for iface in interfaces: + ips = iface.get("ips", []) + # Find the first valid IPv4 address inside iface["ips"]. If no address is found, return None + return next(filter(validate_ipv4_address, ips), None) + # Return None if no matching interface is found + return None + + def find_interface(): completed_process = subprocess.run( ["tcpreplay.exe", "--listnics"], @@ -26,8 +45,8 @@ def find_interface(): if len(columns) > 1 and columns[1].startswith("\\Device\\NPF_"): interface = columns[1] try: - ni_interface = interface.lstrip("\\Device\\NPF_") - ip_address = ni.ifaddresses(ni_interface)[ni.AF_INET][0]["addr"] + nic_guid = interface.lstrip("\\Device\\NPF_") + ip_address = get_ip_by_guid(nic_guid) if ip_address.startswith("169.254"): continue completed_process = subprocess.run(