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
8359bd0b
Commit
8359bd0b
authored
Jan 12, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed consts + test
parent
b2e23746
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
ip.go
ip.go
+7
-5
net_test.go
net_test.go
+15
-0
No files found.
ip.go
View file @
8359bd0b
...
...
@@ -57,7 +57,7 @@ func IsIPLoopback(m ma.Multiaddr) bool {
b
:=
m
.
Bytes
()
// /ip4/127 prefix (_entire_ /8 is loopback...)
if
bytes
.
HasPrefix
(
b
,
[]
byte
{
4
,
127
})
{
if
bytes
.
HasPrefix
(
b
,
[]
byte
{
ma
.
P_IP
4
,
127
})
{
return
true
}
...
...
@@ -69,10 +69,12 @@ func IsIPLoopback(m ma.Multiaddr) bool {
return
false
}
// IPV6 Link Local addresses are non routable.
func
IsIPV6LinkLocal
(
m
ma
.
Multiaddr
)
bool
{
b
:=
m
.
Bytes
()
return
bytes
.
HasPrefix
(
b
,
[]
byte
{
41
,
254
,
128
})
// IP6 Link Local addresses are non routable. The prefix is technically
// fe80::/10, but we test fe80::/12 for simplicity (no need to mask).
// So far, no hardware interfaces exist long enough to use those 2 bits.
// Send a PR if there is.
func
IsIP6LinkLocal
(
m
ma
.
Multiaddr
)
bool
{
return
bytes
.
HasPrefix
(
m
.
Bytes
(),
[]
byte
{
ma
.
P_IP6
,
0xfe
,
0x80
,
0
})
}
// IsIPUnspecified returns whether a Multiaddr is am Unspecified IP address
...
...
net_test.go
View file @
8359bd0b
...
...
@@ -2,6 +2,7 @@ package manet
import
(
"bytes"
"fmt"
"net"
"sync"
"testing"
...
...
@@ -334,3 +335,17 @@ func TestIPUnspecified(t *testing.T) {
t
.
Error
(
"IsIPUnspecified failed (IP6Unspecified)"
)
}
}
func
TestIP6LinkLocal
(
t
*
testing
.
T
)
{
if
!
IsIP6LinkLocal
(
IP6LinkLocalLoopback
)
{
t
.
Error
(
"IsIP6LinkLocal failed (IP6LinkLocalLoopback)"
)
}
for
a
:=
0
;
a
<
65536
;
a
++
{
isLinkLocal
:=
(
a
==
0xfe80
)
m
:=
newMultiaddr
(
t
,
fmt
.
Sprintf
(
"/ip6/%x::1"
,
a
))
if
IsIP6LinkLocal
(
m
)
!=
isLinkLocal
{
t
.
Error
(
"IsIP6LinkLocal failed (%s != %v)"
,
m
,
isLinkLocal
)
}
}
}
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