use of com.att.aro.core.util.TSharkConfirmationImpl in project VideoOptimzer by attdevsupport.
the class PacketReaderLibraryImpl method readPacket.
@Override
public void readPacket(String packetfile, IPacketListener listener) throws IOException {
// windows dependency only
if (Util.isWindowsOS()) {
checkNativeLib();
}
FileDetails fileDetails = parseFileDetails(packetfile);
if (!fileDetails.isPcap() && !fileDetails.isPcapNG()) {
LOGGER.error("Not a valid pcap file " + packetfile);
return;
}
long start = System.currentTimeMillis();
// Update system property org.pcap4j.af.inet6 to correct value based on original OS which captured pcap/pcapng file
identifyOSInfo(packetfile);
if (fileDetails.isPcap) {
PcapHandle handle = null;
try {
handle = Pcaps.openOffline(packetfile);
} catch (PcapNativeException e) {
LOGGER.error("Error while reading pcap file " + packetfile, e);
return;
} catch (Exception ee) {
LOGGER.error("Error unknow " + packetfile, ee);
return;
}
try {
int currentPacketNumber = 0;
int totalPacketReads = 0;
while (true) {
try {
++currentPacketNumber;
Packet pcap4jPacket = handle.getNextPacketEx();
// Get last packet's capture timestamp
Timestamp timestamp = handle.getTimestamp();
com.att.aro.core.packetreader.pojo.Packet packet = translatePcap4jPacket(timestamp.getTime() / 1000, timestamp.getNanos() / 1000, pcap4jPacket);
++totalPacketReads;
listener.packetArrived(null, packet);
} catch (EOFException e) {
LOGGER.info(String.format("Finished reading total %d packets out of %d packets for pcap file %s", totalPacketReads, currentPacketNumber - 1, packetfile));
break;
} catch (Exception ex) {
LOGGER.debug("Error while reading packet number " + currentPacketNumber, ex);
}
}
} catch (Exception e) {
LOGGER.error("Error while reading pcap file " + packetfile, e);
} finally {
handle.close();
}
} else {
TSharkConfirmationImpl tsharkConfirmation = new TSharkConfirmationImpl(externalProcessRunner);
if (!tsharkConfirmation.checkTsharkVersion()) {
throw new TsharkException("Wireshark is either not installed on your machine or its not in your path.");
}
handlePCAPNGFile(packetfile, listener);
}
LOGGER.info("Time to read pcap file in ms: " + (System.currentTimeMillis() - start));
}
Aggregations