From bc59c75eb09b6fa89352da23b7ff7972be20f937 Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Fri, 15 Jun 2018 12:14:10 -0500 Subject: [PATCH] Added IPv6 Support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Someone made a comment… I added it. --- ipsc/dmrlink_config.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ipsc/dmrlink_config.py b/ipsc/dmrlink_config.py index 2e3067b..47b150d 100755 --- a/ipsc/dmrlink_config.py +++ b/ipsc/dmrlink_config.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # ############################################################################### -# Copyright (C) 2016 Cortney T. Buffington, N0MJS +# Copyright (C) 2016-2018 Cortney T. Buffington, N0MJS # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,16 +21,32 @@ import ConfigParser import sys -from socket import gethostbyname +from socket import getaddrinfo, IPPROTO_UDP # Does anybody read this stuff? There's a PEP somewhere that says I should do this. __author__ = 'Cortney T. Buffington, N0MJS' -__copyright__ = 'Copyright (c) 2016 Cortney T. Buffington, N0MJS and the K0USY Group' +__copyright__ = 'Copyright (c) 2016-2018 Cortney T. Buffington, N0MJS and the K0USY Group' __license__ = 'GNU GPLv3' __maintainer__ = 'Cort Buffington, N0MJS' __email__ = 'n0mjs@me.com' +def get_address(_config): + ipv4 = '' + ipv6 = '' + socket_info = getaddrinfo(_config, None, 0, 0, IPPROTO_UDP) + for item in socket_info: + if item[0] == 2: + ipv4 = item[4][0] + elif item[0] == 30: + ipv6 = item[4][0] + + if ipv4: + return ipv4 + if ipv6: + return ipv6 + return 'invalid address' + def build_config(_config_file): config = ConfigParser.ConfigParser() @@ -115,7 +131,7 @@ def build_config(_config_file): # Things we need to know to connect and be a peer in this IPSC 'RADIO_ID': hex(int(config.get(section, 'RADIO_ID')))[2:].rjust(8,'0').decode('hex'), - 'IP': gethostbyname(config.get(section, 'IP')), + 'IP': config.get(section, 'IP'), 'PORT': config.getint(section, 'PORT'), 'ALIVE_TIMER': config.getint(section, 'ALIVE_TIMER'), 'MAX_MISSED': config.getint(section, 'MAX_MISSED'), @@ -144,7 +160,7 @@ def build_config(_config_file): }) if not CONFIG['SYSTEMS'][section]['LOCAL']['MASTER_PEER']: CONFIG['SYSTEMS'][section]['MASTER'].update({ - 'IP': gethostbyname(config.get(section, 'MASTER_IP')), + 'IP': get_address(config.get(section, 'MASTER_IP')), 'PORT': config.getint(section, 'MASTER_PORT') })