From af966734586e49709b168190893ecdf3cbbc9677 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sun, 24 Jan 2010 15:57:06 -0600 Subject: [PATCH] Better fix for ipv6 --- basis/io/sockets/sockets-tests.factor | 3 +++ basis/io/sockets/sockets.factor | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/basis/io/sockets/sockets-tests.factor b/basis/io/sockets/sockets-tests.factor index 5f6071b8ae..96ffbc5e18 100644 --- a/basis/io/sockets/sockets-tests.factor +++ b/basis/io/sockets/sockets-tests.factor @@ -52,6 +52,9 @@ io.streams.string ; [ B{ 0 0 0 0 0 0 0 0 0 127 0 0 0 0 0 1 } ] [ "::127.0.0.1" T{ inet6 } inet-pton ] unit-test +[ B{ 0 2 0 0 0 0 0 9 0 127 0 0 0 0 0 1 } ] +[ "2::9:127.0.0.1" T{ inet6 } inet-pton ] unit-test + [ "2001:6f8:37a:5:0:0:0:1" ] [ "2001:6f8:37a:5::1" T{ inet6 } [ inet-pton ] [ inet-ntop ] bi ] unit-test diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index 465813a711..59d12f95bc 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -120,19 +120,16 @@ ERROR: bad-ipv6-component obj ; ERROR: bad-ipv4-embedded-prefix obj ; -: ensure-zero-prefix ( seq -- seq ) - dup [ hex> ] map - [ { f 0 } swap member? ] all? [ bad-ipv4-embedded-prefix ] unless ; +: parse-ipv6-component ( seq -- seq' ) + [ dup hex> [ nip ] [ bad-ipv6-component ] if* ] { } map-as ; : parse-inet6 ( string -- seq ) [ f ] [ ":" split CHAR: . over last member? [ unclip-last - [ ensure-zero-prefix drop ] [ parse-inet4 ] bi* + [ parse-ipv6-component ] [ parse-inet4 ] bi* append ] [ - [ - dup hex> [ nip ] [ bad-ipv6-component ] if* - ] { } map-as + parse-ipv6-component ] if ] if-empty ;