本文整理汇总了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;
}