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
20cc417a
Commit
20cc417a
authored
Nov 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added ipv6 link-local loopback
parent
4489dfa8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
net/convert.go
net/convert.go
+17
-1
net/net_test.go
net/net_test.go
+10
-2
No files found.
net/convert.go
View file @
20cc417a
package
manet
import
(
"bytes"
"fmt"
"net"
"strings"
...
...
@@ -14,6 +15,9 @@ var (
// IP6Loopback is the ip6 loopback multiaddr
IP6Loopback
=
ma
.
StringCast
(
"/ip6/::1"
)
// IP6LinkLocalLoopback is the ip6 link-local loopback multiaddr
IP6LinkLocalLoopback
=
ma
.
StringCast
(
"/ip6/fe80::1"
)
)
var
errIncorrectNetAddr
=
fmt
.
Errorf
(
"incorrect network addr conversion"
)
...
...
@@ -169,5 +173,17 @@ func IsThinWaist(m ma.Multiaddr) bool {
// IsIPLoopback returns whether a Multiaddr is a "Loopback" IP address
// This means either /ip4/127.0.0.1 or /ip6/::1
func
IsIPLoopback
(
m
ma
.
Multiaddr
)
bool
{
return
m
.
Equal
(
IP4Loopback
)
||
m
.
Equal
(
IP6Loopback
)
b
:=
m
.
Bytes
()
// /ip4/127 prefix (_entire_ /8 is loopback...)
if
bytes
.
HasPrefix
(
b
,
[]
byte
{
4
,
127
})
{
return
true
}
// /ip6/::1
if
IP6Loopback
.
Equal
(
m
)
||
IP6LinkLocalLoopback
.
Equal
(
m
)
{
return
true
}
return
false
}
net/net_test.go
View file @
20cc417a
...
...
@@ -208,11 +208,19 @@ func TestLoopback(t *testing.T) {
t
.
Error
(
"IP6Loopback incorrect:"
,
IP6Loopback
)
}
if
IP6LinkLocalLoopback
.
String
()
!=
"/ip6/fe80::1"
{
t
.
Error
(
"IP6LinkLocalLoopback incorrect:"
,
IP6Loopback
)
}
if
!
IsIPLoopback
(
IP4Loopback
)
{
t
.
Error
(
"IsIPLoopback failed (IP4)"
)
t
.
Error
(
"IsIPLoopback failed (IP4
Loopback
)"
)
}
if
!
IsIPLoopback
(
IP6Loopback
)
{
t
.
Error
(
"IsIPLoopback failed (IP6)"
)
t
.
Error
(
"IsIPLoopback failed (IP6Loopback)"
)
}
if
!
IsIPLoopback
(
IP6LinkLocalLoopback
)
{
t
.
Error
(
"IsIPLoopback failed (IP6LinkLocalLoopback)"
)
}
}
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