From f55004a574aecd11f31e2d0a54bca11c70db9934 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 3 Nov 2024 17:54:59 +0200 Subject: [PATCH] Allow binding to IPv6 (if present) If an interface has an IPv6 address record associated with it then, and only then, prefer that. Otherwise AF_INET is used (Ipv4 address) --- RNS/Interfaces/TCPInterface.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RNS/Interfaces/TCPInterface.py b/RNS/Interfaces/TCPInterface.py index 54eadb0..2c6a036 100644 --- a/RNS/Interfaces/TCPInterface.py +++ b/RNS/Interfaces/TCPInterface.py @@ -412,6 +412,11 @@ class TCPServerInterface(Interface): def get_address_for_if(name): import RNS.vendor.ifaddr.niwrapper as netinfo ifaddr = netinfo.ifaddresses(name) + + # IPv6 preference (if present) + if(netinfo.AF_INET6 in ifaddr): + return ifaddr[netinfo.AF_INET6][0]["addr"] + return ifaddr[netinfo.AF_INET][0]["addr"] @staticmethod