Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rosjava Core Gradle
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
CeTI
ROS
ROS Java Packages
Rosjava Core Gradle
Commits
4b6df3d9
Commit
4b6df3d9
authored
11 years ago
by
damonkohler
Browse files
Options
Downloads
Plain Diff
Merge pull request #180 from tulku/networkinterface
Adds newNonLoopbackForNetworkInterface
parents
bbdf1ae8
4500f7dd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
rosjava/src/main/java/org/ros/address/InetAddressFactory.java
+13
-4
13 additions, 4 deletions
...ava/src/main/java/org/ros/address/InetAddressFactory.java
with
13 additions
and
4 deletions
rosjava/src/main/java/org/ros/address/InetAddressFactory.java
+
13
−
4
View file @
4b6df3d9
...
@@ -25,6 +25,7 @@ import java.net.InetAddress;
...
@@ -25,6 +25,7 @@ import java.net.InetAddress;
import
java.net.NetworkInterface
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
...
@@ -63,8 +64,8 @@ public class InetAddressFactory {
...
@@ -63,8 +64,8 @@ public class InetAddressFactory {
return
inetAddresses
;
return
inetAddresses
;
}
}
p
ublic
static
InetAddress
newNonLoopback
(
)
{
p
rivate
static
InetAddress
filterInetAddresses
(
Collection
<
InetAddress
>
inetAddresses
)
{
for
(
InetAddress
address
:
getAllI
netAddresses
()
)
{
for
(
InetAddress
address
:
i
netAddresses
)
{
// IPv4 only for now.
// IPv4 only for now.
if
(!
address
.
isLoopbackAddress
()
&&
isIpv4
(
address
))
{
if
(!
address
.
isLoopbackAddress
()
&&
isIpv4
(
address
))
{
return
address
;
return
address
;
...
@@ -73,7 +74,15 @@ public class InetAddressFactory {
...
@@ -73,7 +74,15 @@ public class InetAddressFactory {
throw
new
RosRuntimeException
(
"No non-loopback interface found."
);
throw
new
RosRuntimeException
(
"No non-loopback interface found."
);
}
}
private
static
Collection
<
InetAddress
>
getAllInetAddressByName
(
String
host
)
{
public
static
InetAddress
newNonLoopback
()
{
return
filterInetAddresses
(
getAllInetAddresses
());
}
public
static
InetAddress
newNonLoopbackForNetworkInterface
(
NetworkInterface
networkInterface
)
{
return
filterInetAddresses
(
Collections
.
list
(
networkInterface
.
getInetAddresses
()));
}
private
static
Collection
<
InetAddress
>
getAllInetAddressesByName
(
String
host
)
{
InetAddress
[]
allAddressesByName
;
InetAddress
[]
allAddressesByName
;
try
{
try
{
allAddressesByName
=
org
.
xbill
.
DNS
.
Address
.
getAllByName
(
host
);
allAddressesByName
=
org
.
xbill
.
DNS
.
Address
.
getAllByName
(
host
);
...
@@ -117,7 +126,7 @@ public class InetAddressFactory {
...
@@ -117,7 +126,7 @@ public class InetAddressFactory {
}
catch
(
UnknownHostException
e
)
{
}
catch
(
UnknownHostException
e
)
{
throw
new
RosRuntimeException
(
e
);
throw
new
RosRuntimeException
(
e
);
}
}
Collection
<
InetAddress
>
allAddressesByName
=
getAllInetAddressByName
(
host
);
Collection
<
InetAddress
>
allAddressesByName
=
getAllInetAddress
es
ByName
(
host
);
// First, try to find a non-loopback IPv4 address.
// First, try to find a non-loopback IPv4 address.
for
(
InetAddress
address
:
allAddressesByName
)
{
for
(
InetAddress
address
:
allAddressesByName
)
{
if
(!
address
.
isLoopbackAddress
()
&&
isIpv4
(
address
))
{
if
(!
address
.
isLoopbackAddress
()
&&
isIpv4
(
address
))
{
...
...
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