Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
floodlight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
croft1
floodlight
Commits
76671f15
Commit
76671f15
authored
12 years ago
by
Alex Reimers
Browse files
Options
Downloads
Patches
Plain Diff
IPv4.java - Add static method for IPv4 from int to byte[].
parent
0f825d26
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
src/main/java/net/floodlightcontroller/packet/IPv4.java
+17
-3
17 additions, 3 deletions
src/main/java/net/floodlightcontroller/packet/IPv4.java
src/test/java/net/floodlightcontroller/packet/IPv4Test.java
+7
-2
7 additions, 2 deletions
src/test/java/net/floodlightcontroller/packet/IPv4Test.java
with
24 additions
and
5 deletions
src/main/java/net/floodlightcontroller/packet/IPv4.java
+
17
−
3
View file @
76671f15
...
...
@@ -456,9 +456,9 @@ public class IPv4 extends BasePacket {
/**
* Accepts an IPv4 address of the form xxx.xxx.xxx.xxx, ie 192.168.0.1 and
* returns the corresponding byte array
* @param ipAddress
* @return
* returns the corresponding byte array
.
* @param ipAddress
The IP address in the form xx.xxx.xxx.xxx.
* @return
The IP address separated into bytes
*/
public
static
byte
[]
toIPv4AddressBytes
(
String
ipAddress
)
{
String
[]
octets
=
ipAddress
.
split
(
"\\."
);
...
...
@@ -472,6 +472,20 @@ public class IPv4 extends BasePacket {
}
return
result
;
}
/**
* Accepts an IPv4 address in the form of an integer and
* returns the corresponding byte array.
* @param ipAddress The IP address as an integer.
* @return The IP address separated into bytes.
*/
public
static
byte
[]
toIPv4AddressBytes
(
int
ipAddress
)
{
return
new
byte
[]
{
(
byte
)(
ipAddress
>>>
24
),
(
byte
)(
ipAddress
>>>
16
),
(
byte
)(
ipAddress
>>>
8
),
(
byte
)
ipAddress
};
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
...
...
This diff is collapsed.
Click to expand it.
src/test/java/net/floodlightcontroller/packet/IPv4Test.java
+
7
−
2
View file @
76671f15
...
...
@@ -35,8 +35,13 @@ import org.junit.Test;
public
class
IPv4Test
{
@Test
public
void
testToIPv4Address
()
{
int
expected
=
0xc0a80001
;
assertEquals
(
expected
,
IPv4
.
toIPv4Address
(
"192.168.0.1"
));
int
intIp
=
0xc0a80001
;
String
stringIp
=
"192.168.0.1"
;
byte
[]
byteIp
=
new
byte
[]
{(
byte
)
192
,
(
byte
)
168
,
(
byte
)
0
,
(
byte
)
1
};
assertEquals
(
intIp
,
IPv4
.
toIPv4Address
(
stringIp
));
assertEquals
(
intIp
,
IPv4
.
toIPv4Address
(
byteIp
));
assertTrue
(
Arrays
.
equals
(
byteIp
,
IPv4
.
toIPv4AddressBytes
(
intIp
)));
assertTrue
(
Arrays
.
equals
(
byteIp
,
IPv4
.
toIPv4AddressBytes
(
stringIp
)));
}
@Test
...
...
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