Make new IPv6 support only work on Windows to prevent direct connection breaking
This commit is contained in:
parent
1380e9b594
commit
d9f3a7946c
|
@ -22,7 +22,11 @@ void resolve_domain(void) {
|
||||||
|
|
||||||
static int socket_bind(SOCKET socket, unsigned int port) {
|
static int socket_bind(SOCKET socket, unsigned int port) {
|
||||||
struct sockaddr_in rxAddr;
|
struct sockaddr_in rxAddr;
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
rxAddr.sin_family = AF_INET6;
|
rxAddr.sin_family = AF_INET6;
|
||||||
|
#else
|
||||||
|
rxAddr.sin_family = AF_INET;
|
||||||
|
#endif
|
||||||
rxAddr.sin_port = htons(port);
|
rxAddr.sin_port = htons(port);
|
||||||
rxAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
rxAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
|
@ -72,7 +76,6 @@ static int socket_receive(SOCKET socket, struct sockaddr_in* rxAddr, u8* buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ns_socket_initialize(enum NetworkType networkType, UNUSED bool reconnecting) {
|
static bool ns_socket_initialize(enum NetworkType networkType, UNUSED bool reconnecting) {
|
||||||
|
|
||||||
// sanity check port
|
// sanity check port
|
||||||
unsigned int port = (networkType == NT_CLIENT) ? configJoinPort : configHostPort;
|
unsigned int port = (networkType == NT_CLIENT) ? configJoinPort : configHostPort;
|
||||||
if (port == 0) { port = DEFAULT_PORT; }
|
if (port == 0) { port = DEFAULT_PORT; }
|
||||||
|
@ -100,7 +103,12 @@ static bool ns_socket_initialize(enum NetworkType networkType, UNUSED bool recon
|
||||||
LOG_INFO("bound to port %u", port);
|
LOG_INFO("bound to port %u", port);
|
||||||
} else {
|
} else {
|
||||||
// save the port to send to
|
// save the port to send to
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
sAddr[0].sin_family = AF_INET6;
|
sAddr[0].sin_family = AF_INET6;
|
||||||
|
#else
|
||||||
|
sAddr[0].sin_family = AF_INET;
|
||||||
|
#endif
|
||||||
|
|
||||||
sAddr[0].sin_port = htons(port);
|
sAddr[0].sin_port = htons(port);
|
||||||
resolve_domain();
|
resolve_domain();
|
||||||
sAddr[0].sin_addr.s_addr = inet_addr(configJoinIp);
|
sAddr[0].sin_addr.s_addr = inet_addr(configJoinIp);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
SOCKET socket_initialize(void) {
|
SOCKET socket_initialize(void) {
|
||||||
// initialize socket
|
// initialize socket
|
||||||
SOCKET sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (sock == INVALID_SOCKET) {
|
if (sock == INVALID_SOCKET) {
|
||||||
LOG_ERROR("socket failed with error %d", SOCKET_LAST_ERROR);
|
LOG_ERROR("socket failed with error %d", SOCKET_LAST_ERROR);
|
||||||
return INVALID_SOCKET;
|
return INVALID_SOCKET;
|
||||||
|
@ -18,14 +18,6 @@ SOCKET socket_initialize(void) {
|
||||||
return INVALID_SOCKET;
|
return INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure our socket is dual-stack. So we can use both IPv4 and IPv6.
|
|
||||||
int opt = 0;
|
|
||||||
rc = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&opt, sizeof(opt));
|
|
||||||
if (rc != NO_ERROR) {
|
|
||||||
LOG_ERROR("setsockopt(IPV6_V6ONLY) failed with error: %d", rc);
|
|
||||||
return INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue