Class Wintun
- java.lang.Object
-
- org.drasyl.channel.tun.jna.windows.Wintun
-
public final class Wintun extends Object
JNA mapping for the Wintun Network Adapter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Wintun.WINTUN_ADAPTER_HANDLE
A handle representing Wintun adapter.static class
Wintun.WINTUN_SESSION_HANDLE
A handle representing Wintun session.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.sun.jna.Pointer
WintunAllocateSendPacket(Wintun.WINTUN_SESSION_HANDLE Session, WinDef.DWORD PacketSize)
Allocates memory for a packet to send.static void
WintunCloseAdapter(Wintun.WINTUN_ADAPTER_HANDLE Adapter)
Releases Wintun adapter resources and, if adapter was created with WintunCreateAdapter, removes adapter.static Wintun.WINTUN_ADAPTER_HANDLE
WintunCreateAdapter(com.sun.jna.WString Name, com.sun.jna.WString TunnelType, Guid.GUID RequestedGUID)
Creates a new Wintun adapter.static void
WintunEndSession(Wintun.WINTUN_SESSION_HANDLE Session)
Ends Wintun session.static void
WintunGetAdapterLUID(Wintun.WINTUN_ADAPTER_HANDLE Adapter, com.sun.jna.Pointer Luid)
Returns the LUID of the adapter.static WinNT.HANDLE
WintunGetReadWaitEvent(Wintun.WINTUN_SESSION_HANDLE Session)
Gets Wintun session's read-wait event handle.static WinDef.DWORD
WintunGetRunningDriverVersion()
Determines the version of the Wintun driver currently loaded.static com.sun.jna.Pointer
WintunReceivePacket(Wintun.WINTUN_SESSION_HANDLE Session, com.sun.jna.Pointer PacketSize)
Retrieves one or packet.static void
WintunReleaseReceivePacket(Wintun.WINTUN_SESSION_HANDLE Session, com.sun.jna.Pointer Packet)
Releases internal buffer after the received packet has been processed by the client.static void
WintunSendPacket(Wintun.WINTUN_SESSION_HANDLE Session, com.sun.jna.Pointer Packet)
Sends the packet and releases internal buffer.static Wintun.WINTUN_SESSION_HANDLE
WintunStartSession(Wintun.WINTUN_ADAPTER_HANDLE Adapter, WinDef.DWORD Capacity)
Starts Wintun session.
-
-
-
Method Detail
-
WintunCreateAdapter
public static Wintun.WINTUN_ADAPTER_HANDLE WintunCreateAdapter(com.sun.jna.WString Name, com.sun.jna.WString TunnelType, Guid.GUID RequestedGUID) throws com.sun.jna.LastErrorException
Creates a new Wintun adapter.- Parameters:
Name
- The requested name of the adapter. Zero-terminated string of up to MAX_ADAPTER_NAME-1 characters.TunnelType
- Name of the adapter tunnel type. Zero-terminated string of up to MAX_ADAPTER_NAME-1 characters.RequestedGUID
- The GUID of the created network adapter, which then influences NLA generation deterministically. If it is set to NULL, the GUID is chosen by the system at random, and hence a new NLA entry is created for each new adapter. It is called "requested" GUID because the API it uses is completely undocumented, and so there could be minor interesting complications with its usage.- Returns:
- If the function succeeds, the return value is the adapter handle. Must be released with WintunCloseAdapter. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
- Throws:
com.sun.jna.LastErrorException
-
WintunCloseAdapter
public static void WintunCloseAdapter(Wintun.WINTUN_ADAPTER_HANDLE Adapter) throws com.sun.jna.LastErrorException
Releases Wintun adapter resources and, if adapter was created with WintunCreateAdapter, removes adapter.- Parameters:
Adapter
- Adapter handle obtained with WintunCreateAdapter or WintunOpenAdapter.- Throws:
com.sun.jna.LastErrorException
-
WintunGetAdapterLUID
public static void WintunGetAdapterLUID(Wintun.WINTUN_ADAPTER_HANDLE Adapter, com.sun.jna.Pointer Luid) throws com.sun.jna.LastErrorException
Returns the LUID of the adapter.- Parameters:
Adapter
- Adapter handle obtained with WintunOpenAdapter or WintunCreateAdapter.Luid
- Pointer to LUID to receive adapter LUID.- Throws:
com.sun.jna.LastErrorException
-
WintunGetRunningDriverVersion
public static WinDef.DWORD WintunGetRunningDriverVersion() throws com.sun.jna.LastErrorException
Determines the version of the Wintun driver currently loaded.- Returns:
- If the function succeeds, the return value is the version number. If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible errors include the following: ERROR_FILE_NOT_FOUND Wintun not loaded
- Throws:
com.sun.jna.LastErrorException
-
WintunStartSession
public static Wintun.WINTUN_SESSION_HANDLE WintunStartSession(Wintun.WINTUN_ADAPTER_HANDLE Adapter, WinDef.DWORD Capacity) throws com.sun.jna.LastErrorException
Starts Wintun session.- Parameters:
Adapter
- Adapter handle obtained with WintunOpenAdapter or WintunCreateAdapter.Capacity
- Rings capacity. Must be between WINTUN_MIN_RING_CAPACITY and WINTUN_MAX_RING_CAPACITY (incl.) Must be a power of two.- Returns:
- Wintun session handle. Must be released with WintunEndSession. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
- Throws:
com.sun.jna.LastErrorException
-
WintunEndSession
public static void WintunEndSession(Wintun.WINTUN_SESSION_HANDLE Session) throws com.sun.jna.LastErrorException
Ends Wintun session.- Parameters:
Session
- Wintun session handle obtained with WintunStartSession.- Throws:
com.sun.jna.LastErrorException
-
WintunGetReadWaitEvent
public static WinNT.HANDLE WintunGetReadWaitEvent(Wintun.WINTUN_SESSION_HANDLE Session) throws com.sun.jna.LastErrorException
Gets Wintun session's read-wait event handle.- Parameters:
Session
- Wintun session handle obtained with WintunStartSession.- Returns:
- Pointer to receive event handle to wait for available data when reading. Should WintunReceivePackets return ERROR_NO_MORE_ITEMS (after spinning on it for a while under heavy load), wait for this event to become signaled before retrying WintunReceivePackets. Do not call CloseHandle on this event - it is managed by the session.
- Throws:
com.sun.jna.LastErrorException
-
WintunReceivePacket
public static com.sun.jna.Pointer WintunReceivePacket(Wintun.WINTUN_SESSION_HANDLE Session, com.sun.jna.Pointer PacketSize) throws com.sun.jna.LastErrorException
Retrieves one or packet. After the packet content is consumed, call WintunReleaseReceivePacket with Packet returned from this function to release internal buffer. This function is thread-safe.- Parameters:
Session
- Wintun session handle obtained with WintunStartSession.PacketSize
- Pointer to receive packet size.- Returns:
- Pointer to layer 3 IPv4 or IPv6 packet. Client may modify its content at will. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Possible errors include the following: ERROR_HANDLE_EOF Wintun adapter is terminating; ERROR_NO_MORE_ITEMS Wintun buffer is exhausted; ERROR_INVALID_DATA Wintun buffer is corrupt.
- Throws:
com.sun.jna.LastErrorException
-
WintunReleaseReceivePacket
public static void WintunReleaseReceivePacket(Wintun.WINTUN_SESSION_HANDLE Session, com.sun.jna.Pointer Packet) throws com.sun.jna.LastErrorException
Releases internal buffer after the received packet has been processed by the client. This function is thread-safe.- Parameters:
Session
- Wintun session handle obtained with WintunStartSession.Packet
- Packet obtained with WintunReceivePacket.- Throws:
com.sun.jna.LastErrorException
-
WintunAllocateSendPacket
public static com.sun.jna.Pointer WintunAllocateSendPacket(Wintun.WINTUN_SESSION_HANDLE Session, WinDef.DWORD PacketSize) throws com.sun.jna.LastErrorException
Allocates memory for a packet to send. After the memory is filled with packet data, call WintunSendPacket to send and release internal buffer. WintunAllocateSendPacket is thread-safe and the WintunAllocateSendPacket order of calls define the packet sending order.- Parameters:
Session
- Wintun session handle obtained with WintunStartSession.PacketSize
- Exact packet size. Must be less or equal to WINTUN_MAX_IP_PACKET_SIZE.- Returns:
- Throws:
com.sun.jna.LastErrorException
-
WintunSendPacket
public static void WintunSendPacket(Wintun.WINTUN_SESSION_HANDLE Session, com.sun.jna.Pointer Packet) throws com.sun.jna.LastErrorException
Sends the packet and releases internal buffer. WintunSendPacket is thread-safe, but the WintunAllocateSendPacket order of calls define the packet sending order. This means the packet is not guaranteed to be sent in the WintunSendPacket yet.- Parameters:
Session
- Wintun session handle obtained with WintunStartSession.Packet
- Packet obtained with WintunAllocateSendPacket.- Throws:
com.sun.jna.LastErrorException
-
-