本文整理汇总了Java中org.jnetpcap.packet.PcapPacket类的典型用法代码示例。如果您正苦于以下问题:Java PcapPacket类的具体用法?Java PcapPacket怎么用?Java PcapPacket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PcapPacket类属于org.jnetpcap.packet包,在下文中一共展示了PcapPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getByteLimitedHandler
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Creation of a pseudopackethandler packet handler type which breaks the loop after.
*
* @return returns a packethandler which handles' the packets and stops if the max_bytes amount is handled.
*/
private static PcapPacketHandler<PseudoPacketHandler> getByteLimitedHandler(final Pcap pcap, final long MAX_BYTES) {
// Packet handler. Generic callback function for PseudoPacketHandler.
return new PcapPacketHandler<PseudoPacketHandler>() {
long packetBytes = 0;
// Handle nextPacket callback.
public void nextPacket(PcapPacket packet, PseudoPacketHandler handler) {
handler.handle(packet);
packetBytes+= packet.size();
if (packetBytes >= MAX_BYTES) {
pcap.breakloop();
}
}
};
}
示例2: getPacketList
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Gets the packet list.
*
* @param file
* the file
* @return the packet list
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private List<PcapPacket> getPacketList(String file) throws IOException {
StringBuilder errbuf = new StringBuilder();
Pcap pcap = Pcap.openOffline(file, errbuf);
if (pcap == null) {
throw new IOException(errbuf.toString());
}
final PcapPacketArrayList list = new PcapPacketArrayList(
(int) new File(file).length() / 100);
pcap.loop(Pcap.LOOP_INFINATE, list, null);
pcap.close();
return list;
}
示例3: testScanIpv6File
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Printing to DEV_NULL still causes entire packet structure to be decoded and
* dumped to /dev/null while using every available header found in the packet.
* Good stress test for Ip6 based packets.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testScanIpv6File() throws IOException {
TextFormatter out = new TextFormatter(OUT);
out.setResolveAddresses(false);
int i = 0;
Ethernet eth = new Ethernet();
for (PcapPacket packet : TestUtils.getIterable("tests/test-ipv6.pcap")) {
System.out.println(packet.toDebugString());
if (packet.hasHeader(eth)) {
out.format(eth);
}
out.setFrameIndex(i++);
out.format(packet);
}
}
示例4: handle
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* pseudonymize the packet as configured.
*
* @param packet the captured PcapPacket
*/
@Override
public void handle(PcapPacket packet) {
//Copy the data.
byte[] packetData = packet.getByteArray(0, packet.size());
try {
// If parsing fails the packet is not pseudonymized. This should logged at a lower level TODO PEF-77.
// Packet should be discarded because pseudonymization is not guaranteed otherwise.
final byte[] pseudopacketData = _pseudonymizer.pseudonymize(packetData);
PcapPacket copyPacket = new PcapPacket(packet.getCaptureHeader(), ByteBuffer.wrap(pseudopacketData));
_pseudoDumper.dump(copyPacket);
}
catch (final IOException e) {
logger.severe(e.getMessage());
}
}
示例5: handle
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Handles the packets and writes the packet after modification with the metal library,
* JNetPcap library and stores a reference file.
*
* @param packet the captured PcapPacket
*/
@Override
public void handle(PcapPacket packet) {
_referenceDumper.dump(packet);
byte[] packetData = packet.getByteArray(0, packet.size());
try {
final byte[] pseudopacketData = _pseudonymizer.pseudonymize(packetData);
PcapPacket copyPacket = new PcapPacket(packet.getCaptureHeader(), ByteBuffer.wrap(pseudopacketData));
_metalDumper.dump(copyPacket);
} catch (final IOException ioexc) {
logger.severe("problem when pseudonymizing packets with the metal library");
}
_packetModifier.modifyPacket(packet);
_jnetpcapDumper.dump(packet);
}
示例6: setPacket
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Set the value of the field packet
* @param packet the new packet to set
*/
public boolean setPacket(final PcapPacket packet) {
boolean unkown = false;
_packet = packet;
eth = packet.getHeader(new Ethernet());
ip = packet.getHeader(new Ip4());
tcp = packet.getHeader(new Tcp());
if (tcp == null) {
udp = packet.getHeader(new Udp());
if (udp == null) {
icmp = packet.getHeader(new Icmp());
if (icmp == null) {
unkown = true;
setProtocol(Protocol.OTHER);
} else {
setProtocol(Protocol.ICMP);
}
} else {
setProtocol(Protocol.UDP);
}
} else {
setProtocol(Protocol.TCP);
}
return !unkown;
}
示例7: startCapture
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
@FXML
protected void startCapture(ActionEvent event) {
MenuItem source = (MenuItem) event.getSource();
NetworkAdapter networkAdapter = PcapManager.getInstance().getNetworkAdapter();
if (networkAdapter == null) {
showCaptureOptions(null);
return;
}
setStatusInfo(Config.getString("label_start_capture"));
source.setDisable(true);
menuItemStop.setDisable(false);
PcapManager.getInstance().captureLive(packet -> {
// 将第一个数据包的时间戳设置为起始时间
if (Config.getTimestamp() <= Config.DEFAULT_TIMESTAMP) {
Config.setTimestamp(packet.getCaptureHeader().timestampInMicros());
}
PcapPacket packetCopy = new PcapPacket(packet); // 获取副本
ObservableList items = tableView.getItems();
items.add(new PacketInfo(packetCopy));
});
}
示例8: meetCriteria
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
@Override
public Boolean meetCriteria(PcapPacket itemToCheck)
{
if (!itemToCheck.hasHeader(Ip4.ID))
return false;
Ip4 ipHeader = new Ip4();
ipHeader = itemToCheck.getHeader(ipHeader);
if (direction == null) //direction wasn't set, so any direction
return subnetInfo.isInRange(ipHeader.sourceToInt()) || subnetInfo.isInRange(ipHeader.destinationToInt());
switch(direction)
{
case Incoming: return subnetInfo.isInRange(ipHeader.sourceToInt());
case Outgoing: return subnetInfo.isInRange(ipHeader.destinationToInt());
default: return null; //doesn't get here
}
}
示例9: meetCriteria
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
@Override
public Boolean meetCriteria(PcapPacket itemToCheck)
{
if (!itemToCheck.hasHeader(Ethernet.ID))
return false;
Ethernet eth = new Ethernet();
eth = itemToCheck.getHeader(eth);
switch (direction)
{
case Incoming:
return Arrays.equals(ownMAC, eth.destination());
case Outgoing:
return Arrays.equals(ownMAC, eth.source());
default:
return false; //doesn't get here
}
}
示例10: nextPacket
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
@Override
public void nextPacket(PcapPacket packet, Void nothing)
{
if (!isCooldownPeriod)
{
for (Criteria<PcapPacket, Boolean> criteria : criteriaList)
{
if (criteria.meetCriteria(packet))
{
if (isRepeated)
{
isCooldownPeriod = true;
timer.schedule(() -> isCooldownPeriod = false, cooldownInSecs, TimeUnit.SECONDS);
}
else
sniffer.stopCapture();
listener.watchdogFoundMatchingPacket(packet, criteriaToMsgMap.get(criteria));
}
}
}
}
示例11: convertPacketTypeToMatchListToCriteria
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
private List<Criteria<PcapPacket, Boolean>> convertPacketTypeToMatchListToCriteria(List<PacketTypeToMatch> packetTypeList)
{
List<Criteria<PcapPacket, Boolean>> criterias = new ArrayList<>();
for (PacketTypeToMatch item : packetTypeList)
{
Criteria<PcapPacket, Boolean> andCriteria = null;
List<Criteria<PcapPacket, Boolean>> criteriasToAND = generateCriteriasToAND(item);
if (criteriasToAND.size() > 0)
andCriteria = criteriasToAND.get(0);
for (int i = 1; i < criteriasToAND.size(); i++)
andCriteria = new AndCriteria<PcapPacket>(andCriteria, criteriasToAND.get(i));
if (criteriasToAND.size() > 0)
{
criterias.add(andCriteria);
criteriaToMsgMap.put(andCriteria, new WatchdogMessage(item.getMessageTextValue(), item.getMessageOutputMethodValue()));
}
}
return criterias;
}
示例12: testSip
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Test sip.
*/
public void testSip() {
Sip sip = new Sip();
Sdp sdp = new Sdp();
PcapPacket packet = super.getPcapPacket(SIP, 223 - 1);
if (packet.hasHeader(sip)) {
System.out.printf("%s", sip);
if (packet.hasHeader(sdp)) {
System.out.printf("%s", sdp);
}
} else {
System.out.printf(packet.toString());
}
}
示例13: testCompare2SetsOfPackets
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Test compare2 sets of packets.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testCompare2SetsOfPackets() throws IOException {
List<PcapPacket> l1 = getPacketList(L2TP);
List<PcapPacket> l2 = getPacketList(L2TP);
assertEquals(l1.size(), l2.size());
for (int i = 0; i < l1.size(); i++) {
PcapPacket p1 = l1.get(i);
PcapPacket p2 = l2.get(i);
if (p1.size() != p2.size()) {
System.out.printf("#%d p1=%d p2=%d\n%s\n%s\n", i, l1.size(),
l2.size(), p1.toHexdump(), p2.toHexdump());
System.out.println(p1.toString());
System.out.println(p2.toString());
}
assertEquals(p1.size(), p2.size());
assertTrue(compareJBuffer(p1, p2));
}
}
示例14: testCompare2SetsOfPackets2
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
* Test compare2 sets of packets2.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testCompare2SetsOfPackets2() throws IOException {
List<PcapPacket> l1 = getPacketList(L2TP);
List<PcapPacket> l2 = getPacketList(L2TP);
Ip4 ip1 = new Ip4();
Ip4 ip2 = new Ip4();
assertEquals(l1.size(), l2.size());
System.out.println("------------------------------\n");
for (int i = 0; i < l1.size(); i++) {
PcapPacket p1 = l1.get(i);
PcapPacket p2 = l2.get(i);
p1.getHeader(ip1);
p2.getHeader(ip2);
assertTrue("ip1.size() == p2.size()", p1.size() == p2.size());
assertTrue(ip1.toString(), ip1.isChecksumValid());
assertTrue(ip2.toString(), ip2.isChecksumValid());
assertTrue(compareJBuffer(p1, p2));
}
}
示例15: onPreExecute
import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
protected void onPreExecute(){
blockLength=PcapFileLoader.blockLength;
pcapPackets=new PcapPacket[blockLength.value];
PcapFileLoader.pcapPackets[block]=pcapPackets;
lowerBound=new IntHolder(targetPacket);
if (indeterminate[block] || targetPacket<= PcapFileLoader.range[block][1].value){
if (!indeterminate[block]){
PcapFileLoader.pcap[block].close();
}
JScanner.getThreadLocal().setFrameNumber(0);
final StringBuilder errbuf=new StringBuilder();
pcap = Pcap.openOffline(filename, errbuf);
currentPacket=new IntHolder(0);
PcapFileLoader.pcap[block]=pcap;
PcapFileLoader.range[block][1]=currentPacket;
} else {
pcap=PcapFileLoader.pcap[block];
currentPacket=PcapFileLoader.range[block][1];
}
PcapFileLoader.range[block][0]=lowerBound;
indeterminate[block]=true;
Log.d("PcapBlockLoadTask", "loading block: "+Integer.toString(block)+"|"+Integer.toString(lowerBound.value));
}