OpenVPN
Data Structures | Functions
tap.h File Reference
#include <windows.h>
#include "basic.h"
Include dependency graph for tap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tap_adapter_node
 Network adapter list node. More...
 

Functions

DWORD tap_create_adapter (_In_opt_ HWND hwndParent, _In_opt_ LPCTSTR szDeviceDescription, _In_ LPCTSTR szHwId, _Inout_ LPBOOL pbRebootRequired, _Out_ LPGUID pguidAdapter)
 Creates a TUN/TAP adapter. More...
 
DWORD tap_delete_adapter (_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _Inout_ LPBOOL pbRebootRequired)
 Deletes an adapter. More...
 
DWORD tap_enable_adapter (_In_opt_ HWND hwndParent, _In_ LPCGUID pguidAdapter, _In_ BOOL bEnable, _Inout_ LPBOOL pbRebootRequired)
 Enables or disables an adapter. More...
 
DWORD tap_set_adapter_name (_In_ LPCGUID pguidAdapter, _In_ LPCTSTR szName, _In_ BOOL bSilent)
 Sets adapter name. More...
 
DWORD tap_list_adapters (_In_opt_ HWND hwndParent, _In_opt_ LPCTSTR szzHwIDs, _Out_ struct tap_adapter_node **ppAdapterList)
 Creates a list of existing network adapters. More...
 
void tap_free_adapter_list (_In_ struct tap_adapter_node *pAdapterList)
 Frees a list of network adapters. More...
 

Function Documentation

◆ tap_create_adapter()

DWORD tap_create_adapter ( _In_opt_ HWND  hwndParent,
_In_opt_ LPCTSTR  szDeviceDescription,
_In_ LPCTSTR  szHwId,
_Inout_ LPBOOL  pbRebootRequired,
_Out_ LPGUID  pguidAdapter 
)

Creates a TUN/TAP adapter.

Parameters
hwndParentA handle to the top-level window to use for any user adapter that is related to non-device-specific actions (such as a select-device dialog box that uses the global class driver list). This handle is optional and can be NULL. If a specific top-level window is not required, set hwndParent to NULL.
szDeviceDescriptionA pointer to a NULL-terminated string that supplies the text description of the device. This pointer is optional and can be NULL.
szHwIdA pointer to a NULL-terminated string that supplies the hardware id of the device (e.g. "root\\tap0901", "Wintun").
pbRebootRequiredA pointer to a BOOL flag. If the device requires a system restart, this flag is set to TRUE. Otherwise, the flag is left unmodified. This allows the flag to be globally initialized to FALSE and reused for multiple adapter manipulations.
pguidAdapterA pointer to GUID that receives network adapter ID.
Returns
ERROR_SUCCESS on success; Win32 error code otherwise

Definition at line 725 of file tap.c.

References check_reboot(), find_function(), get_net_adapter_guid(), GUID_DEVCLASS_NET, M_ERRNO, M_NONFATAL, and msg.

Referenced by _tmain(), and ProcessDeferredAction().

◆ tap_delete_adapter()

DWORD tap_delete_adapter ( _In_opt_ HWND  hwndParent,
_In_ LPCGUID  pguidAdapter,
_Inout_ LPBOOL  pbRebootRequired 
)

Deletes an adapter.

Parameters
hwndParentA handle to the top-level window to use for any user adapter that is related to non-device-specific actions (such as a select-device dialog box that uses the global class driver list). This handle is optional and can be NULL. If a specific top-level window is not required, set hwndParent to NULL.
pguidAdapterA pointer to GUID that contains network adapter ID.
pbRebootRequiredA pointer to a BOOL flag. If the device requires a system restart, this flag is set to TRUE. Otherwise, the flag is left unmodified. This allows the flag to be globally initialized to FALSE and reused for multiple adapter manipulations.
Returns
ERROR_SUCCESS on success; Win32 error code otherwise

Definition at line 1007 of file tap.c.

References delete_device(), and execute_on_first_adapter().

Referenced by _tmain(), and ProcessDeferredAction().

◆ tap_enable_adapter()

DWORD tap_enable_adapter ( _In_opt_ HWND  hwndParent,
_In_ LPCGUID  pguidAdapter,
_In_ BOOL  bEnable,
_Inout_ LPBOOL  pbRebootRequired 
)

Enables or disables an adapter.

Parameters
hwndParentA handle to the top-level window to use for any user adapter that is related to non-device-specific actions (such as a select-device dialog box that uses the global class driver list). This handle is optional and can be NULL. If a specific top-level window is not required, set hwndParent to NULL.
pguidAdapterA pointer to GUID that contains network adapter ID.
bEnableTRUE to enable; FALSE to disable
pbRebootRequiredA pointer to a BOOL flag. If the device requires a system restart, this flag is set to TRUE. Otherwise, the flag is left unmodified. This allows the flag to be globally initialized to FALSE and reused for multiple adapter manipulations.
Returns
ERROR_SUCCESS on success; Win32 error code otherwise

Definition at line 1017 of file tap.c.

References disable_device(), enable_device(), and execute_on_first_adapter().

Referenced by ProcessDeferredAction().

◆ tap_free_adapter_list()

void tap_free_adapter_list ( _In_ struct tap_adapter_node pAdapterList)

Frees a list of network adapters.

Parameters
pAdapterListA pointer to the first adapter in the list to free.

Definition at line 1357 of file tap.c.

References free, and tap_adapter_node::pNext.

Referenced by _tmain(), find_adapters(), ProcessDeferredAction(), schedule_adapter_create(), and schedule_adapter_delete().

◆ tap_list_adapters()

DWORD tap_list_adapters ( _In_opt_ HWND  hwndParent,
_In_opt_ LPCTSTR  szzHwIDs,
_Out_ struct tap_adapter_node **  ppAdapterList 
)

Creates a list of existing network adapters.

Parameters
hwndParentA handle to the top-level window to use for any user adapter that is related to non-device-specific actions (such as a select-device dialog box that uses the global class driver list). This handle is optional and can be NULL. If a specific top-level window is not required, set hwndParent to NULL.
szzHwIDsA string of strings that supplies the list of hardware IDs of the device. This pointer is optional and can be NULL. When NULL, all network adapters found are added to the list.
ppAdapterListA pointer to the list to receive pointer to the first adapter in the list. After the list is no longer required, free it using tap_free_adapter_list().
Returns
ERROR_SUCCESS on success; Win32 error code otherwise

Definition at line 1148 of file tap.c.

References _tcszistr(), _tcszlen(), ADAPTER_REGKEY_PATH_MAX, free, get_device_reg_property(), get_net_adapter_guid(), get_reg_string(), tap_adapter_node::guid, GUID_DEVCLASS_NET, M_ERRNO, M_FATAL, M_NONFATAL, M_WARN, malloc, msg, tap_adapter_node::pNext, PRIsLPOLESTR, PRIsLPTSTR, szAdapterRegKeyPathTemplate, tap_adapter_node::szName, and tap_adapter_node::szzHardwareIDs.

Referenced by _tmain(), find_adapters(), ProcessDeferredAction(), schedule_adapter_create(), and schedule_adapter_delete().

◆ tap_set_adapter_name()

DWORD tap_set_adapter_name ( _In_ LPCGUID  pguidAdapter,
_In_ LPCTSTR  szName,
_In_ BOOL  bSilent 
)

Sets adapter name.

Parameters
pguidAdapterA pointer to GUID that contains network adapter ID.
szNameNew adapter name - must be unique
bSilentIf true, MSI installer won't display message box and only print error to log.
Returns
ERROR_SUCCESS on success; Win32 error code otherwise

Definition at line 1065 of file tap.c.

References ADAPTER_REGKEY_PATH_MAX, ExecCommand(), free, get_reg_string(), GUID_DEVCLASS_NET, M_ERRNO, M_NONFATAL, M_WARN, malloc, msg, PRIsLPTSTR, and szAdapterRegKeyPathTemplate.

Referenced by _tmain(), and ProcessDeferredAction().