Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
41068aa6
Commit
41068aa6
authored
Sep 30, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correctly format ip4-in-6 addresses
fixes part one of #77
parent
a80cfc33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
multiaddr_test.go
multiaddr_test.go
+1
-0
transcoders.go
transcoders.go
+12
-3
No files found.
multiaddr_test.go
View file @
41068aa6
...
...
@@ -451,6 +451,7 @@ func TestBinaryRepresentation(t *testing.T) {
func
TestRoundTrip
(
t
*
testing
.
T
)
{
for
_
,
s
:=
range
[]
string
{
"/unix/a/b/c/d"
,
"/ip6/::ffff:127.0.0.1/tcp/111"
,
"/ip4/127.0.0.1/tcp/123"
,
"/ip4/127.0.0.1/udp/123"
,
"/ip4/127.0.0.1/udp/123/ip6/::"
,
...
...
transcoders.go
View file @
41068aa6
...
...
@@ -46,8 +46,8 @@ func (t twrp) ValidateBytes(b []byte) error {
return
t
.
validbyte
(
b
)
}
var
TranscoderIP4
=
NewTranscoderFromFunctions
(
ip4StB
,
ipBtS
,
nil
)
var
TranscoderIP6
=
NewTranscoderFromFunctions
(
ip6StB
,
ipBtS
,
nil
)
var
TranscoderIP4
=
NewTranscoderFromFunctions
(
ip4StB
,
ip
4
BtS
,
nil
)
var
TranscoderIP6
=
NewTranscoderFromFunctions
(
ip6StB
,
ip
6
BtS
,
nil
)
var
TranscoderIP6Zone
=
NewTranscoderFromFunctions
(
ip6zoneStB
,
ip6zoneBtS
,
ip6zoneVal
)
func
ip4StB
(
s
string
)
([]
byte
,
error
)
{
...
...
@@ -88,7 +88,16 @@ func ip6StB(s string) ([]byte, error) {
return
i
,
nil
}
func
ipBtS
(
b
[]
byte
)
(
string
,
error
)
{
func
ip6BtS
(
b
[]
byte
)
(
string
,
error
)
{
ip
:=
net
.
IP
(
b
)
if
ip4
:=
ip
.
To4
();
ip4
!=
nil
{
// Go fails to prepend the `::ffff:` part.
return
"::ffff:"
+
ip4
.
String
(),
nil
}
return
ip
.
String
(),
nil
}
func
ip4BtS
(
b
[]
byte
)
(
string
,
error
)
{
return
net
.
IP
(
b
)
.
String
(),
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment