diff options
author | Patric Stout <truebrain@openttd.org> | 2021-04-27 11:51:00 +0200 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-07-16 19:50:29 +0200 |
commit | 8adade26ed0354e5357803cf19ea9839c2eb785c (patch) | |
tree | 08c73e20a16ea19ee1545de8df6c4b1095c08707 /src/network/core/os_abstraction.cpp | |
parent | 55eed246b842d372cd32784c1afcc904aef67f65 (diff) | |
download | openttd-8adade26ed0354e5357803cf19ea9839c2eb785c.tar.xz |
Feature: allow the use of STUN to connect client and server together
This method doesn't require port-forwarding to be used, and works for
most common NAT routers in home setups. But, for sure it doesn't work
for all setups, and not everyone will be able to use this.
Diffstat (limited to 'src/network/core/os_abstraction.cpp')
-rw-r--r-- | src/network/core/os_abstraction.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/network/core/os_abstraction.cpp b/src/network/core/os_abstraction.cpp index 202806a34..225c95d93 100644 --- a/src/network/core/os_abstraction.cpp +++ b/src/network/core/os_abstraction.cpp @@ -160,6 +160,23 @@ bool SetNoDelay(SOCKET d) } /** + * Try to set the socket to reuse ports. + * @param d The socket to reuse ports on. + * @return True if disabling the delaying succeeded, otherwise false. + */ +bool SetReusePort(SOCKET d) +{ +#ifdef _WIN32 + /* Windows has no SO_REUSEPORT, but for our usecases SO_REUSEADDR does the same job. */ + int reuse_port = 1; + return setsockopt(d, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuse_port, sizeof(reuse_port)) == 0; +#else + int reuse_port = 1; + return setsockopt(d, SOL_SOCKET, SO_REUSEPORT, &reuse_port, sizeof(reuse_port)) == 0; +#endif +} + +/** * Get the error from a socket, if any. * @param d The socket to get the error from. * @return The errno on the socket. |