Libpcap wrapper

JnetPcap not able to capture packets after capturing few lakh packets at heavy traffic.

I am using Jnetpcap 1.3 , My observation is in windows machine after capturing few lakhs packet, Jnetpcap is not able to capture more packets.There is heavy traffic on NIC. Please provide some solution on this.

sendPacket() duplicating the frames

Dear community,

I would like to ask you a specific question: I'm trying to develop a software switch with the jNetPcap 1.4 library on Java 1.7, the goal is to have a program, that can forward packets received on port no. 1 to port no. 2 and vice versa (just on these two NIC-s).

I can see all the incoming packets on both of the interfaces, but when it comes to forwarding, I have a problem: if I send a packet on interface X with pcap.sendPacket(PcapPacket) the nextPacket() function inside the PcapPacketHandler() class will see it also, and will treat is a "new" packet, insted of just ignoring it, because it was sent by the same Pcap instance.

Is there any way to ignore the packets, that were sent by the pcap.sendPacket(PcapPacket) function (so they do not appear again in the nextPacket() function)?

I don't know much about the underlying winpcap library, but I'm sure SharpPcap in C# has this type of functionality. Doesn't jNetPcap have it also, or am I missing something?

Things I've tried:

1.Using pcap.inject() instead of pcap.sendPacket(), but my NIC doesn't seem to support this function

2. Setting the capture direction to inbound only with pcap.setDirection(Direction.IN) - this seems to have absolutely no effect, the packets are captured just as before setting it.

Ps.If the jNetPcap library does not have this functionality, please, could you advise how to solve the problem? I'm thinking of buffering the sent packets to an array of some type and checking every newly detected packet to be the same as one packet in the array - but this seems to be a computationally complex solution.

Here's my sample code (not the whole, just the relevant pieces):

// Init
Pcap pcap = Pcap.openLive(allDevices.get( 0 ).getName(), 64*1024, Pcap.MODE_PROMISCUOUS, 1000, errbuf);

...

PcapPacketHandler jpacketHandler = new PcapPacketHandler() {
public void nextPacket(PcapPacket packet, String user) {

can't capture google search url

Iam developing an application to capture all http url.I used pcap.LOOP_INFINATE for persistent capturing, but when i search on google ,it does not capturing packet.Kindly give me a solution for this.

Jnetpacap crash after GC.

Hi All,

We are getting constant crashes using this library under heavy load. This is the exception in the output:

Exception in thread "DisposableGC" Exception in thread "ListenThread" java.lang.Error: Maximum permit count exceeded
at java.util.concurrent.Semaphore$Sync.tryReleaseShared(Semaphore.java:197)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1340)
at java.util.concurrent.Semaphore.release(Semaphore.java:615)
at org.jnetpcap.nio.DisposableGC.dispose(Unknown Source)
at org.jnetpcap.nio.DisposableGC.drainRefQueueLoop(Unknown Source)
at org.jnetpcap.nio.DisposableGC$2.run(Unknown Source)
at java.lang.Thread.run(Thread.java:724)
java.lang.Error: Maximum permit count exceeded
at java.util.concurrent.Semaphore$Sync.tryReleaseShared(Semaphore.java:197)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1340)
at java.util.concurrent.Semaphore.release(Semaphore.java:615)
at org.jnetpcap.nio.DisposableGC.dispose(Unknown Source)
at org.jnetpcap.nio.DisposableGC.drainRefQueueBounded(Unknown Source)
at org.jnetpcap.nio.DisposableReference.(Unknown Source)
at org.jnetpcap.nio.JMemoryReference.(Unknown Source)
at org.jnetpcap.nio.JMemory.createReference(Unknown Source)
at org.jnetpcap.nio.JMemory.allocate(Unknown Source)
at org.jnetpcap.nio.JMemory.(Unknown Source)
at org.jnetpcap.nio.JMemoryPool$Block.(Unknown Source)
at org.jnetpcap.nio.JMemoryPool.newBlock(Unknown Source)
at org.jnetpcap.nio.JMemoryPool.getBlock(Unknown Source)
at org.jnetpcap.nio.JMemoryPool.duplicate2(Unknown Source)
at org.jnetpcap.packet.PcapPacket.transferHeaderAndDataFrom0(Unknown Source)
at org.jnetpcap.packet.PcapPacket.(Unknown Source)

Pcap loop() not working

Hi,

I am new to jnetpcap. For doing my project,I have to write a program to capture outbound n/w packets.
I have created a program to capture a single packet header. Header length and time stamp are obtained( but time stamp is not correct). But actually I want to capture infinite number of packets. So I wrote a code with pcap.loop() for capturing a single packet, but not working.

This is my code:

StringBuilder errbuf = new StringBuilder();
ArrayList ifs = new ArrayList<>();
int statusCode = Pcap.findAllDevs(ifs, errbuf);
if (statusCode != Pcap.OK) {
System.out.println("Error occured: " + errbuf.toString());
return;
}

PcapIf netInterface = ifs.get(1);

int snaplen = 2048;
int promiscous = Pcap.MODE_PROMISCUOUS;
int timeout = 60 * 1000;
Pcap pcap =
Pcap.openLive(netInterface.getName(), snaplen, promiscous, timeout, errbuf);

PcapBpfProgram filter = new PcapBpfProgram();
String expression = "port 80";
int optimize = 0; // 1 means true, 0 means false
int netmask = 0;

int r = pcap.compile(filter, expression, optimize, netmask);
if (r != Pcap.OK) {
System.out.println("Filter error: " + pcap.getErr());
}
pcap.setFilter(filter);

PcapPacketHandler> handler = new PcapPacketHandler>() {
@Override
public void nextPacket(PcapPacket packet, Queue queue) {
System.out.println("size of packet is=" + packet.size());
Ip4 ip4 = new Ip4();
if(packet.hasHeader(ip4))
{
ip4 = packet.getHeader(ip4);
byte[] source = ip4.source();
System.out.println(source);
}
Tcp tcp = new Tcp();

Syndicate content