當前位置: 首頁>>代碼示例>>Java>>正文


Java DataLinkType類代碼示例

本文整理匯總了Java中org.pcap4j.packet.namednumber.DataLinkType的典型用法代碼示例。如果您正苦於以下問題:Java DataLinkType類的具體用法?Java DataLinkType怎麽用?Java DataLinkType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DataLinkType類屬於org.pcap4j.packet.namednumber包,在下文中一共展示了DataLinkType類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onEvent

import org.pcap4j.packet.namednumber.DataLinkType; //導入依賴的package包/類
@Override
public void onEvent(PacketContainer container, long sequence, boolean endOfBatch) throws Exception {
    if (shouldSkipEvent(sequence)) {
        return;
    }

    DataLinkType dlt = container.getDlt();
    byte[] data = container.getRawPacket();

    Packet packet = PacketFactories.getFactory(Packet.class, DataLinkType.class)
            .newInstance(data, 0, data.length, dlt);

    // Don't use packet.get(IpV4Packet.class).
    // In case of 'IP in IP' packets it doesn't work properly.
    IpV4Packet ipV4Packet = extractIpV4Packet(packet,
            pkt -> pkt.getOuterOf(UdpPacket.class),
            pkt -> pkt.getOuterOf(TcpPacket.class),
            pkt -> pkt.getOuterOf(FragmentedPacket.class));

    if (ipV4Packet != null) {
        IpNumber protocol = ipV4Packet.getHeader().getProtocol();
        if (protocol.compareTo(IpNumber.UDP) == 0 || protocol.compareTo(IpNumber.TCP) == 0) {
            container.setIpV4Packet(ipV4Packet);
        }
    }
}
 
開發者ID:sip3io,項目名稱:tapir,代碼行數:27,代碼來源:PacketDecoder.java

示例2: handleExportPcapFile

import org.pcap4j.packet.namednumber.DataLinkType; //導入依賴的package包/類
/**
 * Export stream to pcap file
 */
public void handleExportPcapFile() {
    try {
        Profile p = tabledata.getProfiles().get(streamPacketTableView.getSelectionModel().getSelectedIndex());
        String packetBinary = p.getStream().getPacket().getBinary();

        byte[] pkt = Base64.decodeBase64(packetBinary);
        Packet packet = EthernetPacket.newPacket(pkt, 0, pkt.length);
        File pcapFile = File.createTempFile("temp-file-name", ".pcap");
        PcapHandle handle = Pcaps.openDead(DataLinkType.EN10MB, 65536);
        PcapDumper dumper = handle.dumpOpen(pcapFile.getAbsolutePath());
        Timestamp ts = new Timestamp(0);
        dumper.dump(packet, ts);
        dumper.close();
        handle.close();

        String fileName = p.getName() + ".pcap";
        Window owner = streamPacketTableView.getScene().getWindow();
        FileManager.exportFile("Save Pcap File", fileName, pcapFile, owner, FileType.PCAP);
    } catch (IllegalRawDataException | IOException | PcapNativeException | NotOpenException ex) {
        LOG.error("Error during generate JSON file", ex);
    }
}
 
開發者ID:exalt-tech,項目名稱:trex-stateless-gui,代碼行數:26,代碼來源:PacketTableView.java

示例3: getDlt

import org.pcap4j.packet.namednumber.DataLinkType; //導入依賴的package包/類
public DataLinkType getDlt() {
    return dlt;
}
 
開發者ID:sip3io,項目名稱:tapir,代碼行數:4,代碼來源:PacketContainer.java

示例4: setDlt

import org.pcap4j.packet.namednumber.DataLinkType; //導入依賴的package包/類
public void setDlt(DataLinkType dlt) {
    this.dlt = dlt;
}
 
開發者ID:sip3io,項目名稱:tapir,代碼行數:4,代碼來源:PacketContainer.java


注:本文中的org.pcap4j.packet.namednumber.DataLinkType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。