Skip to content

Commit

Permalink
Added a fallback from win_pcap_stats_ex to pcap_stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitoy committed Jan 17, 2016
1 parent 493972b commit 770fb41
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions pcap4j-core/src/main/java/org/pcap4j/core/PcapHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1196,26 +1196,28 @@ public PcapStat getStats() throws PcapNativeException, NotOpenException {
if (Platform.isWindows()) {
IntByReference pcapStatSize = new IntByReference();
Pointer psp = PcapLibrary.INSTANCE.win_pcap_stats_ex(handle, pcapStatSize);

if (pcapStatSize.getValue() != 24) {
throw new PcapNativeException(getError());
}
if (psp == null) {
throw new PcapNativeException(getError());
if (
!getError()
.equals("Cannot retrieve the extended statistics from a file or a TurboCap port")
) {
if (pcapStatSize.getValue() != 24) {
throw new PcapNativeException(getError());
}
if (psp == null) {
throw new PcapNativeException(getError());
}
return new PcapStat(psp, true);
}

return new PcapStat(psp, true);
}
else {
pcap_stat ps = new pcap_stat();
ps.setAutoSynch(false);
int rc = NativeMappings.pcap_stats(handle, ps);
if (rc < 0) {
throw new PcapNativeException(getError(), rc);
}

return new PcapStat(ps.getPointer(), false);
pcap_stat ps = new pcap_stat();
ps.setAutoSynch(false);
int rc = NativeMappings.pcap_stats(handle, ps);
if (rc < 0) {
throw new PcapNativeException(getError(), rc);
}

return new PcapStat(ps.getPointer(), false);
} finally {
handleLock.readLock().unlock();
}
Expand Down

0 comments on commit 770fb41

Please sign in to comment.