From 62c6be5c35da62c1809b217850c18b1e3abe47f1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 1 May 2020 06:03:02 -0700 Subject: sockets: bug in formatting ipv6 address. The str-in6addr and str-in6addr-net functions mishandle the zero address, rendering it as ":" instead of "::". * share/txr/stdlib/socket.tl (sys:in6addr-condensed-text): Test for the degenerate case and map it to "::" output. --- share/txr/stdlib/socket.tl | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/share/txr/stdlib/socket.tl b/share/txr/stdlib/socket.tl index 5f9d3d7c..2571aef1 100644 --- a/share/txr/stdlib/socket.tl +++ b/share/txr/stdlib/socket.tl @@ -62,17 +62,20 @@ `@a.@b.@c.@d@p`))) (defun sys:in6addr-condensed-text (numeric-pieces) - (let* ((notyet t) - (texts (window-mappend - 1 nil - (lambda (pre chunk post) - (cond - ((and notyet (zerop (car chunk)) (cdr chunk)) - (zap notyet) - (if (and post pre) '("") '(":"))) - (t (mapcar (op format nil "~x") chunk)))) - [partition-by zerop numeric-pieces]))) - `@{texts ":"}`)) + (let ((parted [partition-by zerop numeric-pieces])) + (if (or (cdr parted) (nzerop (caar parted))) + (let* ((notyet t) + (texts (window-mappend + 1 nil + (lambda (pre chunk post) + (cond + ((and notyet (zerop (car chunk)) (cdr chunk)) + (zap notyet) + (if (and post pre) '("") '(":"))) + (t (mapcar (op format nil "~x") chunk)))) + parted))) + `@{texts ":"}`) + "::"))) (defun str-in6addr (addr : port) (let ((str (if (and (<= (width addr) 48) -- cgit v1.2.3