Sending packets
Send a hand-crafted packet to the network.
public static void main(String[] _args)
throws ErrorException, PermissionDeniedException, PromiscuousModePermissionDeniedException,
TimestampPrecisionNotSupportedException, RadioFrequencyModeNotSupportedException,
NoSuchDeviceException, ActivatedException, InterfaceNotUpException,
InterfaceNotSupportTimestampTypeException {
var service = Service.Creator.create("PcapService");
try (var pcap = service.live(service.interfaces(), new DefaultLiveOptions())) {
PacketBuffer buffer = pcap.allocate(PacketBuffer.class).capacity(14);
buffer.writeBytes(
new byte[] {(byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255});
buffer.writeBytes(
new byte[] {(byte) 222, (byte) 173, (byte) 190, (byte) 239, (byte) 192, (byte) 254});
buffer.writeShortRE(0x0806);
try {
pcap.sendPacket(buffer);
} catch (ErrorException e) {
System.err.println(e.getMessage());
}
buffer.release();
}
}
fun main() {
val service = Service.Creator.create("PcapService")
val pcap = service.live(service.interfaces(), DefaultLiveOptions())
val buffer = pcap.allocate(PacketBuffer::class.java).capacity(14)
buffer.writeBytes(byteArrayOf(255.toByte(), 255.toByte(), 255.toByte(), 255.toByte(), 255.toByte(), 255.toByte()))
buffer.writeBytes(byteArrayOf(222.toByte(), 173.toByte(), 190.toByte(), 239.toByte(), 192.toByte(), 254.toByte()))
buffer.writeShortRE(0x0806)
try {
pcap.sendPacket(buffer)
} catch (e: ErrorException) {
System.err.println(e.message)
}
buffer.release()
pcap.close()
}
def main(_args: Array[String]): Unit = {
val service = Service.Creator.create("PcapService")
val pcap = service.live(service.interfaces(), new DefaultLiveOptions())
val buffer = pcap.allocate(classOf[PacketBuffer]).capacity(14)
buffer.writeBytes(Array[Byte](255.toByte, 255.toByte, 255.toByte, 255.toByte, 255.toByte, 255.toByte))
buffer.writeBytes(Array[Byte](222.toByte, 173.toByte, 190.toByte, 239.toByte, 192.toByte, 254.toByte))
buffer.writeShortRE(0x0806)
try pcap.sendPacket(buffer)
catch {
case e: ErrorException =>
System.err.println(e.getMessage)
}
buffer.release()
pcap.close()
}
Last updated