Java Code Examples for org.pcap4j.packet.EthernetPacket#newPacket()
The following examples show how to use
org.pcap4j.packet.EthernetPacket#newPacket() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PacketTableView.java From trex-stateless-gui with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 2
Source File: UnixPktDumpService.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
private EthernetPacket toEtherPkt(byte[] pkt) { EthernetPacket ethPkt = null; try { ethPkt = EthernetPacket.newPacket(pkt, 0, pkt.length); } catch (IllegalRawDataException e) { LOG.error("Save PCAP. Unable to parse pkt from server.", e); return null; } return ethPkt; }
Example 3
Source File: RecordController.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
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; }
Example 4
Source File: TrexEthernetPacket.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
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); } }
Example 5
Source File: PacketHex.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Handle mouse clicked event */ private void handleMouseClickedEvent() { TreeTableRow<HexData> selectedRow = (TreeTableRow<HexData>) textField.getParent().getParent(); if (!selectedRow.getTreeItem().getValue().getOffset().contains("-")) { String originalLine = textField.getText(); String selectedHex = textField.getSelectedText().trim(); String replacedHex = showDialog(selectedHex); if (replacedHex != null) { try { textField.replaceSelection(replacedHex.toUpperCase()); String payLoad = hexToASCII(textField.getText()); TreeTableRow<HexData> hexTable = (TreeTableRow<HexData>) textField.getParent().getParent(); TreeItem<HexData> selectedItem = hexTable.getTreeItem(); selectedItem.setValue(new HexData(selectedItem.getValue().getOffset(), textField.getText(), packetParser.formatPayLoad(payLoad))); String originalHex = getPacketHexFromList(); if (selectedItem.getValue().getOffset().contains("-")) { originalHex = originalHex.replaceAll(originalLine.replaceAll(" ", "").replaceAll("\n", ""), textField.getText().replaceAll(" ", "").replaceAll("\n", "")); } byte[] rawdata = DatatypeConverter.parseHexBinary(originalHex); EthernetPacket p = EthernetPacket.newPacket(rawdata, 0, rawdata.length); packetParser.parsePacket(p, packetInfo); treeRoot.getChildren().clear(); setData(packetInfo); } catch (IllegalRawDataException ex) { java.util.logging.Logger.getLogger(PacketHex.class.getName()).log(Level.SEVERE, null, ex); } } } }
Example 6
Source File: PacketUtil.java From trex-stateless-gui with Apache License 2.0 | 2 votes |
/** * Get packet from encoded string * * @param encodedBinaryPacket * @return packet * @throws IllegalRawDataException */ public Packet getPacketFromEncodedString(String encodedBinaryPacket) throws IllegalRawDataException { byte[] pkt = Base64.decodeBase64(encodedBinaryPacket); return EthernetPacket.newPacket(pkt, 0, pkt.length); }