LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
addresses.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "addresses.h"
10#include <QHostAddress>
11#include <QNetworkInterface>
12
13namespace LC::Util
14{
15 AddrList_t GetLocalAddresses (int defaultPort)
16 {
17 AddrList_t defaultAddrs;
18 const auto locals =
19 {
20 QHostAddress::parseSubnet ("10.0.0.0/8"),
21 QHostAddress::parseSubnet ("172.16.0.0/12"),
22 QHostAddress::parseSubnet ("192.168.0.0/16")
23 };
24 for (const auto& addr : GetAllAddresses ())
25 if (std::any_of (std::begin (locals), std::end (locals),
26 [&addr] (const auto& subnet) { return addr.isInSubnet (subnet); }))
27 defaultAddrs.push_back ({ addr.toString (), QString::number (defaultPort) });
28 return defaultAddrs;
29 }
30
32 {
34 for (const auto& addr : QNetworkInterface::allAddresses ())
35 if (addr.scopeId ().isEmpty ())
36 result << addr;
37
38 if (!result.contains (QHostAddress::Any))
39 result << QHostAddress::Any;
40
41 return result;
42 }
43
44}
QList< QHostAddress > GetAllAddresses()
Returns all addresses likely accessible "from the outside".
Definition addresses.cpp:31
AddrList_t GetLocalAddresses(int defaultPort)
Returns all local addresses.
Definition addresses.cpp:15
QList< QPair< QString, QString > > AddrList_t
Definition addresses.h:21