diff options
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/BOSHConnectionPool.cpp | 13 | ||||
-rw-r--r-- | Swiften/Network/ChainedConnector.cpp | 1 | ||||
-rw-r--r-- | Swiften/Network/DummyTimerFactory.cpp | 3 | ||||
-rw-r--r-- | Swiften/Network/HTTPConnectProxiedConnection.cpp | 7 | ||||
-rw-r--r-- | Swiften/Network/NetworkEnvironment.cpp | 5 | ||||
-rw-r--r-- | Swiften/Network/PlatformDomainNameServiceQuery.cpp | 3 | ||||
-rw-r--r-- | Swiften/Network/UnixProxyProvider.cpp | 1 | ||||
-rw-r--r-- | Swiften/Network/WindowsNetworkEnvironment.cpp | 5 |
8 files changed, 14 insertions, 24 deletions
diff --git a/Swiften/Network/BOSHConnectionPool.cpp b/Swiften/Network/BOSHConnectionPool.cpp index 9ce40d3..e4ca471 100644 --- a/Swiften/Network/BOSHConnectionPool.cpp +++ b/Swiften/Network/BOSHConnectionPool.cpp @@ -1,79 +1,78 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/BOSHConnectionPool.h> #include <climits> #include <boost/bind.hpp> #include <boost/lexical_cast.hpp> #include <Swiften/Base/Log.h> #include <Swiften/Base/SafeString.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/CachingDomainNameResolver.h> #include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h> namespace Swift { BOSHConnectionPool::BOSHConnectionPool(const URL& boshURL, DomainNameResolver* realResolver, ConnectionFactory* connectionFactoryParameter, XMLParserFactory* parserFactory, TLSContextFactory* tlsFactory, TimerFactory* timerFactory, EventLoop* eventLoop, const std::string& to, unsigned long long initialRID, const URL& boshHTTPConnectProxyURL, const SafeString& boshHTTPConnectProxyAuthID, const SafeString& boshHTTPConnectProxyAuthPassword, const TLSOptions& tlsOptions, std::shared_ptr<HTTPTrafficFilter> trafficFilter) : boshURL(boshURL), connectionFactory(connectionFactoryParameter), xmlParserFactory(parserFactory), timerFactory(timerFactory), rid(initialRID), pendingTerminate(false), to(to), requestLimit(2), restartCount(0), pendingRestart(false), tlsContextFactory_(tlsFactory), tlsOptions_(tlsOptions) { if (!boshHTTPConnectProxyURL.isEmpty()) { connectionFactory = new HTTPConnectProxiedConnectionFactory(realResolver, connectionFactory, timerFactory, boshHTTPConnectProxyURL.getHost(), URL::getPortOrDefaultPort(boshHTTPConnectProxyURL), boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword, trafficFilter); } resolver = new CachingDomainNameResolver(realResolver, eventLoop); } BOSHConnectionPool::~BOSHConnectionPool() { /* Don't do a normal close here. Instead kill things forcibly, as close() or writeFooter() will already have been called */ std::vector<BOSHConnection::ref> connectionCopies = connections; - foreach (BOSHConnection::ref connection, connectionCopies) { + for (auto&& connection : connectionCopies) { if (connection) { destroyConnection(connection); connection->disconnect(); } } - foreach (ConnectionFactory* factory, myConnectionFactories) { + for (auto factory : myConnectionFactories) { delete factory; } delete resolver; } void BOSHConnectionPool::write(const SafeByteArray& data) { dataQueue.push_back(data); tryToSendQueuedData(); } void BOSHConnectionPool::handleDataRead(const SafeByteArray& data) { onXMPPDataRead(data); tryToSendQueuedData(); /* Will rebalance the connections */ } void BOSHConnectionPool::restartStream() { BOSHConnection::ref connection = getSuitableConnection(); if (connection) { pendingRestart = false; rid++; connection->setRID(rid); connection->restartStream(); restartCount++; } else { pendingRestart = true; } } void BOSHConnectionPool::setTLSCertificate(CertificateWithKey::ref certWithKey) { @@ -89,149 +88,149 @@ Certificate::ref BOSHConnectionPool::getPeerCertificate() const { if (!pinnedCertificateChain_.empty()) { peerCertificate = pinnedCertificateChain_[0]; } return peerCertificate; } std::vector<Certificate::ref> BOSHConnectionPool::getPeerCertificateChain() const { return pinnedCertificateChain_; } std::shared_ptr<CertificateVerificationError> BOSHConnectionPool::getPeerCertificateVerificationError() const { return lastVerificationError_; } void BOSHConnectionPool::writeFooter() { pendingTerminate = true; tryToSendQueuedData(); } void BOSHConnectionPool::open() { createConnection(); } void BOSHConnectionPool::close() { if (!sid.empty()) { writeFooter(); } else { pendingTerminate = true; std::vector<BOSHConnection::ref> connectionCopies = connections; - foreach (BOSHConnection::ref connection, connectionCopies) { + for (auto&& connection : connectionCopies) { if (connection) { connection->disconnect(); } } } } void BOSHConnectionPool::handleSessionStarted(const std::string& sessionID, size_t requests) { sid = sessionID; requestLimit = requests; onSessionStarted(); } void BOSHConnectionPool::handleConnectFinished(bool error, BOSHConnection::ref connection) { if (error) { onSessionTerminated(std::make_shared<BOSHError>(BOSHError::UndefinedCondition)); /*TODO: We can probably manage to not terminate the stream here and use the rid/ack retry * logic to just swallow the error and try again (some number of tries). */ } else { if (connection->getPeerCertificate() && pinnedCertificateChain_.empty()) { pinnedCertificateChain_ = connection->getPeerCertificateChain(); } if (!pinnedCertificateChain_.empty()) { lastVerificationError_ = connection->getPeerCertificateVerificationError(); } if (sid.empty()) { connection->startStream(to, rid); } if (pendingRestart) { restartStream(); } tryToSendQueuedData(); } } BOSHConnection::ref BOSHConnectionPool::getSuitableConnection() { BOSHConnection::ref suitableConnection; - foreach (BOSHConnection::ref connection, connections) { + for (auto&& connection : connections) { if (connection->isReadyToSend()) { suitableConnection = connection; break; } } if (!suitableConnection && connections.size() < requestLimit) { /* This is not a suitable connection because it won't have yet connected and added TLS if needed. */ BOSHConnection::ref newConnection = createConnection(); newConnection->setSID(sid); } assert(connections.size() <= requestLimit); assert((!suitableConnection) || suitableConnection->isReadyToSend()); return suitableConnection; } void BOSHConnectionPool::tryToSendQueuedData() { if (sid.empty()) { /* If we've not got as far as stream start yet, pend */ return; } BOSHConnection::ref suitableConnection = getSuitableConnection(); bool toSend = !dataQueue.empty(); if (suitableConnection) { if (toSend) { rid++; suitableConnection->setRID(rid); SafeByteArray data; - foreach (const SafeByteArray& datum, dataQueue) { + for (const auto& datum : dataQueue) { data.insert(data.end(), datum.begin(), datum.end()); } suitableConnection->write(data); dataQueue.clear(); } else if (pendingTerminate) { rid++; suitableConnection->setRID(rid); suitableConnection->terminateStream(); sid = ""; close(); } } if (!pendingTerminate) { /* Ensure there's always a session waiting to read data for us */ bool pending = false; - foreach (BOSHConnection::ref connection, connections) { + for (auto&& connection : connections) { if (connection && !connection->isReadyToSend()) { pending = true; } } if (!pending) { if (restartCount >= 1) { /* Don't open a second connection until we've restarted the stream twice - i.e. we've authed and resource bound.*/ if (suitableConnection) { rid++; suitableConnection->setRID(rid); suitableConnection->write(createSafeByteArray("")); } else { /* My thought process I went through when writing this, to aid anyone else confused why this can happen... * * What to do here? I think this isn't possible. If you didn't have two connections, suitable would have made one. If you have two connections and neither is suitable, pending would be true. If you have a non-pending connection, it's suitable. If I decide to do something here, remove assert above. Ah! Yes, because there's a period between creating the connection and it being connected. */ } } } } } void BOSHConnectionPool::handleHTTPError(const std::string& /*errorCode*/) { diff --git a/Swiften/Network/ChainedConnector.cpp b/Swiften/Network/ChainedConnector.cpp index fbea868..ea55db3 100644 --- a/Swiften/Network/ChainedConnector.cpp +++ b/Swiften/Network/ChainedConnector.cpp @@ -1,44 +1,43 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/ChainedConnector.h> #include <typeinfo> #include <boost/bind.hpp> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/ConnectionFactory.h> #include <Swiften/Network/Connector.h> using namespace Swift; ChainedConnector::ChainedConnector( const std::string& hostname, int port, const boost::optional<std::string>& serviceLookupPrefix, DomainNameResolver* resolver, const std::vector<ConnectionFactory*>& connectionFactories, TimerFactory* timerFactory) : hostname(hostname), port(port), serviceLookupPrefix(serviceLookupPrefix), resolver(resolver), connectionFactories(connectionFactories), timerFactory(timerFactory), timeoutMilliseconds(0) { } ChainedConnector::~ChainedConnector() { if (currentConnector) { currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2)); currentConnector->stop(); currentConnector.reset(); } } void ChainedConnector::setTimeoutMilliseconds(int milliseconds) { diff --git a/Swiften/Network/DummyTimerFactory.cpp b/Swiften/Network/DummyTimerFactory.cpp index cdc776c..0bad7be 100644 --- a/Swiften/Network/DummyTimerFactory.cpp +++ b/Swiften/Network/DummyTimerFactory.cpp @@ -1,60 +1,59 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/DummyTimerFactory.h> #include <algorithm> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/Timer.h> namespace Swift { class DummyTimerFactory::DummyTimer : public Timer { public: DummyTimer(int timeout, DummyTimerFactory* factory) : timeout(timeout), factory(factory), isRunning(false), startTime(~0) { } virtual void start() { isRunning = true; startTime = factory->currentTime; } virtual void stop() { isRunning = false; } int getAlarmTime() const { return startTime + timeout; } int timeout; DummyTimerFactory* factory; bool isRunning; int startTime; }; DummyTimerFactory::DummyTimerFactory() : currentTime(0) { } std::shared_ptr<Timer> DummyTimerFactory::createTimer(int milliseconds) { std::shared_ptr<DummyTimer> timer(new DummyTimer(milliseconds, this)); timers.push_back(timer); return timer; } void DummyTimerFactory::setTime(int time) { assert(time > currentTime); - foreach(std::shared_ptr<DummyTimer> timer, timers) { + for (auto&& timer : timers) { if (timer->getAlarmTime() > currentTime && timer->getAlarmTime() <= time && timer->isRunning) { timer->onTick(); } } currentTime = time; } } diff --git a/Swiften/Network/HTTPConnectProxiedConnection.cpp b/Swiften/Network/HTTPConnectProxiedConnection.cpp index b9ab604..b5e521b 100644 --- a/Swiften/Network/HTTPConnectProxiedConnection.cpp +++ b/Swiften/Network/HTTPConnectProxiedConnection.cpp @@ -1,138 +1,135 @@ /* * Copyright (c) 2010-2011 Thilo Cestonaro * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/HTTPConnectProxiedConnection.h> #include <iostream> #include <utility> #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> #include <boost/lexical_cast.hpp> #include <Swiften/Base/Algorithm.h> #include <Swiften/Base/ByteArray.h> #include <Swiften/Base/Log.h> #include <Swiften/Base/String.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/ConnectionFactory.h> #include <Swiften/Network/HTTPTrafficFilter.h> #include <Swiften/Network/HostAddressPort.h> #include <Swiften/StringCodecs/Base64.h> using namespace Swift; HTTPConnectProxiedConnection::HTTPConnectProxiedConnection( DomainNameResolver* resolver, ConnectionFactory* connectionFactory, TimerFactory* timerFactory, const std::string& proxyHost, int proxyPort, const SafeString& authID, const SafeString& authPassword) : ProxiedConnection(resolver, connectionFactory, timerFactory, proxyHost, proxyPort), authID_(authID), authPassword_(authPassword) { } HTTPConnectProxiedConnection::~HTTPConnectProxiedConnection() { } void HTTPConnectProxiedConnection::setHTTPTrafficFilter(std::shared_ptr<HTTPTrafficFilter> trafficFilter) { trafficFilter_ = trafficFilter; } void HTTPConnectProxiedConnection::initializeProxy() { httpResponseBuffer_.clear(); std::stringstream connect; connect << "CONNECT " << getServer().getAddress().toString() << ":" << getServer().getPort() << " HTTP/1.1\r\n"; SafeByteArray data = createSafeByteArray(connect.str()); if (!authID_.empty() && !authPassword_.empty()) { append(data, createSafeByteArray("Proxy-Authorization: Basic ")); SafeByteArray credentials = authID_; append(credentials, createSafeByteArray(":")); append(credentials, authPassword_); append(data, Base64::encode(credentials)); append(data, createSafeByteArray("\r\n")); } else if (!nextHTTPRequestHeaders_.empty()) { - typedef std::pair<std::string, std::string> StringPair; - foreach(const StringPair& headerField, nextHTTPRequestHeaders_) { + for (const auto& headerField : nextHTTPRequestHeaders_) { append(data, createSafeByteArray(headerField.first)); append(data, createSafeByteArray(": ")); append(data, createSafeByteArray(headerField.second)); append(data, createSafeByteArray("\r\n")); } nextHTTPRequestHeaders_.clear(); } append(data, createSafeByteArray("\r\n")); SWIFT_LOG(debug) << "HTTP Proxy send headers: " << byteArrayToString(ByteArray(data.begin(), data.end())) << std::endl; write(data); } void HTTPConnectProxiedConnection::parseHTTPHeader(const std::string& data, std::string& statusLine, std::vector<std::pair<std::string, std::string> >& headerFields) { std::istringstream dataStream(data); // parse status line std::getline(dataStream, statusLine); // parse fields std::string headerLine; std::string::size_type splitIndex; while (std::getline(dataStream, headerLine) && headerLine != "\r") { splitIndex = headerLine.find(':', 0); if (splitIndex != std::string::npos) { headerFields.push_back(std::pair<std::string, std::string>(headerLine.substr(0, splitIndex), headerLine.substr(splitIndex + 1))); } } } void HTTPConnectProxiedConnection::sendHTTPRequest(const std::string& statusLine, const std::vector<std::pair<std::string, std::string> >& headerFields) { - typedef std::pair<std::string, std::string> HTTPHeaderField; std::stringstream request; request << statusLine << "\r\n"; - foreach (const HTTPHeaderField& field, headerFields) { + for (const auto& field : headerFields) { request << field.first << ":" << field.second << "\r\n"; } request << "\r\n"; write(createSafeByteArray(request.str())); } void HTTPConnectProxiedConnection::handleProxyInitializeData(std::shared_ptr<SafeByteArray> data) { std::string dataString = byteArrayToString(ByteArray(data->begin(), data->end())); SWIFT_LOG(debug) << data << std::endl; httpResponseBuffer_.append(dataString); std::string statusLine; std::vector<std::pair<std::string, std::string> > headerFields; std::string::size_type headerEnd = httpResponseBuffer_.find("\r\n\r\n", 0); if (headerEnd == std::string::npos) { if ((httpResponseBuffer_.size() > 4) && (httpResponseBuffer_.substr(0, 4) != "HTTP")) { setProxyInitializeFinished(false); } return; } parseHTTPHeader(httpResponseBuffer_.substr(0, headerEnd), statusLine, headerFields); if (trafficFilter_) { std::vector<std::pair<std::string, std::string> > newHeaderFields = trafficFilter_->filterHTTPResponseHeader(statusLine, headerFields); if (!newHeaderFields.empty()) { std::stringstream statusLine; reconnect(); nextHTTPRequestHeaders_ = newHeaderFields; diff --git a/Swiften/Network/NetworkEnvironment.cpp b/Swiften/Network/NetworkEnvironment.cpp index 19f727c..87883c1 100644 --- a/Swiften/Network/NetworkEnvironment.cpp +++ b/Swiften/Network/NetworkEnvironment.cpp @@ -1,32 +1,31 @@ /* * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/NetworkEnvironment.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/HostAddress.h> #include <Swiften/Network/NetworkInterface.h> namespace Swift { NetworkEnvironment::~NetworkEnvironment() { } HostAddress NetworkEnvironment::getLocalAddress() const { std::vector<NetworkInterface> networkInterfaces = getNetworkInterfaces(); - foreach (const NetworkInterface& iface, networkInterfaces) { + for (const auto& iface : networkInterfaces) { if (!iface.isLoopback()) { - foreach (const HostAddress& address, iface.getAddresses()) { + for (const auto& address : iface.getAddresses()) { if (address.getRawAddress().is_v4()) { return address; } } } } return HostAddress(); } } diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp index 71611f5..5cffcdb 100644 --- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp +++ b/Swiften/Network/PlatformDomainNameServiceQuery.cpp @@ -1,62 +1,61 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <boost/asio.hpp> #include <Swiften/Network/PlatformDomainNameServiceQuery.h> #pragma GCC diagnostic ignored "-Wold-style-cast" #include <Swiften/Base/Platform.h> #include <stdlib.h> #include <boost/numeric/conversion/cast.hpp> #ifdef SWIFTEN_PLATFORM_WINDOWS #undef UNICODE #include <windows.h> #include <windns.h> #ifndef DNS_TYPE_SRV #define DNS_TYPE_SRV 33 #endif #else #include <arpa/nameser.h> #include <arpa/nameser_compat.h> #include <resolv.h> #endif #include <boost/bind.hpp> #include <Swiften/Base/ByteArray.h> #include <Swiften/EventLoop/EventLoop.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Base/BoostRandomGenerator.h> #include <Swiften/Base/Log.h> #include <Swiften/Network/PlatformDomainNameResolver.h> using namespace Swift; namespace Swift { PlatformDomainNameServiceQuery::PlatformDomainNameServiceQuery(const boost::optional<std::string>& serviceName, EventLoop* eventLoop, PlatformDomainNameResolver* resolver) : PlatformDomainNameQuery(resolver), eventLoop(eventLoop), serviceValid(false) { if (!!serviceName) { service = *serviceName; serviceValid = true; } } PlatformDomainNameServiceQuery::~PlatformDomainNameServiceQuery() { } void PlatformDomainNameServiceQuery::run() { getResolver()->addQueryToQueue(shared_from_this()); } void PlatformDomainNameServiceQuery::runBlocking() { if (!serviceValid) { emitError(); return; } SWIFT_LOG(debug) << "Querying " << service << std::endl; diff --git a/Swiften/Network/UnixProxyProvider.cpp b/Swiften/Network/UnixProxyProvider.cpp index 6c23add..e6afa3d 100644 --- a/Swiften/Network/UnixProxyProvider.cpp +++ b/Swiften/Network/UnixProxyProvider.cpp @@ -1,45 +1,44 @@ /* * Copyright (c) 2010-2011 Thilo Cestonaro * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/UnixProxyProvider.h> -#include <Swiften/Base/foreach.h> #if defined(HAVE_GCONF) # include "Swiften/Network/GConfProxyProvider.h" #endif namespace Swift { UnixProxyProvider::UnixProxyProvider() : gconfProxyProvider(nullptr), environmentProxyProvider() { #if defined(HAVE_GCONF) gconfProxyProvider = new GConfProxyProvider(); #endif } UnixProxyProvider::~UnixProxyProvider() { #if defined(HAVE_GCONF) delete gconfProxyProvider; #endif } HostAddressPort UnixProxyProvider::getSOCKS5Proxy() const { HostAddressPort proxy; #if defined(HAVE_GCONF) proxy = gconfProxyProvider->getSOCKS5Proxy(); if(proxy.isValid()) { return proxy; } #endif proxy = environmentProxyProvider.getSOCKS5Proxy(); diff --git a/Swiften/Network/WindowsNetworkEnvironment.cpp b/Swiften/Network/WindowsNetworkEnvironment.cpp index 6ce41de..e90a5c6 100644 --- a/Swiften/Network/WindowsNetworkEnvironment.cpp +++ b/Swiften/Network/WindowsNetworkEnvironment.cpp @@ -1,74 +1,73 @@ /* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Network/WindowsNetworkEnvironment.h> #include <map> #include <string> #include <vector> #include <boost/optional.hpp> #include <iphlpapi.h> #include <winsock2.h> #include <Swiften/Base/ByteArray.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/HostAddress.h> #include <Swiften/Network/NetworkInterface.h> namespace Swift { std::vector<NetworkInterface> WindowsNetworkEnvironment::getNetworkInterfaces() const { std::vector<NetworkInterface> result; ByteArray adapters; ULONG bufferSize = 0; ULONG ret; ULONG flags = GAA_FLAG_INCLUDE_ALL_INTERFACES | GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER; while ((ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, reinterpret_cast<IP_ADAPTER_ADDRESSES*>(vecptr(adapters)), &bufferSize)) == ERROR_BUFFER_OVERFLOW) { adapters.resize(bufferSize); }; if (ret != ERROR_SUCCESS) { return result; } std::map<std::string,NetworkInterface> interfaces; for (IP_ADAPTER_ADDRESSES* adapter = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(vecptr(adapters)); adapter; adapter = adapter->Next) { std::string name(adapter->AdapterName); if (adapter->OperStatus != IfOperStatusUp) { continue; } for (IP_ADAPTER_UNICAST_ADDRESS* address = adapter->FirstUnicastAddress; address; address = address->Next) { boost::optional<HostAddress> hostAddress; if (address->Address.lpSockaddr->sa_family == PF_INET) { sockaddr_in* sa = reinterpret_cast<sockaddr_in*>(address->Address.lpSockaddr); hostAddress = HostAddress(reinterpret_cast<const unsigned char*>(&(sa->sin_addr)), 4); } else if (address->Address.lpSockaddr->sa_family == PF_INET6) { sockaddr_in6* sa = reinterpret_cast<sockaddr_in6*>(address->Address.lpSockaddr); hostAddress = HostAddress(reinterpret_cast<const unsigned char*>(&(sa->sin6_addr)), 16); } if (hostAddress && !hostAddress->isLocalhost()) { std::map<std::string, NetworkInterface>::iterator i = interfaces.insert(std::make_pair(name, NetworkInterface(name, false))).first; i->second.addAddress(*hostAddress); } } } - for (std::map<std::string,NetworkInterface>::const_iterator i = interfaces.begin(); i != interfaces.end(); ++i) { - result.push_back(i->second); + for (const auto& interface : interfaces) { + result.push_back(interface.second); } return result; } } |