summaryrefslogtreecommitdiffstats
blob: 104cd2f834691896674da4764b3d42343b0ec72d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <Swiften/Network/HostAddressPort.h>

#include <boost/lexical_cast.hpp>

using namespace Swift;

HostAddressPort::HostAddressPort(const HostAddress& address, int port) : address_(address), port_(port) {
}

HostAddressPort::HostAddressPort(const boost::asio::ip::tcp::endpoint& endpoint) {
	address_ = HostAddress(endpoint.address());
	port_ = endpoint.port();
}

HostAddressPort::HostAddressPort(const boost::asio::ip::udp::endpoint& endpoint) {
	address_ = HostAddress(endpoint.address());
	port_ = endpoint.port();
}

std::string HostAddressPort::toString() const {
	return getAddress().toString() + ":" + boost::lexical_cast<std::string>(getPort());
}

boost::asio::ip::udp::endpoint HostAddressPort::toEndpoint() const
{
	return boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string(address_.toString()), port_);
}