Fix not connecting on old macOS

This commit is contained in:
UnknownShadow200 2021-06-04 19:35:43 +10:00
parent 9a9114a9f9
commit 50b084dfbd
3 changed files with 12 additions and 7 deletions

View File

@ -41,7 +41,7 @@ endif
ifeq ($(PLAT),darwin)
LIBS=
LDFLAGS=-rdynamic -framework Carbon -framework AGL -framework OpenGL
LDFLAGS=-rdynamic -framework Carbon -framework AGL -framework OpenGL -framework IOKit
endif
ifeq ($(PLAT),freebsd)

View File

@ -459,7 +459,7 @@ cc_result Socket_GetError(cc_socket s, cc_result* result) {
return getsockopt(s, SOL_SOCKET, SO_ERROR, result, &resultSize);
}
static int Socket_ParseAddress(void* dst, const cc_string* address, int port) {
static int ParseAddress(void* dst, const cc_string* address, int port, int* addrSize) {
struct sockaddr_in* addr4 = (struct sockaddr_in* )dst;
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)dst;
char str[NATIVE_STR_LEN];
@ -468,11 +468,13 @@ static int Socket_ParseAddress(void* dst, const cc_string* address, int port) {
if (inet_pton(AF_INET, str, &addr4->sin_addr) > 0) {
addr4->sin_family = AF_INET;
addr4->sin_port = htons(port);
*addrSize = sizeof(struct sockaddr_in);
return AF_INET;
}
if (inet_pton(AF_INET6, str, &addr6->sin6_addr) > 0) {
addr6->sin6_family = AF_INET6;
addr6->sin6_port = htons(port);
*addrSize = sizeof(struct sockaddr_in6);
return AF_INET6;
}
return 0;
@ -480,23 +482,24 @@ static int Socket_ParseAddress(void* dst, const cc_string* address, int port) {
int Socket_ValidAddress(const cc_string* address) {
struct sockaddr_storage addr;
return Socket_ParseAddress(&addr, address, 0);
int addrSize;
return ParseAddress(&addr, address, 0, &addrSize);
}
cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port) {
int family, blocking_raw = -1; /* non-blocking mode */
int family, addrSize, blocking_raw = -1; /* non-blocking mode */
struct sockaddr_storage addr;
cc_result res;
*s = -1;
if (!(family = Socket_ParseAddress(&addr, address, port)))
if (!(family = ParseAddress(&addr, address, port, &addrSize)))
return ERR_INVALID_ARGUMENT;
*s = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (*s == -1) return errno;
ioctl(*s, FIONBIO, &blocking_raw);
res = connect(*s, &addr, sizeof(addr));
res = connect(*s, &addr, addrSize);
return res == -1 ? errno : 0;
}
@ -1195,6 +1198,7 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* arg
argc--; argv++; /* skip executable path argument */
#ifdef CC_BUILD_DARWIN
/* Sometimes a "-psn_0_[number]" argument is added before actual args */
if (argc) {
static const cc_string psn = String_FromConst("-psn_0_");
cc_string arg0 = String_FromReadonly(argv[0]);
@ -1204,6 +1208,7 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* arg
count = min(argc, GAME_MAX_CMDARGS);
for (i = 0; i < count; i++) {
/* -d[directory] argument to change directory data is stored in */
if (argv[i][0] == '-' && argv[i][1] == 'd' && argv[i][2]) {
--count;
continue;
@ -1242,6 +1247,7 @@ cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) {
static const cc_string bundle = String_FromConst(".app/Contents/MacOS/");
cc_string raw = String_Init(path, len, 0);
/* If running from within a bundle, set data folder to folder containing bundle */
if (String_CaselessEnds(&raw, &bundle)) {
len -= bundle.length;

View File

@ -404,7 +404,6 @@ static void LoadWinsockFuncs(void) {
static const cc_string winsock32 = String_FromConst("WS2_32.DLL");
LoadDynamicFuncs(&winsock32, funcs, Array_Elems(funcs));
_WSAStringToAddressW = NULL;
}
cc_result Socket_Available(cc_socket s, int* available) {