aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test_socket.cpp
diff options
context:
space:
mode:
authorWuzzy <wuzzy2@mail.ru>2021-08-16 15:57:07 +0000
committerGitHub <noreply@github.com>2021-08-16 17:57:07 +0200
commit2eec997e979b8f2781970e5e2fdd8d4330aa4ec5 (patch)
treeba60451bfcd5002385ef41a16e258ed16dd4a302 /src/unittest/test_socket.cpp
parent328d9492256e600159d2e04987e493b3a269a067 (diff)
downloadminetest-2eec997e979b8f2781970e5e2fdd8d4330aa4ec5.tar.gz
minetest-2eec997e979b8f2781970e5e2fdd8d4330aa4ec5.tar.bz2
minetest-2eec997e979b8f2781970e5e2fdd8d4330aa4ec5.zip
Clarify the meaning of "rightclick"/"use" in documentation (#11471)
Diffstat (limited to 'src/unittest/test_socket.cpp')
0 files changed, 0 insertions, 0 deletions
='#n122'>122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "test.h"

#include "log.h"
#include "settings.h"
#include "network/socket.h"

class TestSocket : public TestBase {
public:
	TestSocket()
	{
		if (INTERNET_SIMULATOR == false)
			TestManager::registerTestModule(this);
	}

	const char *getName() { return "TestSocket"; }

	void runTests(IGameDef *gamedef);

	void testIPv4Socket();
	void testIPv6Socket();

	static const int port = 30003;
};

static TestSocket g_test_instance;

void TestSocket::runTests(IGameDef *gamedef)
{
	TEST(testIPv4Socket);

	if (g_settings->getBool("enable_ipv6"))
		TEST(testIPv6Socket);
}

////////////////////////////////////////////////////////////////////////////////

void TestSocket::testIPv4Socket()
{
	Address address(0, 0, 0, 0, port);
	Address bind_addr(0, 0, 0, 0, port);

	/*
	 * Try to use the bind_address for servers with no localhost address
	 * For example: FreeBSD jails
	 */
	std::string bind_str = g_settings->get("bind_address");
	try {
		bind_addr.Resolve(bind_str.c_str());

		if (!bind_addr.isIPv6()) {
			address = bind_addr;
		}
	} catch (ResolveError &e) {
	}

	UDPSocket socket(false);
	socket.Bind(address);