- All Implemented Interfaces:
AutoCloseable
ForeignInitializer
used to facilitate loading native
libary symbols and making of 'downcall' and 'upcall' function calls.- Author:
- Sly Technologies Inc, repos@slytechs.com, mark
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jnetpcap.internal.ForeignInitializer
ForeignInitializer.CType, ForeignInitializer.DowncallSupplier<T extends ForeignDowncall<?>>, ForeignInitializer.MethodHandleLookup, ForeignInitializer.MissingSymbolsPolicy
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Appendable
The Constant which defines the default logging output which discards all of its input. -
Constructor Summary
ConstructorDescriptionPcapForeignInitializer
(Class<?> initializerClass) Instantiates a new pcap foreign initializer. -
Method Summary
Modifier and TypeMethodDescriptionstatic Appendable
Gets the loggin output.static Pcap.LibraryPolicy
Gets the default missing symbols policy.static boolean
loadNativePcapLibrary
(boolean ignoreErrors) Load native pcap library, or one of its derivatives.static void
Sets the logging output produced by the default missing symbols policy receiver.static void
setPolicy
(Pcap.LibraryPolicy newPolicy) Sets the default missing native symbols policy.Methods inherited from class org.jnetpcap.internal.ForeignInitializer
close, downcall, downcall, getName, makeAccessible, setMissingSymbolsPolicy, setName, upcall, upcallStatic, upcallStatic, upcallVirtual
-
Field Details
-
DEFAULT_LOGGING_OUTPUT
The Constant which defines the default logging output which discards all of its input.
-
-
Constructor Details
-
PcapForeignInitializer
Instantiates a new pcap foreign initializer.- Parameters:
initializerClass
- the initializer class
-
-
Method Details
-
getLogginOutput
-
getPolicy
Gets the default missing symbols policy.- Returns:
- the default missing symbols policy
-
loadNativePcapLibrary
public static boolean loadNativePcapLibrary(boolean ignoreErrors) throws ExceptionInInitializerError Load native pcap library, or one of its derivatives. The defaults for the native library loading procedure, define a list of possible pcap library undecorated names such as 'wpcap,npcap,pcap' and utilize the relativeSystem.loadLibrary(String)
to search for the shared object/native library.By specifying various system properties on the java command line, you can redefine how, where and what to look for when loading the native library.
The following properties are used in a search in the following order:- "java.library.path":
- Defines directories where the native library will searched for.
- "org.jnetpcap.libpcap.file":
- Defines an absolute directory and decorated filename path to load the
native library using
invalid @link
{@link System.#load(String)
- "org.jnetpcap.libpcap.filename":
- Defines a decorated filename only of the native library. The decorated
filename will be appended to the
"java.library.path" and an absolute
library load call will be attempted
System.load(String)
. - "org.jnetpcap.libpcap.names":
- A comma separated list of undecorated library names. Each of the
undecorated names in the list will be attempted to load using
System.loadLibrary(String)
combined with the "java.library.path" property value. - "org.jnetpcap.so.extensions":
- Lastly, as a long-shot attempt, a list of absolute files will be built by combining all the property values given, with fully decorated filenames which utilize the provided extensions, to try and locate the native library on the platform. The default extension list are defined as "so,dylib". Each one will be tried in turn.
- Parameters:
ignoreErrors
- if true, no errors will be thrown but afalse
flag will be returned- Returns:
- true, if pcap library is loaded otherwise false
- Throws:
ExceptionInInitializerError
- the exception in initializer error- See Also:
-
setPolicy
Sets the default missing native symbols policy.Missing symbols policy is executed during early/static initialization phase of Pcap library. The policy object receives a list of symbols both for 'downcall' and 'upcall' symbols which were not found during loading of the native pcap libarary. The
ForeignInitializer
creates stubs for each missing symbol, that when called at runtime will throw a safe exception. A missing symbols policy can intercept missing symbols during initialization phase and if so desired can throw an appropriate exception, halting any further initialization. A different policy might simply log an error using application's logger.- Parameters:
newPolicy
- the new default missing symbols policy- See Also:
-
setLoggingOutput
Sets the logging output produced by the default missing symbols policy receiver. By default the output is sent toPrintWriter.nullWriter()
which discards all output. You can set another output consumer or override the policy usingsetPolicy(LibraryPolicy)
.- Parameters:
out
- the new logging output- See Also:
-