summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-05-01 06:03:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-05-01 06:03:02 -0700
commit9c32e8b4bd0e14a323597977ea7c9e5997a30e97 (patch)
tree6e4e532708fcbfb48fe9364c7254717532414972
parent1197e38c1a146d91eb0521e1b995e37bdb8c3fdc (diff)
downloadtxr-9c32e8b4bd0e14a323597977ea7c9e5997a30e97.tar.gz
txr-9c32e8b4bd0e14a323597977ea7c9e5997a30e97.tar.bz2
txr-9c32e8b4bd0e14a323597977ea7c9e5997a30e97.zip
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.
-rw-r--r--share/txr/stdlib/socket.tl25
1 files 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)