Use getaddrinfo to detect IP literals in client example
socket.inet_pton() is missing on some supported platforms (Python 2.7 on Windows). getaddrinfo() with AI_NUMERICHOST parses without resolving and is available everywhere. It also handles scoped IPv6 literals.pull/70/head
parent
0446e8c73f
commit
89f038ab7c
|
|
@ -132,13 +132,13 @@ def get_DTLSmethod(index):
|
|||
)[index]
|
||||
|
||||
def is_ip_literal(host):
|
||||
for family in (socket.AF_INET, socket.AF_INET6):
|
||||
try:
|
||||
socket.inet_pton(family, host)
|
||||
return True
|
||||
except (socket.error, ValueError):
|
||||
pass
|
||||
return False
|
||||
# AI_NUMERICHOST never resolves, it only parses. Unlike
|
||||
# socket.inet_pton() it is available on every supported platform.
|
||||
try:
|
||||
socket.getaddrinfo(host, None, 0, 0, 0, socket.AI_NUMERICHOST)
|
||||
return True
|
||||
except socket.error:
|
||||
return False
|
||||
|
||||
|
||||
def configure_verification(context, args):
|
||||
|
|
|
|||
Loading…
Reference in New Issue