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
e67650e7
Unverified
Commit
e67650e7
authored
Oct 24, 2018
by
Steven Allen
Committed by
GitHub
Oct 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #48 from multiformats/fix/is-ip-starts-with
make the Is* commands only check if addrs start with
parents
4ae0494b
a7b912ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
19 deletions
+8
-19
ip.go
ip.go
+8
-11
net_test.go
net_test.go
+0
-8
No files found.
ip.go
View file @
e67650e7
...
...
@@ -55,19 +55,15 @@ func IsThinWaist(m ma.Multiaddr) bool {
}
}
// IsIPLoopback returns whether a Multiaddr
i
s a "Loopback" IP address
// This means either /ip4/127.*.*.*, /ip6/::1, or /ip6/::ffff:127.*.*.*.*,
// or /ip6zone/<any value>/ip6/<one of the preceding ip6 values>
// IsIPLoopback returns whether a Multiaddr s
tarts with
a "Loopback" IP address
// This means either /ip4/127.*.*.*
/*
, /ip6/::1
/*
, or /ip6/::ffff:127.*.*.*.*
/*
,
// or /ip6zone/<any value>/ip6/<one of the preceding ip6 values>
/*
func
IsIPLoopback
(
m
ma
.
Multiaddr
)
bool
{
m
=
zoneless
(
m
)
c
,
rest
:=
ma
.
SplitFirst
(
m
)
c
,
_
:=
ma
.
SplitFirst
(
m
)
if
c
==
nil
{
return
false
}
if
rest
!=
nil
{
// Not *just* an IPv4 addr
return
false
}
switch
c
.
Protocol
()
.
Code
{
case
ma
.
P_IP4
,
ma
.
P_IP6
:
return
net
.
IP
(
c
.
RawValue
())
.
IsLoopback
()
...
...
@@ -88,14 +84,15 @@ func IsIP6LinkLocal(m ma.Multiaddr) bool {
return
ip
.
IsLinkLocalMulticast
()
||
ip
.
IsLinkLocalUnicast
()
}
// IsIPUnspecified returns whether a Multiaddr
i
s a
m
Unspecified IP address
// This means either /ip4/0.0.0.0 or /ip6/::
// IsIPUnspecified returns whether a Multiaddr s
tarts with
a
n
Unspecified IP address
// This means either /ip4/0.0.0.0
/*
or /ip6/::
/*
func
IsIPUnspecified
(
m
ma
.
Multiaddr
)
bool
{
m
=
zoneless
(
m
)
if
m
==
nil
{
return
false
}
return
IP4Unspecified
.
Equal
(
m
)
||
IP6Unspecified
.
Equal
(
m
)
c
,
_
:=
ma
.
SplitFirst
(
m
)
return
net
.
IP
(
c
.
RawValue
())
.
IsUnspecified
()
}
// If m matches [zone,ip6,...], return [ip6,...]
...
...
net_test.go
View file @
e67650e7
...
...
@@ -330,10 +330,6 @@ func TestIPLoopback(t *testing.T) {
t
.
Error
(
"IsIPLoopback false positive (/ip4/112.123.11.1)"
)
}
if
IsIPLoopback
(
newMultiaddr
(
t
,
"/ip4/127.0.0.1/ip4/127.0.0.1"
))
{
t
.
Error
(
"IsIPLoopback false positive (/ip4/127.0.0.1/127.0.0.1)"
)
}
if
IsIPLoopback
(
newMultiaddr
(
t
,
"/ip4/192.168.0.1/ip6/::1"
))
{
t
.
Error
(
"IsIPLoopback false positive (/ip4/192.168.0.1/ip6/::1)"
)
}
...
...
@@ -362,10 +358,6 @@ func TestIPLoopback(t *testing.T) {
t
.
Error
(
"IsIPLoopback failed (/ip6zone/xxx/ip6/::1)"
)
}
if
IsIPLoopback
(
newMultiaddr
(
t
,
"/ip6zone/0/ip6/::1/tcp/3333"
))
{
t
.
Error
(
"IsIPLoopback failed (/ip6zone/0/ip6/::1/tcp/3333)"
)
}
if
IsIPLoopback
(
newMultiaddr
(
t
,
"/ip6zone/0/ip6/1::1"
))
{
t
.
Errorf
(
"IsIPLoopback false positive (/ip6zone/0/ip6/1::1)"
)
}
...
...
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