Skip to content

Commit

Permalink
Added IPv6 Support
Browse files Browse the repository at this point in the history
Someone made a comment… I added it.
  • Loading branch information
n0mjs710 committed Jun 15, 2018
1 parent 01a3fff commit bc59c75
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions ipsc/dmrlink_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
###############################################################################
# Copyright (C) 2016 Cortney T. Buffington, N0MJS <[email protected]>
# Copyright (C) 2016-2018 Cortney T. Buffington, N0MJS <[email protected]>
#
# 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
Expand All @@ -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__ = '[email protected]'


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()

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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')
})

Expand Down

0 comments on commit bc59c75

Please sign in to comment.