-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPCapFFM.java
More file actions
73 lines (56 loc) · 3.79 KB
/
Copy pathPCapFFM.java
File metadata and controls
73 lines (56 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package javaforce.ffm;
import java.lang.foreign.*;
import java.lang.invoke.*;
import static java.lang.foreign.ValueLayout.*;
import javaforce.*;
import javaforce.ffm.*;
import javaforce.api.*;
/** PCapAPI FFM implementation.
*
* Generated by GenFFM - DO NOT EDIT
*/
public class PCapFFM implements PCapAPI {
private FFM ffm;
private static PCapFFM instance;
public static synchronized PCapFFM getInstance() {
if (instance == null) {
instance = new PCapFFM();
if (!instance.ffm_init()) {
JFLog.log("PCapFFM init failed!");
instance = null;
}
}
return instance;
}
private MethodHandle pcapCompile;
public boolean pcapCompile(long a1,java.lang.String a2) { try { Arena arena = Arena.ofAuto(); boolean _ret_value_ = (boolean)pcapCompile.invokeExact(a1,(MemorySegment)(a2 == null ? MemorySegment.NULL : arena.allocateFrom(a2)));return _ret_value_; } catch (Throwable t) { JFLog.log(t); return false;} }
private MethodHandle pcapInit;
public boolean pcapInit(java.lang.String a1,java.lang.String a2) { try { Arena arena = Arena.ofAuto(); boolean _ret_value_ = (boolean)pcapInit.invokeExact((MemorySegment)(a1 == null ? MemorySegment.NULL : arena.allocateFrom(a1)),(MemorySegment)(a2 == null ? MemorySegment.NULL : arena.allocateFrom(a2)));return _ret_value_; } catch (Throwable t) { JFLog.log(t); return false;} }
private MethodHandle pcapWrite;
public boolean pcapWrite(long a1,byte[] a2,int a3,int a4) { try { Arena arena = Arena.ofAuto(); MemorySegment _array_a2 = FFM.toMemory(arena, a2);boolean _ret_value_ = (boolean)pcapWrite.invokeExact(a1,_array_a2,a3,a4);FFM.copyBack(_array_a2,a2);return _ret_value_; } catch (Throwable t) { JFLog.log(t); return false;} }
private MethodHandle pcapRead;
public byte[] pcapRead(long a1) { try { FFM.createFFMArray();pcapRead.invokeExact(a1);return (byte[])FFM.getArray(); } catch (Throwable t) { JFLog.log(t); return null;} }
private MethodHandle pcapListLocalInterfaces;
public java.lang.String[] pcapListLocalInterfaces() { try { FFM.createFFMArray();pcapListLocalInterfaces.invokeExact();return (java.lang.String[])FFM.getArray(); } catch (Throwable t) { JFLog.log(t); return null;} }
private MethodHandle pcapStart;
public long pcapStart(java.lang.String a1,boolean a2) { try { Arena arena = Arena.ofAuto(); long _ret_value_ = (long)pcapStart.invokeExact((MemorySegment)(a1 == null ? MemorySegment.NULL : arena.allocateFrom(a1)),a2);return _ret_value_; } catch (Throwable t) { JFLog.log(t); return -1;} }
private MethodHandle pcapStop;
public void pcapStop(long a1) { try { pcapStop.invokeExact(a1); } catch (Throwable t) { JFLog.log(t); } }
private boolean ffm_init() {
if (FFM.debug) JFLog.log("PCapFFM init started");
MethodHandle init;
ffm = FFM.getInstance();
init = ffm.getFunction("PCapAPIinit", ffm.getFunctionDesciptor(ValueLayout.JAVA_BOOLEAN));
if (init == null) return false;
try {if (!(boolean)init.invokeExact()) return false;} catch (Throwable t) {JFLog.log(t); return false;}
pcapCompile = ffm.getFunctionPtr("_pcapCompile", ffm.getFunctionDesciptor(JAVA_BOOLEAN,JAVA_LONG,ADDRESS));
pcapInit = ffm.getFunctionPtr("_pcapInit", ffm.getFunctionDesciptor(JAVA_BOOLEAN,ADDRESS,ADDRESS));
pcapWrite = ffm.getFunctionPtr("_pcapWrite", ffm.getFunctionDesciptor(JAVA_BOOLEAN,JAVA_LONG,ADDRESS,JAVA_INT,JAVA_INT));
pcapRead = ffm.getFunctionPtr("_pcapRead", ffm.getFunctionDesciptorVoid(JAVA_LONG));
pcapListLocalInterfaces = ffm.getFunctionPtr("_pcapListLocalInterfaces", ffm.getFunctionDesciptorVoid());
pcapStart = ffm.getFunctionPtr("_pcapStart", ffm.getFunctionDesciptor(JAVA_LONG,ADDRESS,JAVA_BOOLEAN));
pcapStop = ffm.getFunctionPtr("_pcapStop", ffm.getFunctionDesciptorVoid(JAVA_LONG));
if (FFM.debug) JFLog.log("PCapFFM init complete");
return true;
}
}