X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/067aa5f013dd6108e81c1df0c2ed19491802bc69..4a3882945f605704ede113a9fe98cd19a92363a7:/mon/tripemon.in diff --git a/mon/tripemon.in b/mon/tripemon.in index 8666575a..11ee6dc0 100644 --- a/mon/tripemon.in +++ b/mon/tripemon.in @@ -323,13 +323,19 @@ class Peer (MonitorObject): def _setaddr(me, addr): """Set the peer's address.""" - if addr[0] == 'INET': - ipaddr, port = addr[1:] + if addr[0] in ['INET', 'INET6']: + af, ipaddr, port = addr try: - name = S.gethostbyaddr(ipaddr)[0] - me.addr = 'INET %s:%s [%s]' % (name, port, ipaddr) - except S.herror: - me.addr = 'INET %s:%s' % (ipaddr, port) + name, _ = S.getnameinfo((ipaddr, int(port)), + S.NI_NUMERICSERV | S.NI_NAMEREQD) + except S.gaierror: + me.addr = '%s %s%s%s:%s' % (af, + af == 'INET6' and '[' or '', + ipaddr, + af == 'INET6' and ']' or '', + port) + else: + me.addr = '%s %s:%s [%s]' % (af, name, port, ipaddr) else: me.addr = ' '.join(addr) @@ -1042,6 +1048,8 @@ class AddPeerDialog (MyDialog): * e_name, e_addr, e_port, c_keepalive, l_tunnel: widgets in the dialog """ + AFS = ['ANY', 'INET', 'INET6'] + def __init__(me): """Initialize the dialogue.""" MyDialog.__init__(me, 'Add peer', @@ -1057,8 +1065,13 @@ class AddPeerDialog (MyDialog): me.e_name = table.labelled('Name', ValidatingEntry(r'^[^\s:]+$', '', 16), width = 3) + me.l_af = table.labelled('Family', combo_box_text(), + newlinep = True, width = 3) + for af in me.AFS: + me.l_af.append_text(af) + me.l_af.set_active(0) me.e_addr = table.labelled('Address', - ValidatingEntry(r'^[a-zA-Z0-9.-]+$', '', 24), + ValidatingEntry(r'^[a-zA-Z0-9.-:]+$', '', 24), newlinep = True) me.e_port = table.labelled('Port', ValidatingEntry(numericvalidate(0, 65535), @@ -1110,7 +1123,9 @@ class AddPeerDialog (MyDialog): """Handle an OK press: create the peer.""" try: t = me.l_tunnel.get_active() + afix = me.l_af.get_active() me._addpeer(me.e_name.get_text(), + me.AFS[afix], me.e_addr.get_text(), me.e_port.get_text(), keepalive = (me.c_keepalive.get_active() and