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
p2p
go-cidranger
Commits
4fbccda1
Commit
4fbccda1
authored
Jan 31, 2018
by
Rob Adams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add IP version check
parent
fec54c23
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
0 deletions
+5
-0
net/ip.go
net/ip.go
+3
-0
net/ip_test.go
net/ip_test.go
+2
-0
No files found.
net/ip.go
View file @
4fbccda1
...
...
@@ -210,6 +210,9 @@ func (n Network) Contains(nn NetworkNumber) bool {
// Contains returns true if Network covers o, false otherwise
func
(
n
Network
)
Covers
(
o
Network
)
bool
{
if
len
(
n
.
Number
)
!=
len
(
o
.
Number
)
{
return
false
}
nMaskSize
,
_
:=
n
.
IPNet
.
Mask
.
Size
()
oMaskSize
,
_
:=
o
.
IPNet
.
Mask
.
Size
()
return
n
.
Contains
(
o
.
Number
)
&&
nMaskSize
<=
oMaskSize
...
...
net/ip_test.go
View file @
4fbccda1
...
...
@@ -424,6 +424,8 @@ func TestNetworkCovers(t *testing.T) {
{
"10.0.0.0/16"
,
"10.0.0.0/15"
,
false
,
"prefix false"
},
{
"10.0.0.0/15"
,
"10.0.0.0/16"
,
true
,
"prefix true"
},
{
"10.0.0.0/15"
,
"10.0.0.0/15"
,
true
,
"same"
},
{
"10::0/15"
,
"10.0.0.0/15"
,
false
,
"ip version mismatch"
},
{
"10::0/15"
,
"10::0/16"
,
true
,
"ipv6"
},
}
for
_
,
tc
:=
range
cases
{
...
...
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