当前位置: 首页>>代码示例>>Java>>正文


Java Pcap.getErr方法代码示例

本文整理汇总了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());
}
 
开发者ID:andymalakov,项目名称:libpcap-latency-meter,代码行数:10,代码来源:LiveCaptureProcessor.java

示例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());
    }
}
 
开发者ID:fg-netzwerksicherheit,项目名称:jnetpcapfacade,代码行数:21,代码来源:PcapHelper.java

示例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;
}
 
开发者ID:fg-netzwerksicherheit,项目名称:jnetpcapfacade,代码行数:41,代码来源:PcapHelper.java


注:本文中的org.jnetpcap.Pcap.getErr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。