diff --git a/src/main/java/eu/m724/autopeerer/client/PacketHandler.java b/src/main/java/eu/m724/autopeerer/client/PacketHandler.java index ed95c98..33180c2 100644 --- a/src/main/java/eu/m724/autopeerer/client/PacketHandler.java +++ b/src/main/java/eu/m724/autopeerer/client/PacketHandler.java @@ -81,7 +81,8 @@ public class PacketHandler { var status = PingResponsePacket.PingResponseStatus.ERROR; try { - Process process = Runtime.getRuntime().exec(new String[] { "ping", "-3Ac", "10", "-W", "1", packet.target.getHostAddress() }); + // -3 was also an arumetn but not wokring on all + Process process = Runtime.getRuntime().exec(new String[] { "ping", "-Ac", "10", "-W", "1", packet.target.getHostAddress() }); try (BufferedReader reader = process.inputReader()) { for (String l : reader.lines().toList()) { @@ -100,13 +101,21 @@ public class PacketHandler { } } - System.out.printf("Ping request #%d to %s - %s avg %.3f / mdev %.3f ms\n", packet.requestId, packet.target.getHostAddress(), status, average, meanDeviation); - Packets.send(new PingResponsePacket(packet.requestId, status, average, meanDeviation), outputStream); - } catch (IOException e) { - System.err.println("Error executing ping request"); - e.printStackTrace(); + var code = process.waitFor(); + if (code != 0) { + System.out.printf("ping returned " + code); + } + + } catch (IOException | InterruptedException e) { + System.err.println("Error executing ping request: " + e.getMessage()); } + System.out.printf("Ping request #%d to %s - %s avg %.3f / mdev %.3f ms\n", packet.requestId, packet.target.getHostAddress(), status, average, meanDeviation); + try { + Packets.send(new PingResponsePacket(packet.requestId, status, average, meanDeviation), outputStream); + } catch (IOException e) { + throw new RuntimeException(e); + } }); }