From 42de39c21dc234571b498ba4dd9dd0ab1a4d3f57 Mon Sep 17 00:00:00 2001 From: Ryan Sundberg Date: Tue, 17 Jan 2023 22:35:31 -0800 Subject: [PATCH 4/4] remote: support IPv6 publish urls When the server address is IPv6, build a compatible publish-url. * src/cuirass/remote.scm (ipv6-address?): New function (publish-url): Build IPv6 compatible URLs --- src/cuirass/remote.scm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cuirass/remote.scm b/src/cuirass/remote.scm index 44b342d..caec985 100644 --- a/src/cuirass/remote.scm +++ b/src/cuirass/remote.scm @@ -162,7 +162,11 @@ (define (publish-url address port) "Return the publish url at ADDRESS and PORT." - (string-append "http://" address ":" (number->string port))) + (format #f "http://~a:~d" + (if (ipv6-address? address) + (format #f "[~a]" address) + address) + port)) (define (avahi-service->params service) "Return the URL of the publish server corresponding to the service with the @@ -223,11 +227,15 @@ properties." #:verbosity 1 #:substitute-urls urls)) +(define (ipv6-address? address) + "Is ADDRESS an ipv6 address?" + (not (not (string-index address #\:)))) + (define (parse-host-address host) (cond ((not host) (values AF_INET PF_INET INADDR_ANY)) - ((string-index host #\:) + ((ipv6-address? host) (values AF_INET6 PF_INET6 (inet-pton AF_INET6 host))) (else (values AF_INET PF_INET (inet-pton AF_INET host))))) -- 2.37.2