diff --git a/README.md b/README.md index c450cd4..c417efd 100755 --- a/README.md +++ b/README.md @@ -190,7 +190,6 @@ these dependencies, and when the `rns` package is installed with `pip`, they will be downloaded and installed as well. - [PyCA/cryptography](https://github.com/pyca/cryptography) -- [netifaces](https://github.com/al45tair/netifaces) - [pyserial](https://github.com/pyserial/pyserial) On more unusual systems, and in some rare cases, it might not be possible to diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 6e0da6d..4074c06 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -408,25 +408,15 @@ class TCPServerInterface(Interface): @staticmethod def get_address_for_if(name): - import importlib - if importlib.util.find_spec('netifaces') != None: - import netifaces - return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['addr'] - else: - RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL) - RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL) - RNS.panic() + import RNS.vendor.ifaddr.niwrapper as netinfo + ifaddr = netinfo.ifaddresses(name) + return ifaddr[netinfo.AF_INET][0]["addr"] @staticmethod def get_broadcast_for_if(name): - import importlib - if importlib.util.find_spec('netifaces') != None: - import netifaces - return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['broadcast'] - else: - RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL) - RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL) - RNS.panic() + import RNS.vendor.ifaddr.niwrapper as netinfo + ifaddr = netinfo.ifaddresses(name) + return ifaddr[netinfo.AF_INET][0]["broadcast"] def __init__(self, owner, name, device=None, bindip=None, bindport=None, i2p_tunneled=False): self.rxb = 0 diff --git a/RNS/Interfaces/UDPInterface.py b/RNS/Interfaces/UDPInterface.py index 17fd703..e2d8d57 100644 --- a/RNS/Interfaces/UDPInterface.py +++ b/RNS/Interfaces/UDPInterface.py @@ -34,25 +34,15 @@ class UDPInterface(Interface): @staticmethod def get_address_for_if(name): - import importlib - if importlib.util.find_spec('netifaces') != None: - import netifaces - return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['addr'] - else: - RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL) - RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL) - RNS.panic() + import RNS.vendor.ifaddr.niwrapper as netinfo + ifaddr = netinfo.ifaddresses(name) + return ifaddr[netinfo.AF_INET][0]["addr"] @staticmethod def get_broadcast_for_if(name): - import importlib - if importlib.util.find_spec('netifaces') != None: - import netifaces - return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['broadcast'] - else: - RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL) - RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL) - RNS.panic() + import RNS.vendor.ifaddr.niwrapper as netinfo + ifaddr = netinfo.ifaddresses(name) + return ifaddr[netinfo.AF_INET][0]["broadcast"] def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None): self.rxb = 0 diff --git a/RNS/vendor/ifaddr/niwrapper.py b/RNS/vendor/ifaddr/niwrapper.py index d6b189c..098b4f2 100644 --- a/RNS/vendor/ifaddr/niwrapper.py +++ b/RNS/vendor/ifaddr/niwrapper.py @@ -1,5 +1,4 @@ -# netifaces compatibility layer - +import ipaddress import ifaddr import socket @@ -22,7 +21,10 @@ def ifaddresses(ifname) -> dict: for ip in a.ips: t = {} if ip.is_IPv4: + net = ipaddress.ip_network(str(ip.ip)+"/"+str(ip.network_prefix), strict=False) t["addr"] = ip.ip + t["prefix"] = ip.network_prefix + t["broadcast"] = str(net.broadcast_address) ipv4s.append(t) if ip.is_IPv6: t["addr"] = ip.ip[0] diff --git a/RNS/vendor/ifaddr/test_ifaddr.py b/RNS/vendor/ifaddr/test_ifaddr.py deleted file mode 100644 index e0f6abb..0000000 --- a/RNS/vendor/ifaddr/test_ifaddr.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 2015 Stefan C. Mueller - -import unittest - -import pytest - -import ifaddr -import ifaddr.netifaces - - -try: - import netifaces -except ImportError: - skip_netifaces = True -else: - skip_netifaces = False - - -class TestIfaddr(unittest.TestCase): - """ - Unittests for :mod:`ifaddr`. - - There isn't much unit-testing that can be done without making assumptions - on the system or mocking of operating system APIs. So this just contains - a sanity check for the moment. - """ - - def test_get_adapters_contains_localhost(self) -> None: - - found = False - adapters = ifaddr.get_adapters() - for adapter in adapters: - for ip in adapter.ips: - if ip.ip == "127.0.0.1": - found = True - - self.assertTrue(found, "No adapter has IP 127.0.0.1: %s" % str(adapters)) - - -@pytest.mark.skipif(skip_netifaces, reason='netifaces not installed') -def test_netifaces_compatibility() -> None: - interfaces = ifaddr.netifaces.interfaces() - assert interfaces == netifaces.interfaces() - # TODO: implement those as well - # for interface in interfaces: - # print(interface) - # assert ifaddr.netifaces.ifaddresses(interface) == netifaces.ifaddresses(interface) - # assert ifaddr.netifaces.gateways() == netifaces.gateways() diff --git a/Roadmap.md b/Roadmap.md index 2524ad0..3d53488 100644 --- a/Roadmap.md +++ b/Roadmap.md @@ -38,7 +38,7 @@ These efforts are aimed at improving the ease of which Reticulum is understood, - Update NomadNet screenshots - Update Sideband screenshots - Installation - - Install docs for fedora, needs `python3-netifaces` + - Remove references to netifaces - Add a *Reticulum On Raspberry Pi* section - Update *Reticulum On Android* section if necessary - Update Android install documentation. diff --git a/docs/Reticulum Manual.epub b/docs/Reticulum Manual.epub index 3c73621..0d7b68f 100644 Binary files a/docs/Reticulum Manual.epub and b/docs/Reticulum Manual.epub differ diff --git a/docs/Reticulum Manual.pdf b/docs/Reticulum Manual.pdf index a7d2fdf..5b04c4e 100644 Binary files a/docs/Reticulum Manual.pdf and b/docs/Reticulum Manual.pdf differ diff --git a/setup.py b/setup.py index 6958a4a..35402c1 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ if pure_python: long_description = long_description.replace("

", "

"+pure_notice) else: pkg_name = "rns" - requirements = ['cryptography>=3.4.7', 'pyserial>=3.5', 'netifaces'] + requirements = ['cryptography>=3.4.7', 'pyserial>=3.5'] excluded_modules = exclude=["tests.*", "tests"] packages = setuptools.find_packages(exclude=excluded_modules)