public void send(NativeDatagramSocket socket, InetAddress addr) { socket.send(toDatagramPacket(addr)); } }
private static String getImplementationClassName(int family) { return NativeDatagramSocket.getClassPackage()+ "."+ NativeDatagramSocket.getClassPrefix()+ NativeDatagramSocket.getFamilyPrefix(family)+ "NativeSocket"; }
public static NativeDatagramSocket create(int family, int type, int protocol) throws Exception { String implClassName = NativeDatagramSocket.getImplementationClassName(family); System.err.println(String.format("%s(%d, %d, %d)", implClassName, family, type, protocol)); Class<? extends NativeDatagramSocket> implementationClass = Class.forName(implClassName).asSubclass(NativeDatagramSocket.class); return implementationClass.getDeclaredConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(family, type, protocol); }
public V4Pinger(final int pingerId) throws Exception { super(pingerId, NativeDatagramSocket.create(NativeDatagramSocket.PF_INET, NativeDatagramSocket.IPPROTO_ICMP, pingerId)); // Windows requires at least one packet sent before a receive call can be made without error // so we send a packet here to make sure... This one should not match the normal ping requests // since it does not contain the cookie so it won't interface. if (Platform.isWindows()) { final ICMPEchoPacket packet = new ICMPEchoPacket(64); packet.setCode(0); packet.setType(Type.EchoRequest); packet.getContentBuffer().putLong(System.nanoTime()); packet.getContentBuffer().putLong(System.nanoTime()); getPingSocket().send(packet.toDatagramPacket(InetAddress.getLocalHost())); } }
public void dump() throws Exception { NativeDatagramSocket m_pingSocket = NativeDatagramSocket.create(NativeDatagramSocket.PF_INET6, NativeDatagramSocket.IPPROTO_ICMPV6, 1234); if (Platform.isWindows()) { ICMPv6EchoPacket packet = new ICMPv6EchoPacket(64); packet.setCode(0); packet.setType(Type.EchoRequest); packet.getContentBuffer().putLong(System.nanoTime()); packet.getContentBuffer().putLong(System.nanoTime()); m_pingSocket.send(packet.toDatagramPacket(InetAddress.getByName("::1"))); } try { NativeDatagramPacket datagram = new NativeDatagramPacket(65535); while (true) { m_pingSocket.receive(datagram); System.err.println(datagram); } } catch(Throwable e) { e.printStackTrace(); } }
@Override public void run() { try { final NativeDatagramPacket datagram = new NativeDatagramPacket(65535); while (!isFinished()) { getPingSocket().receive(datagram); final long received = System.nanoTime(); final ICMPv6Packet icmpPacket = new ICMPv6Packet(getIPPayload(datagram)); final V6PingReply echoReply = icmpPacket.getType() == Type.EchoReply ? new V6PingReply(icmpPacket, received) : null; if (echoReply != null && echoReply.isValid()) { // 64 bytes from 127.0.0.1: icmp_seq=0 time=0.069 ms System.out.printf("%d bytes from [%s]: tid=%d icmp_seq=%d time=%.3f ms%n", echoReply.getPacketLength(), datagram.getAddress().getHostAddress(), echoReply.getIdentifier(), echoReply.getSequenceNumber(), echoReply.elapsedTime(TimeUnit.MILLISECONDS) ); for (PingReplyListener listener : getListeners()) { listener.onPingReply(datagram.getAddress(), echoReply); } } } } catch(final Throwable e) { m_throwable.set(e); e.printStackTrace(); } }
public void closeSocket() { if (getPingSocket() != null) { getPingSocket().close(); } }
public void setAllowFragmentation(boolean allow) throws IOException { if (m_v4 != null) m_v4.getPingSocket().allowFragmentation(allow); if (m_v6 != null) m_v6.getPingSocket().allowFragmentation(allow); }
public V6Pinger(int id) throws Exception { super(NativeDatagramSocket.create(NativeDatagramSocket.PF_INET6, NativeDatagramSocket.IPPROTO_ICMPV6, id)); // Windows requires at least one packet sent before a receive call can be made without error // so we send a packet here to make sure... This one should not match the normal ping requests // since it does not contain the cookie so it won't interface. if (Platform.isWindows()) { final ICMPv6EchoPacket packet = new ICMPv6EchoPacket(64); packet.setCode(0); packet.setType(Type.EchoRequest); packet.getContentBuffer().putLong(System.nanoTime()); packet.getContentBuffer().putLong(System.nanoTime()); getPingSocket().send(packet.toDatagramPacket(InetAddress.getByName("::1"))); } }
public void dump() throws Exception { NativeDatagramSocket m_pingSocket = NativeDatagramSocket.create(NativeDatagramSocket.PF_INET6, NativeDatagramSocket.IPPROTO_ICMPV6, 1234); if (Platform.isWindows()) { ICMPv6EchoPacket packet = new ICMPv6EchoPacket(64); packet.setCode(0); packet.setType(Type.EchoRequest); packet.getContentBuffer().putLong(System.nanoTime()); packet.getContentBuffer().putLong(System.nanoTime()); m_pingSocket.send(packet.toDatagramPacket(InetAddress.getByName("::1"))); } try { NativeDatagramPacket datagram = new NativeDatagramPacket(65535); while (true) { m_pingSocket.receive(datagram); System.err.println(datagram); } } catch(Throwable e) { e.printStackTrace(); } }
public void run() { try { NativeDatagramPacket datagram = new NativeDatagramPacket(65535); while (!isFinished()) { getPingSocket().receive(datagram); long received = System.nanoTime(); ICMPv6Packet icmpPacket = new ICMPv6Packet(getIPPayload(datagram)); V6PingReply echoReply = icmpPacket.getType() == Type.EchoReply ? new V6PingReply(icmpPacket, received) : null; if (echoReply != null && echoReply.isValid()) { // 64 bytes from 127.0.0.1: icmp_seq=0 time=0.069 ms System.out.printf("%d bytes from [%s]: tid=%d icmp_seq=%d time=%.3f ms\n", echoReply.getPacketLength(), datagram.getAddress().getHostAddress(), echoReply.getIdentifier(), echoReply.getSequenceNumber(), echoReply.elapsedTime(TimeUnit.MILLISECONDS) ); for (PingReplyListener listener : getListeners()) { listener.onPingReply(datagram.getAddress(), echoReply); } } } } catch(Throwable e) { m_throwable.set(e); e.printStackTrace(); } }
public void closeSocket() { if (getPingSocket() != null) { getPingSocket().close(); } }
public V6Pinger(final int pingerId) throws Exception { super(pingerId, NativeDatagramSocket.create(NativeDatagramSocket.PF_INET6, NativeDatagramSocket.IPPROTO_ICMPV6, pingerId)); // Windows requires at least one packet sent before a receive call can be made without error // so we send a packet here to make sure... This one should not match the normal ping requests // since it does not contain the cookie so it won't interface. if (Platform.isWindows()) { final ICMPv6EchoPacket packet = new ICMPv6EchoPacket(64); packet.setCode(0); packet.setType(Type.EchoRequest); packet.getContentBuffer().putLong(System.nanoTime()); packet.getContentBuffer().putLong(System.nanoTime()); getPingSocket().send(packet.toDatagramPacket(InetAddress.getByName("::1"))); } }
public void dump() throws Exception { NativeDatagramSocket m_pingSocket = NativeDatagramSocket.create(NativeDatagramSocket.PF_INET6, Platform.isMac() ? NativeDatagramSocket.SOCK_DGRAM : NativeDatagramSocket.SOCK_RAW, NativeDatagramSocket.IPPROTO_ICMPV6); if (Platform.isWindows()) { ICMPv6EchoPacket packet = new ICMPv6EchoPacket(64); packet.setCode(0); packet.setType(Type.EchoRequest); packet.getContentBuffer().putLong(System.nanoTime()); packet.getContentBuffer().putLong(System.nanoTime()); m_pingSocket.send(packet.toDatagramPacket(InetAddress.getByName("::1"))); } try { NativeDatagramPacket datagram = new NativeDatagramPacket(65535); while (true) { m_pingSocket.receive(datagram); System.err.println(datagram); } } catch(Throwable e) { e.printStackTrace(); } }
private static String getImplementationClassName(int family) { return NativeDatagramSocket.getClassPackage()+ "."+ NativeDatagramSocket.getClassPrefix()+ NativeDatagramSocket.getFamilyPrefix(family)+ "NativeSocket"; }
public void send(NativeDatagramSocket socket, InetAddress addr) { socket.send(toDatagramPacket(addr)); } }
@Override public void run() { Logging.putPrefix("icmp"); try { final int pingerId = getPingerId(); while (!isFinished()) { final NativeDatagramPacket datagram = new NativeDatagramPacket(65535); getPingSocket().receive(datagram); final long received = System.nanoTime(); final ICMPv6Packet icmpPacket = new ICMPv6Packet(getIPPayload(datagram)); final V6PingReply echoReply = icmpPacket.getType() == Type.EchoReply ? new V6PingReply(icmpPacket, received) : null; if (echoReply != null && echoReply.getIdentifier() == pingerId && echoReply.isValid()) { notifyPingListeners(datagram.getAddress(), echoReply); } } } catch(final Throwable t) { setThrowable(t); LOG.debug("Error caught while processing ping packets: {}", t.getMessage(), t); } }
public void closeSocket() { if (getPingSocket() != null) { getPingSocket().close(); } }
public static NativeDatagramSocket create(final int family, final int protocol, final int listenPort) throws Exception { final String implClassName = NativeDatagramSocket.getImplementationClassName(family); LOG.debug("{}({}, {}, {})", implClassName, family, protocol, listenPort); final Class<? extends NativeDatagramSocket> implementationClass = Class.forName(implClassName).asSubclass(NativeDatagramSocket.class); final Constructor<? extends NativeDatagramSocket> constructor = implementationClass.getDeclaredConstructor(Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); try { return constructor.newInstance(family, SOCK_DGRAM, protocol, listenPort); } catch (final Exception e) { LOG.debug("Failed to create {} SOCK_DGRAM socket ({}). Trying with SOCK_RAW.", implementationClass, e.getMessage()); LOG.trace("Failed to create {} SOCK_DGRAM socket. Trying with SOCK_RAW.", implementationClass, e); return constructor.newInstance(family, SOCK_RAW, protocol, listenPort); } }
public V4Pinger(final int id) throws Exception { super(NativeDatagramSocket.create(NativeDatagramSocket.PF_INET, NativeDatagramSocket.IPPROTO_ICMP, id)); // Windows requires at least one packet sent before a receive call can be made without error // so we send a packet here to make sure... This one should not match the normal ping requests // since it does not contain the cookie so it won't interface. if (Platform.isWindows()) { final ICMPEchoPacket packet = new ICMPEchoPacket(64); packet.setCode(0); packet.setType(Type.EchoRequest); packet.getContentBuffer().putLong(System.nanoTime()); packet.getContentBuffer().putLong(System.nanoTime()); getPingSocket().send(packet.toDatagramPacket(InetAddress.getLocalHost())); } }