Pcap
  • Introduction
  • Getting Started
    • Dependency management
    • Installing Libpcap or Npcap
    • Run as non root user
    • Logging
    • Obtaining the device list
    • Opening an adapter and capturing the packets
    • Capturing the packets without the callback
    • Capture statistics
    • Filtering the traffic
    • Write the packets to a capture file
    • Read packets from a capture file.
    • Sending packets
    • I/O Multiplexing
    • Restricted Method
  • Developer Guide
    • Branches to look
    • Build from Source
    • Notes
  • Packet Structure
    • Packet Header
    • Packet Buffer
  • Packet Codec
    • Using packet codec
    • Adding protocol support
  • Others
  • Thanks to
  • Fork me on Github
Powered by GitBook
On this page

Was this helpful?

  1. Getting Started

Sending packets

Send a hand-crafted packet to the network.

PreviousRead packets from a capture file.NextI/O Multiplexing

Last updated 4 years ago

Was this helpful?

Docs, .

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()
}

: libpcap
javadoc