Class Pcaps


  • public final class Pcaps
    extends java.lang.Object
    Since:
    pcap4j 0.9.1
    Author:
    Kaito Yamada
    • Method Detail

      • getDevByAddress

        public static PcapNetworkInterface getDevByAddress​(java.net.InetAddress addr)
                                                    throws PcapNativeException
        Gets a device by IP address.
        Parameters:
        addr - addr
        Returns:
        a PcapNetworkInterface.
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • lookupDev

        public static java.lang.String lookupDev()
                                          throws PcapNativeException
        Returns:
        a name of a network interface.
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • openOffline

        public static PcapHandle openOffline​(java.lang.String filePath)
                                      throws PcapNativeException
        Parameters:
        filePath - "-" means stdin
        Returns:
        a new PcapHandle object.
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • openDead

        public static PcapHandle openDead​(DataLinkType dlt,
                                          int snaplen)
                                   throws PcapNativeException
        Parameters:
        dlt - dlt
        snaplen - Snapshot length, which is the number of bytes captured for each packet.
        Returns:
        a new PcapHandle object.
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • dataLinkNameToVal

        public static DataLinkType dataLinkNameToVal​(java.lang.String name)
                                              throws PcapNativeException
        Parameters:
        name - a data link type name, which is a DLT_ name with the DLT_ removed.
        Returns:
        a DataLinkType object.
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • dataLinkValToName

        public static java.lang.String dataLinkValToName​(int dataLinkVal)
                                                  throws PcapNativeException
        Parameters:
        dataLinkVal - dataLinkVal
        Returns:
        data link type name
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • dataLinkTypeToDescription

        public static java.lang.String dataLinkTypeToDescription​(DataLinkType dlt)
                                                          throws PcapNativeException
        Parameters:
        dlt - dlt
        Returns:
        a short description of that data link type.
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • dataLinkValToDescription

        public static java.lang.String dataLinkValToDescription​(int dataLinkVal)
                                                         throws PcapNativeException
        Parameters:
        dataLinkVal - dataLinkVal
        Returns:
        a short description of that data link type.
        Throws:
        PcapNativeException - if an error occurs in the pcap native library.
      • strError

        public static java.lang.String strError​(int error)
        Parameters:
        error - error
        Returns:
        an error message.
      • libVersion

        public static java.lang.String libVersion()
        Returns:
        a string giving information about the version of the libpcap library being used; note that it contains more information than just a version number.
      • toBpfString

        public static java.lang.String toBpfString​(java.net.InetAddress inetAddr)
        Parameters:
        inetAddr - Inet4Address or Inet6Address
        Returns:
        a string representation of an InetAddress for BPF.
      • toBpfString

        public static java.lang.String toBpfString​(MacAddress macAddr)
        Parameters:
        macAddr - macAddr
        Returns:
        a string representation of a MAC address for BPF.