summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2013-02-27 19:54:22 -0800
committerJeff Forcier <jeff@bitprophet.org>2013-02-27 19:54:22 -0800
commit3563fca9942a752697cb17af71b179c4f6cc4361 (patch)
treec61a32f52ce4934923fcb36eb0da4d1e5bd020fc
parentb9242c654abd3ec5137f482436f57a306b151573 (diff)
Refactor duplicative code re #110
-rw-r--r--paramiko/config.py26
1 files changed, 9 insertions, 17 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index 2782b6ab..a0805332 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -25,6 +25,7 @@ import os
import re
import socket
+
SSH_PORT = 22
proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I)
@@ -48,30 +49,21 @@ class LazyFqdn(object):
# IPv4 and IPv6 are checked.
#
+ # Handle specific option
address_family = self.config.get('addressfamily', 'any').lower()
-
- if address_family == 'inet':
- ipv4_results = socket.getaddrinfo(host, None, socket.AF_INET,
- socket.SOCK_DGRAM, socket.IPPROTO_IP,
- socket.AI_CANONNAME)
- for res in ipv4_results:
+ if address_family != 'any':
+ family = socket.AF_INET if address_family == 'inet' else socket.AF_INET6
+ results = socket.getaddrinfo(host, None, family,
+ socket.SOCK_DGRAM, socket.IPPROTO_IP, socket.AI_CANONNAME)
+ for res in results:
af, socktype, proto, canonname, sa = res
if canonname and '.' in canonname:
fqdn = canonname
break
- elif address_family == 'inet6':
- ipv6_results = socket.getaddrinfo(host, None, socket.AF_INET6,
- socket.SOCK_DGRAM,
- socket.IPPROTO_IP,
- socket.AI_CANONNAME)
- for res in ipv6_results:
- af, socktype, proto, canonname, sa = res
- if canonname and '.' in canonname:
- fqdn = canonname
- break
-
+ # Handle 'any' / unspecified
if fqdn is None:
fqdn = socket.getfqdn()
+ # Cache
self.fqdn = fqdn
return self.fqdn