Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
6b9cdaff
Commit
6b9cdaff
authored
6 years ago
by
Daniel Czerwonk
Browse files
Options
Downloads
Patches
Plain Diff
removed ToUint32
parent
f88c87e5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
net/ip.go
+1
-6
1 addition, 6 deletions
net/ip.go
net/ip_test.go
+0
-28
0 additions, 28 deletions
net/ip_test.go
with
1 addition
and
34 deletions
net/ip.go
+
1
−
6
View file @
6b9cdaff
...
@@ -41,11 +41,6 @@ func IPv6FromBlocks(b1, b2, b3, b4, b5, b6, b7, b8 uint16) IP {
...
@@ -41,11 +41,6 @@ func IPv6FromBlocks(b1, b2, b3, b4, b5, b6, b7, b8 uint16) IP {
uint64
(
uint64
(
b5
)
<<
48
+
uint64
(
b6
)
<<
32
+
uint64
(
b7
)
<<
16
+
uint64
(
b8
)))
uint64
(
uint64
(
b5
)
<<
48
+
uint64
(
b6
)
<<
32
+
uint64
(
b7
)
<<
16
+
uint64
(
b8
)))
}
}
// ToUint32 returns the uint32 representation of an IP address
func
(
ip
*
IP
)
ToUint32
()
uint32
{
return
uint32
(
^
uint64
(
0
)
>>
32
&
ip
.
lower
)
}
// Equal returns true if ip is equal to other
// Equal returns true if ip is equal to other
func
(
ip
IP
)
Equal
(
other
IP
)
bool
{
func
(
ip
IP
)
Equal
(
other
IP
)
bool
{
return
ip
==
other
return
ip
==
other
...
@@ -110,7 +105,7 @@ func (ip IP) Bytes() []byte {
...
@@ -110,7 +105,7 @@ func (ip IP) Bytes() []byte {
}
}
func
(
ip
IP
)
bytesIPv4
()
[]
byte
{
func
(
ip
IP
)
bytesIPv4
()
[]
byte
{
u
:=
ip
.
ToUint32
(
)
u
:=
uint32
(
^
uint64
(
0
)
>>
32
&
ip
.
lower
)
return
[]
byte
{
return
[]
byte
{
byte
(
u
&
0xFF000000
>>
24
),
byte
(
u
&
0xFF000000
>>
24
),
byte
(
u
&
0x00FF0000
>>
16
),
byte
(
u
&
0x00FF0000
>>
16
),
...
...
This diff is collapsed.
Click to expand it.
net/ip_test.go
+
0
−
28
View file @
6b9cdaff
...
@@ -8,34 +8,6 @@ import (
...
@@ -8,34 +8,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)
)
func
TestToUint32
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
val
uint64
expected
uint32
}{
{
name
:
"IP: 172.24.5.1"
,
val
:
2887255297
,
expected
:
2887255297
,
},
{
name
:
"bigger than IPv4 address"
,
val
:
2887255295
+
17179869184
,
expected
:
2887255295
,
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
ip
:=
IP
{
lower
:
test
.
val
,
}
assert
.
Equal
(
t
,
test
.
expected
,
ip
.
ToUint32
())
})
}
}
func
TestCompare
(
t
*
testing
.
T
)
{
func
TestCompare
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment