diff --git a/toxcore/network.c b/toxcore/network.c index 55aa4e2818..fcd3f67b13 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -882,7 +882,14 @@ bool set_socket_nosigpipe(const Network *ns, Socket sock) bool set_socket_reuseaddr(const Network *ns, Socket sock) { int set = 1; - return net_setsockopt(ns, sock, SOL_SOCKET, SO_REUSEADDR, &set, sizeof(set)) == 0; + bool ret = net_setsockopt(ns, sock, SOL_SOCKET, SO_REUSEADDR, &set, sizeof(set)) == 0; + if (!ret) { + return ret; + } +#ifdef OS_WIN32 + ret = net_setsockopt(ns, sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, &set, sizeof(set)) == 0; +#endif + return ret; } bool set_socket_dualstack(const Network *ns, Socket sock)