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) {
|
||||
struct sockaddr_in rxAddr;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
rxAddr.sin_family = AF_INET6;
|
||||
#else
|
||||
rxAddr.sin_family = AF_INET;
|
||||
#endif
|
||||
rxAddr.sin_port = htons(port);
|
||||
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) {
|
||||
|
||||
// sanity check port
|
||||
unsigned int port = (networkType == NT_CLIENT) ? configJoinPort : configHostPort;
|
||||
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);
|
||||
} else {
|
||||
// save the port to send to
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
sAddr[0].sin_family = AF_INET6;
|
||||
#else
|
||||
sAddr[0].sin_family = AF_INET;
|
||||
#endif
|
||||
|
||||
sAddr[0].sin_port = htons(port);
|
||||
resolve_domain();
|
||||
sAddr[0].sin_addr.s_addr = inet_addr(configJoinIp);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
SOCKET socket_initialize(void) {
|
||||
// initialize socket
|
||||
SOCKET sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sock == INVALID_SOCKET) {
|
||||
LOG_ERROR("socket failed with error %d", SOCKET_LAST_ERROR);
|
||||
return INVALID_SOCKET;
|
||||
|
@ -17,14 +17,6 @@ SOCKET socket_initialize(void) {
|
|||
LOG_ERROR("fcntl failed with error: %d", rc);
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue