summaryrefslogtreecommitdiffstats
blob: 248be2d137eaaac6b19620518f60145fe4446372 (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
/*
 * Copyright (c) 2010-2018 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/Network/HostAddressPort.h>

#include <boost/lexical_cast.hpp>

using namespace Swift;

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

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

std::string HostAddressPort::toString() const {
    std::string portAsString;
    try {
        portAsString = std::to_string(getPort());
    } catch (boost::bad_lexical_cast&) {
    }
    return getAddress().toString() + ":" + portAsString;
}