NetTunnelWindows/NetTunnelSDK/misc.h

113 lines
3.9 KiB
C
Raw Normal View History

2023-06-15 01:35:37 +00:00
#pragma once
#include "tunnel.h"
#include <windows.h>
#define CFG_WIREGUARD_SECTION TEXT("WireGuard")
#define CFG_WIREGUARD_PATH TEXT("WireGuardExe")
#define CFG_WGCFG_PATH TEXT("WgCfgPath")
#define CFG_WG_PATH TEXT("WgExe")
typedef struct {
TCHAR path[MAX_PATH];
} FILE_PATH, *PFILE_PATH;
typedef struct {
PFILE_PATH pFilePath;
unsigned int nItems;
} FILE_LIST, *PFILE_LIST;
/**
* @brief IPv4
*/
typedef struct {
unsigned int prefix; ///< 网络前缀
TCHAR hostip[MAX_IP_LEN]; ///< IP 地址
TCHAR ip[MAX_IP_LEN]; ///< IP 地址
TCHAR network[MAX_IP_LEN]; ///< 网络地址
TCHAR broadcast[MAX_IP_LEN]; ///< 网络广播地址
TCHAR netmask[MAX_IP_LEN]; ///< 网络子网掩码
TCHAR hosts[64]; ///< number of hosts in text
TCHAR hostmin[MAX_IP_LEN]; ///< 最小网络主机 IP
TCHAR hostmax[MAX_IP_LEN]; ///< 最大网络主机 IP
} IP_INFO, *PIP_INFO;
#ifdef __cplusplus // If used by C++ code,
extern "C" {
// we need to export the C interface
#endif
void RemoveTailLineBreak(TCHAR *pInputStr, int strSize);
int RunCommand(TCHAR *pszCmd, TCHAR *pszResultBuffer, int dwResultBufferSize, unsigned long *pRetCode);
2023-06-21 10:04:16 +00:00
/**
* @brief IPv4 CIDR
* @param[in] pNetMask IPv4
* @return IPv4 CIDR
*/
int __cdecl NetmaskToCIDR(const TCHAR *pNetMask);
/**
* @brief CIDR IPv4
* @param[in] cidr CIDR
* @return CIDR
*/
const TCHAR *CIDRToNetmask(const UINT8 cidr);
void ShowWindowsErrorMessage(const TCHAR *pMsgHead);
void StringReplaceAll(TCHAR *pOrigin, const TCHAR *pOldStr, const TCHAR *pNewStr);
void StringRemoveAll(TCHAR *pOrigin, const TCHAR *pString);
TCHAR *binToHexString(TCHAR *p, const unsigned char *cp, unsigned int count);
int GetWindowsServiceStatus(const TCHAR *pSvrName, PDWORD pStatus);
/**
* @brief Unicode TCHAR
* @param[in] pWStr
* @param[out] pOutStr TCHAR
* @param[in] maxOutLen pOutStr
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
int WideCharToTChar(const WCHAR *pWStr, TCHAR *pOutStr, int maxOutLen);
/**
* @brief TCHAR Unicode
* @param[in] pTStr TCHAR
* @param[out] pOutStr WCHAR
* @param[in] maxOutLen pOutStr
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
int TCharToWideChar(const TCHAR *pTStr, WCHAR *pOutStr, int maxOutLen);
int FindFile(const TCHAR *pPath, PFILE_LIST pFileList, const bool exitWhenMatchOne);
/**
* @brief IPv4
* @param[in] pIpStr IPv4
* @param[in] pNetmask IPv4子网掩码
* @param[out] pInfo
* @return 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_UN_SUPPORT
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
int GetIpV4InfoFromNetmask(const TCHAR *pIpStr, const TCHAR *pNetmask, PIP_INFO pInfo);
/**
* @brief IPv4
* @param[in] pIpStr IPv4 '/' CIDR以及子网掩码 example: 192.168.1.32/24, 192.168.1.32/255.255.255.0
* @param[out] pInfo
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_UN_SUPPORT
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
int GetIpV4InfoFromCIDR(const TCHAR *pIpStr, PIP_INFO pInfo);
int GetIpV4InfoFromHostname(int family, const char *host, PIP_INFO pInfo);
#ifdef __cplusplus
}
#endif