From d3125d9a8f1c74ba904fd0d06910ed9fad2dcb31 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 15 Jun 2018 02:43:33 -0700 Subject: [PATCH] core: automatically detect between IPv4 / IPv6 addresses on connect Closes #212. --- classes.py | 5 +++-- example-conf.yml | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/classes.py b/classes.py index cda0ab7..9bfb086 100644 --- a/classes.py +++ b/classes.py @@ -1660,8 +1660,9 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): ip = self.serverdata["ip"] port = self.serverdata["port"] try: - # Set the socket type (IPv6 or IPv4). - stype = socket.AF_INET6 if self.serverdata.get("ipv6") else socket.AF_INET + # Set the socket type (IPv6 or IPv4), auto detecting it if not specified. + isipv6 = self.serverdata.get("ipv6", utils.get_hostname_type(ip) == 2) + stype = socket.AF_INET6 if isipv6 else socket.AF_INET # Creat the socket. self._socket = socket.socket(stype) diff --git a/example-conf.yml b/example-conf.yml index be245f9..01a6043 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -243,8 +243,10 @@ servers: # Determines whether IPv6 should be used for this connection. Should the ip: # above be a hostname instead of an IP, this will also affect whether A records - # (no IPv6) or AAAA records (IPv6) will be used in resolving it. - ipv6: yes + # (IPv4) or AAAA records (IPv6) will be used in resolving it. + # As of PyLink 2.0-alpha4, you can leave this unset for direct connections to IP addresses; + # the address type will be automatically detected. + #ipv6: yes # Received and sent passwords. For passwordless links using SSL fingerprints, simply set # these two fields to "*" and enable SSL with a cert and key file.