本文整理匯總了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);
}
}
}
示例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);
}
}
示例3: getDlt
import org.pcap4j.packet.namednumber.DataLinkType; //導入依賴的package包/類
public DataLinkType getDlt() {
return dlt;
}
示例4: setDlt
import org.pcap4j.packet.namednumber.DataLinkType; //導入依賴的package包/類
public void setDlt(DataLinkType dlt) {
this.dlt = dlt;
}