use of org.pcap4j.packet.IllegalRawDataException in project trex-stateless-gui by cisco-system-traffic-generator.
the class RecordController method toEtherPkt.
private EthernetPacket toEtherPkt(CapturedPkt pkt) {
byte[] pktBinary = Base64.getDecoder().decode(pkt.getBinary());
EthernetPacket ethPkt = null;
try {
ethPkt = EthernetPacket.newPacket(pktBinary, 0, pktBinary.length);
} catch (IllegalRawDataException e) {
LOG.error("Save PCAP. Unable to parse pkt from server.", e);
return null;
}
return ethPkt;
}
use of org.pcap4j.packet.IllegalRawDataException in project trex-stateless-gui by cisco-system-traffic-generator.
the class PacketTableView method handleExportPcapFile.
/**
* 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);
}
}
use of org.pcap4j.packet.IllegalRawDataException in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrexEthernetPacket method fixPacketLength.
private void fixPacketLength() {
try {
EthernetPacket newPacket = packet;
if (packet.getRawData().length < getLength()) {
byte[] pad = new byte[getLength() - packet.getRawData().length];
newPacket = EthernetPacket.newPacket(ArrayUtils.addAll(packet.getRawData(), pad), 0, getLength());
} else {
newPacket = EthernetPacket.newPacket(packet.getRawData(), 0, getLength());
}
setPacket((EthernetPacket) newPacket);
} catch (IllegalRawDataException ex) {
Logger.getLogger(TrexEthernetPacket.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of org.pcap4j.packet.IllegalRawDataException 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