use of org.pcap4j.core.PcapNativeException 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.PcapNativeException in project trex-stateless-gui by cisco-system-traffic-generator.
the class ImportPcapWizardController method handleSelectPcapBtnClicked.
/**
* Handle select pcap button click event
* @param event
*/
@FXML
public void handleSelectPcapBtnClicked(ActionEvent event) {
if (importedPacketPropertiesView.isValidInputValues()) {
String loadFolderPath = PreferencesManager.getInstance().getLoadLocation();
Stage owner = (Stage) wizardViewContainer.getScene().getWindow();
File pcapFile = FileManager.getSelectedFile("Open Pcap File", "", owner, FileType.PCAP, loadFolderPath, false);
if (pcapFile != null) {
try {
if (importedPacketTableView.setPcapFile(pcapFile)) {
wizardViewContainer.getChildren().clear();
wizardViewContainer.getChildren().add(importedPacketTableView);
updateBtnState(false);
} else {
TrexAlertBuilder.build().setType(Alert.AlertType.ERROR).setContent("Invalid Pcap, it should be one flow with IPV4 packets").getAlert().showAndWait();
}
} catch (PcapNativeException | TimeoutException | NotOpenException ex) {
TrexAlertBuilder.build().setType(Alert.AlertType.ERROR).setTitle("Import error").setHeader("An error has occurred while attempting to import.").setContent(ex.getLocalizedMessage()).getAlert().showAndWait();
}
}
}
}
use of org.pcap4j.core.PcapNativeException 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