- java.lang.Object
-
- org.pcap4j.core.Pcaps
-
public final class Pcaps extends java.lang.Object- Since:
- pcap4j 0.9.1
-
-
Constructor Summary
Constructors Modifier Constructor Description privatePcaps()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BpfProgramcompileFilter(int snaplen, DataLinkType dlt, java.lang.String bpfExpression, BpfProgram.BpfCompileMode mode, java.net.Inet4Address netmask)static DataLinkTypedataLinkNameToVal(java.lang.String name)static java.lang.StringdataLinkTypeToDescription(DataLinkType dlt)static java.lang.StringdataLinkTypeToName(DataLinkType dlt)static java.lang.StringdataLinkValToDescription(int dataLinkVal)static java.lang.StringdataLinkValToName(int dataLinkVal)static java.util.List<PcapNetworkInterface>findAllDevs()Gets all devices.static PcapNetworkInterfacegetDevByAddress(java.net.InetAddress addr)Gets a device by IP address.static PcapNetworkInterfacegetDevByName(java.lang.String name)Gets a device by name.static java.lang.StringlibVersion()static java.lang.StringlookupDev()static Inet4NetworkAddresslookupNet(java.lang.String devName)static PcapHandleopenDead(DataLinkType dlt, int snaplen)static PcapHandleopenDead(DataLinkType dlt, int snaplen, PcapHandle.TimestampPrecision precision)static PcapHandleopenOffline(java.lang.String filePath)static PcapHandleopenOffline(java.lang.String filePath, PcapHandle.TimestampPrecision precision)static java.lang.StringstrError(int error)static java.lang.StringtoBpfString(java.net.InetAddress inetAddr)static java.lang.StringtoBpfString(MacAddress macAddr)
-
-
-
Method Detail
-
findAllDevs
public static java.util.List<PcapNetworkInterface> findAllDevs() throws PcapNativeException
Gets all devices.- Returns:
- a list of PcapNetworkInterfaces.
- Throws:
PcapNativeException- if an error occurs in the pcap native library.
-
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.
-
getDevByName
public static PcapNetworkInterface getDevByName(java.lang.String name) throws PcapNativeException
Gets a device by name.- Parameters:
name- name- 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.
-
lookupNet
public static Inet4NetworkAddress lookupNet(java.lang.String devName) throws PcapNativeException
- Parameters:
devName- devName- Returns:
- an
Inet4NetworkAddressobject. - 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.
-
openOffline
public static PcapHandle openOffline(java.lang.String filePath, PcapHandle.TimestampPrecision precision) throws PcapNativeException
- Parameters:
filePath- "-" means stdinprecision- precision- 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- dltsnaplen- 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.
-
openDead
public static PcapHandle openDead(DataLinkType dlt, int snaplen, PcapHandle.TimestampPrecision precision) throws PcapNativeException
- Parameters:
dlt- dltsnaplen- Snapshot length, which is the number of bytes captured for each packet.precision- precision- Returns:
- a new PcapHandle object.
- Throws:
PcapNativeException- if an error occurs in the pcap native library.
-
compileFilter
public static BpfProgram compileFilter(int snaplen, DataLinkType dlt, java.lang.String bpfExpression, BpfProgram.BpfCompileMode mode, java.net.Inet4Address netmask) throws PcapNativeException
- Parameters:
snaplen- snaplendlt- dltbpfExpression- bpfExpressionmode- modenetmask- netmask- Returns:
- a
BpfProgramobject. - 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
DataLinkTypeobject. - Throws:
PcapNativeException- if an error occurs in the pcap native library.
-
dataLinkTypeToName
public static java.lang.String dataLinkTypeToName(DataLinkType dlt) throws PcapNativeException
- Parameters:
dlt- dlt- Returns:
- data link type name
- 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.
-
-