return;
}
System.out.println(nif.getName() + "(" + nif.getDescription() + ")");
PcapHandle handle
= new PcapHandle.Builder(nif.getName())
.snaplen(SNAPLEN)
.promiscuousMode(PromiscuousMode.PROMISCUOUS)
.timeoutMillis(READ_TIMEOUT)
.bufferSize(BUFFER_SIZE)
.build();
handle.setFilter(
filter,
BpfCompileMode.OPTIMIZE
);
int num = 0;
while (true) {
Packet packet = handle.getNextPacket();
if (packet == null) {
continue;
}
else {
Timestamp ts = new Timestamp(handle.getTimestampInts() * 1000L);
ts.setNanos(handle.getTimestampMicros() * 1000);
System.out.println(ts);
System.out.println(packet);
num++;
if (num >= COUNT) {
break;
}
}
}
PcapStat ps = handle.getStats();
System.out.println("ps_recv: " + ps.getNumPacketsReceived());
System.out.println("ps_drop: " + ps.getNumPacketsDropped());
System.out.println("ps_ifdrop: " + ps.getNumPacketsDroppedByIf());
if (Platform.isWindows()) {
System.out.println("bs_capt: " + ps.getNumPacketsCaptured());
}
handle.close();
}