本文整理汇总了Java中org.jnetpcap.Pcap.getErr方法的典型用法代码示例。如果您正苦于以下问题:Java Pcap.getErr方法的具体用法?Java Pcap.getErr怎么用?Java Pcap.getErr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jnetpcap.Pcap
的用法示例。
在下文中一共展示了Pcap.getErr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupFilter
import org.jnetpcap.Pcap; //导入方法依赖的package包/类
private static void setupFilter(Pcap pcap, String expression) throws Exception {
PcapBpfProgram program = new PcapBpfProgram();
final int netmask = (int)Long.parseLong(CaptureSettings.FILTER_NETWORK_MASK_HEX.toLowerCase(), 16);
if (pcap.compile(program, expression, CaptureSettings.OPTIMIZE_FILTER ? 1 : 0, netmask) != Pcap.OK)
throw new Exception("Error compiling LIBPCAP filter: " + pcap.getErr());
if (pcap.setFilter(program) != Pcap.OK)
throw new Exception("Error setting LIBPCAP filter: " + pcap.getErr());
}
示例2: setFilter
import org.jnetpcap.Pcap; //导入方法依赖的package包/类
/**
*
* Sets a filter for a given {@link Pcap} instance. The filterExpression is
* a String following the format as explained e.g. in PCAP-FILTER(7).
*
* @param pcap
* @param filterExpression
*/
public static void setFilter(Pcap pcap, String filterExpression) {
PcapBpfProgram filter = new PcapBpfProgram();
if (pcap.compile(filter, filterExpression, 1, 0) != Pcap.OK) {
log.error("Filter not compilable: " + pcap.getErr());
throw new RuntimeException("Failed to compile filter: "
+ pcap.getErr());
}
if (pcap.setFilter(filter) != Pcap.OK) {
log.error("Filter not settable: " + pcap.getErr());
throw new RuntimeException("Failed to set filter: " + pcap.getErr());
}
}
示例3: createAndActivatePcap
import org.jnetpcap.Pcap; //导入方法依赖的package包/类
public static Pcap createAndActivatePcap(String device) {
NativeLibraryLoader.loadNativeLibs();
Pcap pcap = null;
List<PcapIf> devices = new ArrayList<PcapIf>();
StringBuilder err = new StringBuilder();
if (Pcap.findAllDevs(devices, err) != Pcap.OK || devices.isEmpty()) {
log.error("Failed to find network devices");
throw new RuntimeException("Failed to find network devices!");
}
for (PcapIf dev : devices) {
if (dev.getName().equalsIgnoreCase(device)) {
pcap = Pcap.create(device, err);
break;
}
}
if (pcap == null && devices.size() < 1) {
log.error("Failed to open device: " + device);
throw new RuntimeException("Failed to open \"" + device + "\" device!");
} else if (pcap == null) {
log.error("Failed to get requested device: " + device);
device = devices.get(0).getName();
log.error("Using first device found: " + device);
pcap = Pcap.create(device, err);
}
pcap.setSnaplen(Constants.SNAPLEN);
pcap.setPromisc(Constants.FLAGS);
pcap.setBufferSize(Constants.BUFFER_SIZE);
if (pcap.activate() != 0) {
log.error("Failed to activate device: " + device + " -> " + pcap.getErr());
throw new RuntimeException("Failed to activate \"" + device + "\" device!\n" + "Pcap error follows:\n" + pcap.getErr());
}
return pcap;
}