diff --git a/CHANGELOG.md b/CHANGELOG.md index a3cc7ac..f298183 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,12 @@ TODO - Why two arguments for bestMessage and bestPath for Result? The path should be in the message. - Create Result inside async traceroute, not outside. +### Changed + +- Bump jnb-ping to 3.0.0 and JPAN to 0.6.2-SNAPSHOT + [#20](https://github.com/netsec-ethz/scion-java-multiping/pull/20) + + ### Fixed - Fixed mangled output with mode SHOW_SCMP_ONLY diff --git a/README.md b/README.md index 3d509b2..c1e2bcb 100644 --- a/README.md +++ b/README.md @@ -169,3 +169,14 @@ the example works only for `ethz.ch`): ``` java -Dorg.scion.dnsSearchDomains=ethz.ch. -jar scion-multiping-0.6.1-executable.jar ``` + +## ICMP requires port access + +``` +# show group names +$ id -nG +# get a group id +$ getent group +# enable port +$ sudo sysctl net.ipv4.ping_group_range=' ' +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d0e51a..0224668 100644 --- a/pom.xml +++ b/pom.xml @@ -89,7 +89,7 @@ com.zaxxer jnb-ping - 1.3.2 + 3.0.0 diff --git a/src/main/java/org/scion/multiping/PingTest.java b/src/main/java/org/scion/multiping/PingTest.java new file mode 100644 index 0000000..624ae44 --- /dev/null +++ b/src/main/java/org/scion/multiping/PingTest.java @@ -0,0 +1,62 @@ +// Copyright 2025 ETH Zurich +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.scion.multiping; + +import com.zaxxer.ping.FailureReason; +import com.zaxxer.ping.IcmpPinger; +import com.zaxxer.ping.PingResponseHandler; +import com.zaxxer.ping.PingTarget; +import org.jetbrains.annotations.NotNull; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.UnknownHostException; + +import static org.scion.multiping.util.Util.*; + +public class PingTest { + public static void main(String[] args) throws UnknownHostException { + PingResponseHandler handler = + new PingResponseHandler() { + @Override + public void onFailure( + @NotNull PingTarget pingTarget, @NotNull FailureReason failureReason) { + System.out.println("ICMP failed: " + failureReason); + } + + @Override + public void onResponse(@NotNull PingTarget pingTarget, double v, int i, int i1) { + System.out.println("ICMP success: " + v + " " + i + " " + i1); + } + }; + + //InetAddress address1 = Inet4Address.getByAddress(new byte[]{1, 1, 1, 1}); + //InetAddress address = Inet4Address.getByAddress(new byte[]{130, 59, 44, 218}); + InetAddress address = Inet4Address.getByName("130.59.44.218"); + IcmpPinger pinger = new IcmpPinger(handler); + PingTarget target = new PingTarget(address); + Thread t = new Thread(pinger::runSelector); + t.start(); + // sleep(50); + + pinger.ping(target); + while (pinger.isPendingWork()) { + sleep(100); + } + pinger.stopSelector(); + + + } +} diff --git a/src/main/java/org/scion/multiping/util/ICMP.java b/src/main/java/org/scion/multiping/util/ICMP.java index 5b149e6..decec4e 100644 --- a/src/main/java/org/scion/multiping/util/ICMP.java +++ b/src/main/java/org/scion/multiping/util/ICMP.java @@ -14,10 +14,10 @@ package org.scion.multiping.util; -import static org.scion.multiping.util.Util.round; -import static org.scion.multiping.util.Util.sleep; +import static org.scion.multiping.util.Util.*; import com.google.common.util.concurrent.AtomicDouble; +import com.zaxxer.ping.FailureReason; import com.zaxxer.ping.IcmpPinger; import com.zaxxer.ping.PingResponseHandler; import com.zaxxer.ping.PingTarget; @@ -60,13 +60,17 @@ public static String pingICMP(InetAddress address, Config config) { PingResponseHandler handler = new PingResponseHandler() { @Override - public void onResponse(@NotNull PingTarget pingTarget, double v, int i, int i1) { - seconds.set(v); + public void onFailure( + @NotNull PingTarget pingTarget, @NotNull FailureReason failureReason) { + if (!FailureReason.TimedOut.equals(failureReason)) { + println("ICMP failed: " + failureReason); + } + seconds.set(-1); } @Override - public void onTimeout(@NotNull PingTarget pingTarget) { - seconds.set(-1); + public void onResponse(@NotNull PingTarget pingTarget, double v, int i, int i1) { + seconds.set(v); } }; @@ -74,6 +78,7 @@ public void onTimeout(@NotNull PingTarget pingTarget) { PingTarget target = new PingTarget(address); Thread t = new Thread(pinger::runSelector); t.start(); + sleep(50); nIcmpTried++; pinger.ping(target);