chiark / gitweb /
zone.lisp: Stringify the zone name at construction time.
[zone] / addr-family-ipv6.lisp
index 4bec06cf21d0649a85f97cd1507ac54263b31d15..5ed014e22ac8f953366bb12a2bc212cfb073d6fd 100644 (file)
@@ -157,7 +157,8 @@ (defmethod ipaddr-string ((ip ip6addr))
 
     ;; Third step: output the two parts of the address either side of the
     ;; longest zero run.  If there are no zero words in the address, just
-    ;; write the whole thing.
+    ;; write the whole thing.  There's a special case here for the
+    ;; IPv6-mapped IPv4 address space ::ffff:0.0.0.0/96.
     (with-output-to-string (out)
       (flet ((chunk (start end)
               (when (< start end)
@@ -167,8 +168,19 @@ (defmethod ipaddr-string ((ip ip6addr))
                     (incf i)
                     (when (>= i end) (return))
                     (write-char #\: out))))))
-       (cond ((null best-start)
+       (cond ((< best-length 2)
               (chunk 0 8))
+             ((and (= best-start 0)
+                   (or (and (= best-length 5)
+                            (= (aref words 5) #xffff))
+                       (= best-length 6)))
+              (let ((v4addr (make-instance 'ip4addr
+                                           :addr (ldb (byte 32 0) addr))))
+                (write-string "::" out)
+                (when (= best-length 5)
+                  (chunk 5 6)
+                  (write-char #\: out))
+                (write-string (ipaddr-string v4addr) out)))
              (t
               (chunk 0 best-start)
               (write-string "::" out)