mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 17:47:12 -04:00
Add support for connecting to hostnames
This commit is contained in:
parent
c0dff3c980
commit
45768779d9
@ -534,8 +534,7 @@ static void DirectConnectScreen_Load(struct DirectConnectScreen* s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void DirectConnectScreen_StartClient(void* w, int idx) {
|
static void DirectConnectScreen_StartClient(void* w, int idx) {
|
||||||
static const cc_string loopbackIp = String_FromConst("127.0.0.1");
|
static const cc_string defMppass = String_FromConst("(none)");
|
||||||
static const cc_string defMppass = String_FromConst("(none)");
|
|
||||||
const cc_string* user = &DirectConnectScreen_Instance.iptUsername.text;
|
const cc_string* user = &DirectConnectScreen_Instance.iptUsername.text;
|
||||||
const cc_string* addr = &DirectConnectScreen_Instance.iptAddress.text;
|
const cc_string* addr = &DirectConnectScreen_Instance.iptAddress.text;
|
||||||
const cc_string* mppass = &DirectConnectScreen_Instance.iptMppass.text;
|
const cc_string* mppass = &DirectConnectScreen_Instance.iptMppass.text;
|
||||||
@ -550,7 +549,6 @@ static void DirectConnectScreen_StartClient(void* w, int idx) {
|
|||||||
|
|
||||||
ip = String_UNSAFE_Substring(addr, 0, index);
|
ip = String_UNSAFE_Substring(addr, 0, index);
|
||||||
port = String_UNSAFE_SubstringAt(addr, index + 1);
|
port = String_UNSAFE_SubstringAt(addr, index + 1);
|
||||||
if (String_CaselessEqualsConst(&ip, "localhost")) ip = loopbackIp;
|
|
||||||
|
|
||||||
if (!user->length) {
|
if (!user->length) {
|
||||||
DirectConnectScreen_SetStatus("&eUsername required"); return;
|
DirectConnectScreen_SetStatus("&eUsername required"); return;
|
||||||
|
@ -459,6 +459,32 @@ cc_result Socket_GetError(cc_socket s, cc_result* result) {
|
|||||||
return getsockopt(s, SOL_SOCKET, SO_ERROR, result, &resultSize);
|
return getsockopt(s, SOL_SOCKET, SO_ERROR, result, &resultSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ParseHost(void* dst, const char* host, int port, int* addrSize) {
|
||||||
|
struct addrinfo hints = { 0 };
|
||||||
|
struct addrinfo* result;
|
||||||
|
struct addrinfo* cur;
|
||||||
|
int family = 0, res;
|
||||||
|
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
|
|
||||||
|
res = getaddrinfo(host, NULL, &hints, &result);
|
||||||
|
if (res) return 0;
|
||||||
|
|
||||||
|
for (cur = result; cur; cur = cur->ai_next) {
|
||||||
|
if (cur->ai_family != AF_INET) continue;
|
||||||
|
family = AF_INET;
|
||||||
|
|
||||||
|
Mem_Copy(dst, cur->ai_addr, cur->ai_addrlen);
|
||||||
|
*addrSize = cur->ai_addrlen;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
freeaddrinfo(result);
|
||||||
|
return family;
|
||||||
|
}
|
||||||
|
|
||||||
static int ParseAddress(void* dst, const cc_string* address, int port, int* addrSize) {
|
static int ParseAddress(void* dst, const cc_string* address, int port, int* addrSize) {
|
||||||
struct sockaddr_in* addr4 = (struct sockaddr_in* )dst;
|
struct sockaddr_in* addr4 = (struct sockaddr_in* )dst;
|
||||||
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)dst;
|
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)dst;
|
||||||
@ -477,7 +503,7 @@ static int ParseAddress(void* dst, const cc_string* address, int port, int* addr
|
|||||||
*addrSize = sizeof(struct sockaddr_in6);
|
*addrSize = sizeof(struct sockaddr_in6);
|
||||||
return AF_INET6;
|
return AF_INET6;
|
||||||
}
|
}
|
||||||
return 0;
|
return ParseHost(dst, str, port, addrSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket_ValidAddress(const cc_string* address) {
|
int Socket_ValidAddress(const cc_string* address) {
|
||||||
|
@ -379,7 +379,55 @@ void Platform_LoadSysFonts(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------Socket----------------------------------------------------------*
|
*---------------------------------------------------------Socket----------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static INT (WSAAPI *_WSAStringToAddressW)(LPWSTR addressString, INT addressFamily, LPVOID lpProtocolInfo, LPVOID address, LPINT addressLength);
|
static INT (WSAAPI *_WSAStringToAddressW)(LPWSTR addressString, INT addressFamily, LPVOID protocolInfo, LPVOID address, LPINT addressLength);
|
||||||
|
static INT (WSAAPI *_getaddrinfo)(PCSTR nodeName, PCSTR serviceName, const ADDRINFOA* hints, ADDRINFOA** result);
|
||||||
|
static void (WSAAPI *_freeaddrinfo)(ADDRINFOA* addrInfo);
|
||||||
|
|
||||||
|
static void LoadWinsockFuncs(void) {
|
||||||
|
static const struct DynamicLibSym funcs[] = {
|
||||||
|
DynamicLib_Sym(WSAStringToAddressW), DynamicLib_Sym(getaddrinfo),
|
||||||
|
DynamicLib_Sym(freeaddrinfo),
|
||||||
|
};
|
||||||
|
|
||||||
|
static const cc_string winsock32 = String_FromConst("WS2_32.DLL");
|
||||||
|
LoadDynamicFuncs(&winsock32, funcs, Array_Elems(funcs));
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_result Socket_Available(cc_socket s, int* available) {
|
||||||
|
return ioctlsocket(s, FIONREAD, available);
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_result Socket_GetError(cc_socket s, cc_result* result) {
|
||||||
|
socklen_t resultSize = sizeof(cc_result);
|
||||||
|
return getsockopt(s, SOL_SOCKET, SO_ERROR, result, &resultSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ParseHost(void* dst, WCHAR* host, int port) {
|
||||||
|
ADDRINFOA hints = { 0 };
|
||||||
|
ADDRINFOA* result;
|
||||||
|
ADDRINFOA* cur;
|
||||||
|
int family = 0, res;
|
||||||
|
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_protocol = IPPROTO_TCP;
|
||||||
|
|
||||||
|
Platform_Utf16ToAnsi(host);
|
||||||
|
res = _getaddrinfo((char*)host, NULL, &hints, &result);
|
||||||
|
if (res) return 0;
|
||||||
|
|
||||||
|
for (cur = result; cur; cur = cur->ai_next) {
|
||||||
|
if (cur->ai_family != AF_INET) continue;
|
||||||
|
family = AF_INET;
|
||||||
|
|
||||||
|
Mem_Copy(dst, cur->ai_addr, cur->ai_addrlen);
|
||||||
|
((SOCKADDR_IN*)dst)->sin_port = htons(port);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_freeaddrinfo(result);
|
||||||
|
return family;
|
||||||
|
}
|
||||||
|
|
||||||
static int FallbackParseAddress(SOCKADDR_IN* dst, const cc_string* ip, int port) {
|
static int FallbackParseAddress(SOCKADDR_IN* dst, const cc_string* ip, int port) {
|
||||||
cc_uint8* addr;
|
cc_uint8* addr;
|
||||||
@ -397,24 +445,6 @@ static int FallbackParseAddress(SOCKADDR_IN* dst, const cc_string* ip, int port)
|
|||||||
return AF_INET;
|
return AF_INET;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadWinsockFuncs(void) {
|
|
||||||
static const struct DynamicLibSym funcs[1] = {
|
|
||||||
DynamicLib_Sym(WSAStringToAddressW)
|
|
||||||
};
|
|
||||||
|
|
||||||
static const cc_string winsock32 = String_FromConst("WS2_32.DLL");
|
|
||||||
LoadDynamicFuncs(&winsock32, funcs, Array_Elems(funcs));
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_result Socket_Available(cc_socket s, int* available) {
|
|
||||||
return ioctlsocket(s, FIONREAD, available);
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_result Socket_GetError(cc_socket s, cc_result* result) {
|
|
||||||
socklen_t resultSize = sizeof(cc_result);
|
|
||||||
return getsockopt(s, SOL_SOCKET, SO_ERROR, result, &resultSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int Socket_ParseAddress(void* dst, const cc_string* address, int port) {
|
static int Socket_ParseAddress(void* dst, const cc_string* address, int port) {
|
||||||
SOCKADDR_IN* addr4 = (SOCKADDR_IN*)dst;
|
SOCKADDR_IN* addr4 = (SOCKADDR_IN*)dst;
|
||||||
SOCKADDR_IN6* addr6 = (SOCKADDR_IN6*)dst;
|
SOCKADDR_IN6* addr6 = (SOCKADDR_IN6*)dst;
|
||||||
@ -436,7 +466,9 @@ static int Socket_ParseAddress(void* dst, const cc_string* address, int port) {
|
|||||||
addr6->sin6_port = htons(port);
|
addr6->sin6_port = htons(port);
|
||||||
return AF_INET6;
|
return AF_INET6;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
if (!_getaddrinfo) return 0;
|
||||||
|
return ParseHost(dst, str, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Socket_ValidAddress(const cc_string* address) {
|
int Socket_ValidAddress(const cc_string* address) {
|
||||||
@ -720,7 +752,7 @@ static BOOL (WINAPI *_AttachConsole)(DWORD processId);
|
|||||||
static BOOL (WINAPI *_IsDebuggerPresent)(void);
|
static BOOL (WINAPI *_IsDebuggerPresent)(void);
|
||||||
|
|
||||||
static void LoadKernelFuncs(void) {
|
static void LoadKernelFuncs(void) {
|
||||||
static const struct DynamicLibSym funcs[2] = {
|
static const struct DynamicLibSym funcs[] = {
|
||||||
DynamicLib_Sym(AttachConsole), DynamicLib_Sym(IsDebuggerPresent)
|
DynamicLib_Sym(AttachConsole), DynamicLib_Sym(IsDebuggerPresent)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -778,7 +810,7 @@ static BOOL (WINAPI *_CryptProtectData )(DATA_BLOB* dataIn, PCWSTR dataDescr, P
|
|||||||
static BOOL (WINAPI *_CryptUnprotectData)(DATA_BLOB* dataIn, PWSTR* dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
|
static BOOL (WINAPI *_CryptUnprotectData)(DATA_BLOB* dataIn, PWSTR* dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
|
||||||
|
|
||||||
static void LoadCryptFuncs(void) {
|
static void LoadCryptFuncs(void) {
|
||||||
static const struct DynamicLibSym funcs[2] = {
|
static const struct DynamicLibSym funcs[] = {
|
||||||
DynamicLib_Sym(CryptProtectData), DynamicLib_Sym(CryptUnprotectData)
|
DynamicLib_Sym(CryptProtectData), DynamicLib_Sym(CryptUnprotectData)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user