slytechs-repos/jnetpcap-wrapper

can not invoke native C function 'pcap_findalldevs(AA)I' (Mac)

EgoFan opened this issue · 4 comments

I get an error while running the demo:Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalStateException: can not invoke native C function 'pcap_findalldevs(AA)I',

at org.jnetpcap.internal.ForeignDowncall.invokeInt(ForeignDowncall.java:93)
at org.jnetpcap.Pcap0_7.findAllDevs(Pcap0_7.java:194)
at org.jnetpcap.Pcap.findAllDevs(Pcap.java:1005)
at com.ego.Main.main(Main.java:25)
Caused by: java.lang.IllegalStateException: can not invoke native C function 'pcap_findalldevs(AA)I'
at org.jnetpcap.internal.ForeignDowncall.handle(ForeignDowncall.java:64)
at org.jnetpcap.internal.ForeignDowncall.invokeInt(ForeignDowncall.java:91)
... 3 more
Caused by: java.util.NoSuchElementException: native C symbol "pcap_findalldevs" not found
at org.jnetpcap.internal.ForeignInitializer.resolveSymbol(ForeignInitializer.java:358)
at org.jnetpcap.internal.ForeignInitializer.downcall(ForeignInitializer.java:298)
at org.jnetpcap.Pcap0_7.(Pcap0_7.java:75)
... 2 more

Where is the problem and how to solve it?
Thank you for your answer.

Its not finding the native libpcap library. Can you post your OS, and make sure you have libpcap or npcap on windows installed?

Its not finding the native libpcap library. Can you post your OS, and make sure you have libpcap or npcap on windows installed?

I use MacOS and I have configured libpcap and added the following options as per the documentation:
-Djava.library.path=/opt/homebrew/Cellar/libpcap/1.10.3/lib
--enable-preview
--enable-native-access=ALL-UNNAMED
-Dlibpcap.version=1.10.3

The library path seems wrong. It should be /usr/local/Cellar/libcap/..../lib on a mac. So please play around with the java.library.path property.

Also please verify and make sure that your libraries are installed under /opt/homebrew instead of /usr/local

Note #1 -Dlibpcap.version is not a valid properry used by jNetPcap v2
Note #2 Here is a link to a list of all valid properties: link

Were you able to properly configure the examples to run?