use of org.pcap4j.core.NotOpenException in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrafficProfile method encodePcapFile.
/**
* @param binaryFile
* @return Encodes the bytes array of a PCAP File using Base64
*/
public String encodePcapFile(String binaryFile) {
try {
PcapHandle handle = Pcaps.openOffline(binaryFile);
Packet packet = handle.getNextPacketEx();
handle.close();
byte[] pkt = packet.getRawData();
byte[] bytesEncoded = Base64.encodeBase64(pkt);
return new String(bytesEncoded);
} catch (IOException | PcapNativeException | TimeoutException | NotOpenException ex) {
LOG.error("Error encoding pcap file", ex);
return binaryFile;
}
}
use of org.pcap4j.core.NotOpenException in project trex-stateless-gui by cisco-system-traffic-generator.
the class ImportedPacketTableView method setPcapFile.
/**
* Parse pcap file to get all streams
*
* @param pcapFile
* @return
*/
public boolean setPcapFile(File pcapFile) {
List<PacketInfo> packetInfoList = new ArrayList<>();
try {
PacketUpdater.getInstance().reset();
PcapHandle handler = Pcaps.openOffline(pcapFile.getAbsolutePath());
PacketParser parser = new PacketParser();
Packet packet;
while ((packet = handler.getNextPacketEx()) != null) {
if (!PacketUpdater.getInstance().validatePacket(packet)) {
break;
}
PacketInfo packetInfo = new PacketInfo();
packet = PacketUpdater.getInstance().updatePacketSrcDst(packet);
packetInfo.setPacket(packet);
packetInfo.setTimeStamp(handler.getTimestamp().getTime());
parser.parsePacket(packet, packetInfo);
packetInfoList.add(packetInfo);
}
} catch (EOFException e) {
LOG.info("End of pcap file");
} catch (PcapNativeException | TimeoutException | NotOpenException ex) {
LOG.error("Error parsing selectd pcap file", ex);
}
setTableData(packetInfoList);
return PacketUpdater.getInstance().isValidPacket();
}
use of org.pcap4j.core.NotOpenException in project trex-stateless-gui by cisco-system-traffic-generator.
the class PacketParser method parseFile.
/**
*
* @param fileName
* @param packetInfo
*/
public void parseFile(String fileName, PacketInfo packetInfo) {
Packet packet;
try {
this.packetInfo = packetInfo;
total_octetes = 0;
PcapHandle handle = Pcaps.openOffline(fileName);
packet = handle.getNextPacketEx();
packetInfo.setPacket(packet);
extractPacketInfo(packet);
handle.close();
} catch (PcapNativeException | EOFException | TimeoutException | NotOpenException ex) {
packet = null;
LOG.warn("Failed to extract packet info from first try");
}
if (packet == null) {
try {
LOG.info("Attempting alternate method to read Pcap file");
byte[] pkt = FileUtils.readFileToByteArray(new File(fileName));
packet = EthernetPacket.newPacket(pkt, 0, pkt.length);
extractPacketInfo(packet);
} catch (IOException | IllegalRawDataException ex) {
LOG.error("Failed to read Pcap file", ex);
}
}
}
Aggregations