From 89f038ab7ca0c56539d2c02f499dc91bdd02a148 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 13 Jul 2026 17:53:14 +0000 Subject: [PATCH] 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. --- examples/client.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/client.py b/examples/client.py index 21f7454..b9d5351 100755 --- a/examples/client.py +++ b/examples/client.py @@ -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):