api: rename ReceiveRelease to ReleaseReceivePacket
This makes the API parallel: Wintun*Allocate*SendPacket -> WintunSendPacket WintunReceivePacket -> Wintun*Release*ReceivePacket Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
6afbb300b9
commit
e9e790605a
10
README.md
10
README.md
@ -38,7 +38,7 @@ else if (GetLastError() != ERROR_BUFFER_OVERFLOW) // Silently drop packets if th
|
|||||||
Log(L"Packet write failed");
|
Log(L"Packet write failed");
|
||||||
```
|
```
|
||||||
|
|
||||||
And the `WintunReceivePacket` and `WintunReceiveRelease` functions can be used for receiving packets ([used by `ReceivePackets` in the example.c code](https://git.zx2c4.com/wintun/tree/example/example.c)):
|
And the `WintunReceivePacket` and `WintunReleaseReceivePacket` functions can be used for receiving packets ([used by `ReceivePackets` in the example.c code](https://git.zx2c4.com/wintun/tree/example/example.c)):
|
||||||
|
|
||||||
```C
|
```C
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -48,7 +48,7 @@ for (;;)
|
|||||||
if (IncomingPacket)
|
if (IncomingPacket)
|
||||||
{
|
{
|
||||||
DoSomethingWithPacket(IncomingPacket, IncomingPacketSize);
|
DoSomethingWithPacket(IncomingPacket, IncomingPacketSize);
|
||||||
WintunReceiveRelease(Session, IncomingPacket);
|
WintunReleaseReceivePacket(Session, IncomingPacket);
|
||||||
}
|
}
|
||||||
else if (GetLastError() == ERROR_NO_MORE_ITEMS)
|
else if (GetLastError() == ERROR_NO_MORE_ITEMS)
|
||||||
WaitForSingleObject(WintunGetReadWaitEvent(Session), INFINITE);
|
WaitForSingleObject(WintunGetReadWaitEvent(Session), INFINITE);
|
||||||
@ -361,7 +361,7 @@ Pointer to receive event handle to wait for available data when reading. Should
|
|||||||
|
|
||||||
`BYTE* WintunReceivePacket (WINTUN_SESSION_HANDLE Session, DWORD * PacketSize)`
|
`BYTE* WintunReceivePacket (WINTUN_SESSION_HANDLE Session, DWORD * PacketSize)`
|
||||||
|
|
||||||
Retrieves one or packet. After the packet content is consumed, call WintunReceiveRelease with Packet returned from this function to release internal buffer. This function is thread-safe.
|
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**
|
**Parameters**
|
||||||
|
|
||||||
@ -372,9 +372,9 @@ Retrieves one or packet. After the packet content is consumed, call WintunReceiv
|
|||||||
|
|
||||||
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
|
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
|
||||||
|
|
||||||
#### WintunReceiveRelease()
|
#### WintunReleaseReceivePacket()
|
||||||
|
|
||||||
`void WintunReceiveRelease (WINTUN_SESSION_HANDLE Session, const BYTE * Packet)`
|
`void WintunReleaseReceivePacket (WINTUN_SESSION_HANDLE Session, const BYTE * Packet)`
|
||||||
|
|
||||||
Releases internal buffer after the received packet has been processed by the client. This function is thread-safe.
|
Releases internal buffer after the received packet has been processed by the client. This function is thread-safe.
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ EXPORTS
|
|||||||
WintunGetReadWaitEvent
|
WintunGetReadWaitEvent
|
||||||
WintunGetRunningDriverVersion
|
WintunGetRunningDriverVersion
|
||||||
WintunReceivePacket
|
WintunReceivePacket
|
||||||
WintunReceiveRelease
|
WintunReleaseReceivePacket
|
||||||
WintunSendPacket
|
WintunSendPacket
|
||||||
WintunSetAdapterName
|
WintunSetAdapterName
|
||||||
WintunSetLogger
|
WintunSetLogger
|
||||||
|
@ -222,7 +222,7 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WINAPI
|
void WINAPI
|
||||||
WintunReceiveRelease(_In_ TUN_SESSION *Session, _In_ const BYTE *Packet)
|
WintunReleaseReceivePacket(_In_ TUN_SESSION *Session, _In_ const BYTE *Packet)
|
||||||
{
|
{
|
||||||
EnterCriticalSection(&Session->Send.Lock);
|
EnterCriticalSection(&Session->Send.Lock);
|
||||||
TUN_PACKET *ReleasedBuffPacket = (TUN_PACKET *)(Packet - offsetof(TUN_PACKET, Data));
|
TUN_PACKET *ReleasedBuffPacket = (TUN_PACKET *)(Packet - offsetof(TUN_PACKET, Data));
|
||||||
|
12
api/wintun.h
12
api/wintun.h
@ -41,7 +41,7 @@ typedef void *WINTUN_ADAPTER_HANDLE;
|
|||||||
* @return If the function succeeds, the return value is the adapter handle. Must be released with WintunFreeAdapter. If
|
* @return If the function succeeds, the return value is the adapter handle. Must be released with WintunFreeAdapter. If
|
||||||
* the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
* the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
||||||
*/
|
*/
|
||||||
typedef _Return_type_success_(return != NULL) WINTUN_ADAPTER_HANDLE (WINAPI *WINTUN_CREATE_ADAPTER_FUNC)(
|
typedef _Return_type_success_(return != NULL) WINTUN_ADAPTER_HANDLE(WINAPI *WINTUN_CREATE_ADAPTER_FUNC)(
|
||||||
_In_z_ const WCHAR *Pool,
|
_In_z_ const WCHAR *Pool,
|
||||||
_In_z_ const WCHAR *Name,
|
_In_z_ const WCHAR *Name,
|
||||||
_In_opt_ const GUID *RequestedGUID,
|
_In_opt_ const GUID *RequestedGUID,
|
||||||
@ -104,10 +104,8 @@ typedef BOOL(CALLBACK *WINTUN_ENUM_CALLBACK)(_In_ WINTUN_ADAPTER_HANDLE Adapter,
|
|||||||
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To
|
* @return If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To
|
||||||
* get extended error information, call GetLastError.
|
* get extended error information, call GetLastError.
|
||||||
*/
|
*/
|
||||||
typedef _Return_type_success_(return != FALSE) BOOL(WINAPI *WINTUN_ENUM_ADAPTERS_FUNC)(
|
typedef _Return_type_success_(return != FALSE) BOOL(
|
||||||
_In_z_ const WCHAR *Pool,
|
WINAPI *WINTUN_ENUM_ADAPTERS_FUNC)(_In_z_ const WCHAR *Pool, _In_ WINTUN_ENUM_CALLBACK Callback, _In_ LPARAM Param);
|
||||||
_In_ WINTUN_ENUM_CALLBACK Callback,
|
|
||||||
_In_ LPARAM Param);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases Wintun adapter resources.
|
* Releases Wintun adapter resources.
|
||||||
@ -273,7 +271,7 @@ typedef HANDLE(WINAPI *WINTUN_GET_READ_WAIT_EVENT_FUNC)(_In_ WINTUN_SESSION_HAND
|
|||||||
#define WINTUN_MAX_IP_PACKET_SIZE 0xFFFF
|
#define WINTUN_MAX_IP_PACKET_SIZE 0xFFFF
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves one or packet. After the packet content is consumed, call WintunReceiveRelease with Packet returned
|
* 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.
|
* from this function to release internal buffer. This function is thread-safe.
|
||||||
*
|
*
|
||||||
* @param Session Wintun session handle obtained with WintunStartSession
|
* @param Session Wintun session handle obtained with WintunStartSession
|
||||||
@ -297,7 +295,7 @@ typedef _Return_type_success_(return != NULL) _Ret_bytecount_(*PacketSize) BYTE
|
|||||||
*
|
*
|
||||||
* @param Packet Packet obtained with WintunReceivePacket
|
* @param Packet Packet obtained with WintunReceivePacket
|
||||||
*/
|
*/
|
||||||
typedef void(WINAPI *WINTUN_RECEIVE_RELEASE_FUNC)(_In_ WINTUN_SESSION_HANDLE Session, _In_ const BYTE *Packet);
|
typedef void(WINAPI *WINTUN_RELEASE_RECEIVE_PACKET_FUNC)(_In_ WINTUN_SESSION_HANDLE Session, _In_ const BYTE *Packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocates memory for a packet to send. After the memory is filled with packet data, call WintunSendPacket to send
|
* Allocates memory for a packet to send. After the memory is filled with packet data, call WintunSendPacket to send
|
||||||
|
@ -28,7 +28,7 @@ static WINTUN_START_SESSION_FUNC WintunStartSession;
|
|||||||
static WINTUN_END_SESSION_FUNC WintunEndSession;
|
static WINTUN_END_SESSION_FUNC WintunEndSession;
|
||||||
static WINTUN_GET_READ_WAIT_EVENT_FUNC WintunGetReadWaitEvent;
|
static WINTUN_GET_READ_WAIT_EVENT_FUNC WintunGetReadWaitEvent;
|
||||||
static WINTUN_RECEIVE_PACKET_FUNC WintunReceivePacket;
|
static WINTUN_RECEIVE_PACKET_FUNC WintunReceivePacket;
|
||||||
static WINTUN_RECEIVE_RELEASE_FUNC WintunReceiveRelease;
|
static WINTUN_RELEASE_RECEIVE_PACKET_FUNC WintunReleaseReceivePacket;
|
||||||
static WINTUN_ALLOCATE_SEND_PACKET_FUNC WintunAllocateSendPacket;
|
static WINTUN_ALLOCATE_SEND_PACKET_FUNC WintunAllocateSendPacket;
|
||||||
static WINTUN_SEND_PACKET_FUNC WintunSendPacket;
|
static WINTUN_SEND_PACKET_FUNC WintunSendPacket;
|
||||||
|
|
||||||
@ -50,7 +50,8 @@ InitializeWintun(void)
|
|||||||
X(WintunGetRunningDriverVersion, WINTUN_GET_RUNNING_DRIVER_VERSION_FUNC) ||
|
X(WintunGetRunningDriverVersion, WINTUN_GET_RUNNING_DRIVER_VERSION_FUNC) ||
|
||||||
X(WintunSetLogger, WINTUN_SET_LOGGER_FUNC) || X(WintunStartSession, WINTUN_START_SESSION_FUNC) ||
|
X(WintunSetLogger, WINTUN_SET_LOGGER_FUNC) || X(WintunStartSession, WINTUN_START_SESSION_FUNC) ||
|
||||||
X(WintunEndSession, WINTUN_END_SESSION_FUNC) || X(WintunGetReadWaitEvent, WINTUN_GET_READ_WAIT_EVENT_FUNC) ||
|
X(WintunEndSession, WINTUN_END_SESSION_FUNC) || X(WintunGetReadWaitEvent, WINTUN_GET_READ_WAIT_EVENT_FUNC) ||
|
||||||
X(WintunReceivePacket, WINTUN_RECEIVE_PACKET_FUNC) || X(WintunReceiveRelease, WINTUN_RECEIVE_RELEASE_FUNC) ||
|
X(WintunReceivePacket, WINTUN_RECEIVE_PACKET_FUNC) ||
|
||||||
|
X(WintunReleaseReceivePacket, WINTUN_RELEASE_RECEIVE_PACKET_FUNC) ||
|
||||||
X(WintunAllocateSendPacket, WINTUN_ALLOCATE_SEND_PACKET_FUNC) || X(WintunSendPacket, WINTUN_SEND_PACKET_FUNC))
|
X(WintunAllocateSendPacket, WINTUN_ALLOCATE_SEND_PACKET_FUNC) || X(WintunSendPacket, WINTUN_SEND_PACKET_FUNC))
|
||||||
#undef X
|
#undef X
|
||||||
{
|
{
|
||||||
@ -250,7 +251,7 @@ ReceivePackets(_Inout_ DWORD_PTR SessionPtr)
|
|||||||
if (Packet)
|
if (Packet)
|
||||||
{
|
{
|
||||||
PrintPacket(Packet, PacketSize);
|
PrintPacket(Packet, PacketSize);
|
||||||
WintunReceiveRelease(Session, Packet);
|
WintunReleaseReceivePacket(Session, Packet);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user