NetTunnelWindows/NetTunnelSDK/network.h

373 lines
14 KiB
C
Raw Normal View History

#pragma once
#include <Windows.h>
#ifdef NETTUNNELSDK_EXPORTS
#define NETWORK_API __declspec(dllexport)
#else
#define NETWORK_API __declspec(dllimport)
#endif
/**
*
* @brief
*/
typedef struct {
int InterfaceIndex; ///< 网卡索引
TCHAR NetCardUUID[260]; ///< 网卡名称, Windows标识为 UUID
TCHAR NetCardName[MAX_NETCARD_NAME]; ///< 网卡名称
TCHAR NetCardDescription[132]; ///< 网卡描述
TCHAR NetCardIpaddr[MAX_IP_LEN]; ///< 网卡 IP 地址
TCHAR NetCardNetmask[MAX_IP_LEN]; ///< 网卡子网掩码
TCHAR NetCardGateway[MAX_IP_LEN]; ///< 网卡网关
TCHAR NetCardMacAddr[20]; ///< 网卡 MAC 地址
} NIC_CONTENT, *PNIC_CONTENT;
#ifdef __cplusplus // If used by C++ code,
extern "C" {
// we need to export the C interface
#endif
/**
* @brief
* @param[out] pInfo @see NIC_CONTENT
* @param[out] pItemCounts 32
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetAllNICInfo(PNIC_CONTENT *pInfo, int *pItemCounts);
/**
* @brief Internet
* @param[out] pIfIndex
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS Internet
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetInternetIfIndex(int *pIfIndex);
/**
* @brief IP地址
* @param[in] pIpAddr IP地址
* @param[out] pIfIndex
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_ITEM_UNEXISTS
* - -ERR_UN_SUPPORT
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetInterfaceIfIndexByIpAddr(const TCHAR *pIpAddr, ULONG *pIfIndex);
/**
* @brief GUDI
* @param[in] pGUID GUID
* @param[out] ifName
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_CREATE_COMMOBJECT COM
* - -ERR_SYS_CALL COM
* - -ERR_ITEM_UNEXISTS GUID
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetInterfaceNameByGUID(const TCHAR *pGUID, TCHAR ifName[MAX_NETCARD_NAME]);
/**
* @brief
* @param[in] pInterfaceName
* @param[out] pIfIndex Index
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_SYS_CALL
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetInterfaceIfIndexByName(const TCHAR *pInterfaceName, int *pIfIndex);
/**
* @brief GUID
* @param[in] ifIndex
* @param[out] pGuid GUID
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_MEMORY_STR GUID
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetInterfaceGUIDByIfIndex(const int ifIndex, GUID *pGuid);
/**
* @brief GUID
* @param[in] pInterfaceName
* @param[out] pGuid GUID
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_MEMORY_STR GUID
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetInterfaceGUIDByName(const TCHAR *pInterfaceName, GUID *pGuid);
TUNNEL_API int __cdecl WaitNetAdapterConnected(const TCHAR *pInterfaceName, int timeOutOfMs);
/**
* @brief Internet
* @param[in] ifIndex
* @param[in] pRet
* - TRUE Internet
* - FALSE Internet
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_GET_IPFOWARDTBL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl IsInternetConnectAdapter(int ifIndex, bool *pRet);
/**
* @brief NetworkCategory Private
* @param[in] pInterfaceName
* @param[out] pIsPrivate
* - TRUE Private
* - FALSE Public
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_CREATE_COMMOBJECT COM
* - -ERR_SYS_CALL COM
* - -ERR_ITEM_UNEXISTS
* - -ERR_MEMORY_STR
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetNetConnectionNetworkCategory(const TCHAR *pInterfaceName, bool *pIsPrivate);
/**
* @brief / Windows
* @param[in] ifIndex
* @param[in] isEnable / Windows
* - TRUE
* - FALSE
* @param[in] isSetPrivate
* -TRUE
* -FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_CREATE_COMMOBJECT COM
* - -ERR_SYS_CALL COM
* - -ERR_ITEM_UNEXISTS GUID
* - -ERR_NET_UNCONNECT
* - ERR_SUCCESS
*/
NETWORK_API int __cdecl SetNetIntelnetConnectionSharing(int ifIndex, bool isEnable, bool isSetPrivate);
/**
* @brief
* @param[in] ifIndex
* @param[out] pIsEnable
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_CREATE_COMMOBJECT COM
* - -ERR_SYS_CALL COM
* - -ERR_ITEM_UNEXISTS GUID
* - -ERR_NET_UNCONNECT
* - -ERR_CALL_COMMOBJECT
* - ERR_SUCCESS
*/
NETWORK_API int __cdecl GetNetIntelnetConnectionSharing(int ifIndex, bool *pIsEnable);
/**
* @brief Private/Public
* @param[in] pInterfaceName pInterfaceName
* @param[in] isPrivate Category
* - TRUE Private
* - FALSE Public
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
NETWORK_API int __cdecl SetNetConnectionNetworkCategory(const TCHAR *pInterfaceName, const bool isPrivate);
/**
* @brief
* @param[in] pIP IP
* @param[in] pMask
* @param[in] pGateway
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_UN_SUPPORT IP地址转网络字节序网络地址失败
* - -ERR_NET_ADD_ROUTE
* - -ERR_NET_REMOVE_ROUTE
* - ERR_SUCCESS
*/
NETWORK_API int __cdecl AddRouteTable(const char *pIP, const char *pMask, const char *pGateway);
/**
* @brief Windows WireGuard NAT
* @param[in] pInterfaceName
* @param[in] pCidrIpaddr CIDR
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetNATRule(const TCHAR *pInterfaceName, const TCHAR *pCidrIpaddr);
/**
* @brief Windows WireGuard NAT
* @param pInterfaceName
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl RemoveNATRule(const TCHAR *pInterfaceName);
TUNNEL_API int __cdecl CreatePorxyService();
#if 0
/**
* @brief Windows Hyper-V NAT转发功能
* @param[out] pEnabled Hyper-V , TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetWindowsHyperVStatus(int *pEnabled);
/**
* @brief / Windows Hyper-V
* @param[in] enabled TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl EnableWindowsHyperV(bool enabled);
/**
* @brief Private/Public
* @param[in] pInterfaceName
* @param[in] isPrivate
* - TRUE Private
* - FALSE Public
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetInterfacePrivate(const TCHAR *pInterfaceName, bool isPrivate);
/**
* @brief NetworkCategory Private
* @param[in] pInterfaceName
* @param[out] pIsPrivateMode
* - TRUE Private
* - FALSE Public
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_ITEM_UNEXISTS
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl IsInterfacePrivate(const TCHAR *pInterfaceName, bool *pIsPrivateMode);
/**
* @brief
* @param[in] pInterfaceName
* @param[out] pIndex
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetInterfaceIndexByName(const TCHAR *pInterfaceName, int *pIndex);
/**
* @brief
* @param[in] pInterfaceName
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl RemoveInterfaceIpAddress(const TCHAR *pInterfaceName);
/**
* @brief IP地址
* @param[in] pInterfaceName
* @param[in] pCidrIpaddr CIDR类型IP地址
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetInterfaceIpAddressFromCIDR(const TCHAR *pInterfaceName, const TCHAR *pCidrIpaddr);
/**
* @brief IP地址
* @param[in] pInterfaceName
* @param[in] pIpaddr IP
* @param[in] pNetmask
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_MEMORY_STR
* - -ERR_CALL_SHELL
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetInterfaceIpAddress(const TCHAR *pInterfaceName, const TCHAR *pIpaddr, const TCHAR *pNetmask);
/**
* @brief NAT功能是否开启
* @param[in] pInterfaceName
* @param[out] pIsEnabled NAT当前是否开启
* - TRUE NAT
* - FALSE NAT
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MEMORY_STR
* - -ERR_ITEM_UNEXISTS
* - -ERR_CALL_SHELL
* - -ERR_PROCESS_RETURN
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl IsNetConnectionSharingEnabled(const TCHAR *pInterfaceName, bool *pIsEnabled);
/**
* @brief WireGuard Windows PowerShell
* @return
* - TRUE
* - FALSE
*/
TUNNEL_API bool __cdecl IsCustomNatPSCmdInstalled();
#endif
#ifdef __cplusplus
}
#endif