Package jpcap

Class JpcapSender

java.lang.Object
jpcap.JpcapSender

public class JpcapSender extends Object
This class is used to send a packet.
  • Method Details

    • openDevice

      public static JpcapSender openDevice(NetworkInterface device) throws IOException
      Initializes a network interface for sending a packet, and returns an instance of this class.
      Parameters:
      device - Interface for sending a packet
      Returns:
      intstance of this class (JpcapSender)
      Throws:
      IOException - Raised when initialization of the interface failed
      IOException
    • openRawSocket

      @Deprecated public static JpcapSender openRawSocket() throws IOException
      Deprecated.
      Open a raw IP socket to send a packet.
      When sending a packet via a raw socket, the datalink header of the packet is ignored (= automatically generated by OS).

      Note: the implementation and behavior of a raw socket may vary in different OS. Also, you can only open one raw socket at a time.

      Returns:
      intstance of this class (JpcapSender)
      Throws:
      IOException - Raised when initialization of the interface failed
      IOException
    • close

      public void close()
      Closes the interface.
    • sendPacket

      public void sendPacket(Packet packet)
      Sends a packet.

      If this JpcapSender instance was created by openDevice(), you need to set the Datalink layer's header (e.g., Ethernet header) of the packet.

      If this JpcapSender instance was created by openRawSocket(), you can only send IP packets, but you may not need to set the Datalink layer's header of the IP packets you want to send.
      Note: the implementation and behavior of a raw socket may vary in different OS. For example, in Windows 2000/XP, you need to manually set the datalink/IP headers of a packet.

      Parameters:
      packet - Packet to be sent