4#include "private/qnativesocketengine_p_p.h"
5#include "private/qnetconmonitor_p.h"
7#include "private/qobject_p.h"
9#include <SystemConfiguration/SystemConfiguration.h>
10#include <CoreFoundation/CoreFoundation.h>
12#include <netinet/in.h>
22class ReachabilityDispatchQueue
25 ReachabilityDispatchQueue()
27 queue = dispatch_queue_create(
"qt-network-reachability-queue",
nullptr);
29 qCWarning(lcNetMon,
"Failed to create a dispatch queue for reachability probes");
32 ~ReachabilityDispatchQueue()
35 dispatch_release(queue);
38 dispatch_queue_t
data()
const
44 dispatch_queue_t
queue =
nullptr;
46 Q_DISABLE_COPY_MOVE(ReachabilityDispatchQueue)
49dispatch_queue_t qt_reachability_queue()
51 static const ReachabilityDispatchQueue reachabilityQueue;
52 return reachabilityQueue.data();
62 dst.a4 = sockaddr_in{};
63 dst.a4.sin_family = AF_INET;
64 dst.a4.sin_addr.s_addr = htonl(
src.toIPv4Address());
65 dst.a4.sin_len =
sizeof(sockaddr_in);
67 dst.a6 = sockaddr_in6{};
69 dst.a6.sin6_len =
sizeof(sockaddr_in6);
71 std::memcpy(&
dst.a6.sin6_addr, &ipv6,
sizeof ipv6);
84 SCNetworkReachabilityRef
probe =
nullptr;
85 SCNetworkReachabilityFlags
state = kSCNetworkReachabilityFlagsIsLocalAddress;
91#ifdef QT_PLATFORM_UIKIT
110#ifdef QT_PLATFORM_UIKIT
111 const bool hadWwan = isWwan();
118#ifdef QT_PLATFORM_UIKIT
119 if (hadWwan != isWwan())
120 emit q->isWwanChanged(isWwan());
131 state = kSCNetworkReachabilityFlagsIsLocalAddress;
137 return !!(
state & kSCNetworkReachabilityFlagsReachable);
140#ifdef QT_PLATFORM_UIKIT
141bool QNetworkConnectionMonitorPrivate::isWwan()
const
143 return !!(
state & kSCNetworkReachabilityFlagsIsWWAN);
154 monitorPrivate->updateState(
flags);
181 qCWarning(lcNetMon,
"Monitor is already active, call stopMonitoring() first");
186 qCWarning(lcNetMon,
"Invalid (null) local address, cannot create a reachability target");
193 qt_sockaddr client = qt_hostaddress_to_sockaddr(local);
196 d->probe = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault,
reinterpret_cast<sockaddr *
>(&client));
199 d->probe = SCNetworkReachabilityCreateWithAddressPair(kCFAllocatorDefault,
200 reinterpret_cast<sockaddr *
>(&client),
201 reinterpret_cast<sockaddr *
>(&
target));
207 SCNetworkReachabilityGetFlags(
d->probe, &
d->state);
209 qCWarning(lcNetMon,
"Failed to create network reachability probe");
221 qCWarning(lcNetMon,
"Monitor is already active, call stopMonitoring() first");
226 qCWarning(lcNetMon,
"Can not start monitoring, set targets first");
230 auto queue = qt_reachability_queue();
232 qWarning(lcNetMon,
"Failed to create a dispatch queue to schedule a probe on");
236 SCNetworkReachabilityContext
context = {};
239 qWarning(lcNetMon,
"Failed to set a reachability callback");
244 if (!SCNetworkReachabilitySetDispatchQueue(
d->probe,
queue)) {
245 qWarning(lcNetMon,
"Failed to schedule a reachability callback on a queue");
249 return d->scheduled =
true;
265 SCNetworkReachabilitySetDispatchQueue(
d->probe,
nullptr);
266 SCNetworkReachabilitySetCallback(
d->probe,
nullptr,
nullptr);
267 d->scheduled =
false;
276 qCWarning(lcNetMon,
"Calling isReachable() is unsafe after the monitoring started");
281 qCWarning(lcNetMon,
"Reachability is unknown, set the target first");
285 return d->isReachable();
288#ifdef QT_PLATFORM_UIKIT
289bool QNetworkConnectionMonitor::isWwan()
const
294 qCWarning(lcNetMon,
"Calling isWwan() is unsafe after the monitoring started");
299 qCWarning(lcNetMon,
"Medium is unknown, set the target first");
static constexpr auto IPv4Protocol
static constexpr auto IPv6Protocol
The QHostAddress class provides an IP address.
bool isNull() const
Returns true if this host address is not valid for any host or interface.
SCNetworkReachabilityFlags state
void updateState(SCNetworkReachabilityFlags newState)
SCNetworkReachabilityRef probe
static void probeCallback(SCNetworkReachabilityRef probe, SCNetworkReachabilityFlags flags, void *info)
bool isMonitoring() const
bool setTargets(const QHostAddress &local, const QHostAddress &remote)
~QNetworkConnectionMonitor()
QNetworkConnectionMonitor()
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
QFileInfo info(fileName)
[8]