| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | /* GIO - GLib Input, Output and Streaming Library
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 2011 Red Hat, Inc | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-05-18 09:12:45 +01:00
										 |  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2017-05-27 18:21:30 +02:00
										 |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General | 
					
						
							| 
									
										
										
										
											2014-01-23 12:58:29 +01:00
										 |  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "config.h"
 | 
					
						
							|  |  |  | #include "glib.h"
 | 
					
						
							|  |  |  | #include "glibintl.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "gnetworkmonitor.h"
 | 
					
						
							|  |  |  | #include "ginetaddress.h"
 | 
					
						
							|  |  |  | #include "ginetsocketaddress.h"
 | 
					
						
							|  |  |  | #include "ginitable.h"
 | 
					
						
							|  |  |  | #include "gioenumtypes.h"
 | 
					
						
							|  |  |  | #include "giomodule-priv.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  | #include "gtask.h"
 | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2023-10-24 10:53:48 +01:00
										 |  |  |  * GNetworkMonitor: | 
					
						
							| 
									
										
										
										
											2012-01-30 15:59:38 -05:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-10-24 10:53:48 +01:00
										 |  |  |  * `GNetworkMonitor` provides an easy-to-use cross-platform API | 
					
						
							| 
									
										
										
										
											2017-05-02 07:23:32 -04:00
										 |  |  |  * for monitoring network connectivity. On Linux, the available | 
					
						
							|  |  |  |  * implementations are based on the kernel's netlink interface and | 
					
						
							|  |  |  |  * on NetworkManager. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-05-10 12:44:57 +02:00
										 |  |  |  * There is also an implementation for use inside Flatpak sandboxes. | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Since: 2.32 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 16:20:43 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * GNetworkMonitorInterface: | 
					
						
							|  |  |  |  * @g_iface: The parent interface. | 
					
						
							|  |  |  |  * @network_changed: the virtual function pointer for the | 
					
						
							|  |  |  |  *  GNetworkMonitor::network-changed signal. | 
					
						
							|  |  |  |  * @can_reach: the virtual function pointer for g_network_monitor_can_reach() | 
					
						
							|  |  |  |  * @can_reach_async: the virtual function pointer for | 
					
						
							|  |  |  |  *  g_network_monitor_can_reach_async() | 
					
						
							|  |  |  |  * @can_reach_finish: the virtual function pointer for | 
					
						
							|  |  |  |  *  g_network_monitor_can_reach_finish() | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The virtual function table for #GNetworkMonitor. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Since: 2.32 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | G_DEFINE_INTERFACE_WITH_CODE (GNetworkMonitor, g_network_monitor, G_TYPE_OBJECT, | 
					
						
							| 
									
										
										
										
											2019-07-29 17:24:49 +02:00
										 |  |  |                               g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE)) | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum { | 
					
						
							|  |  |  |   NETWORK_CHANGED, | 
					
						
							|  |  |  |   LAST_SIGNAL | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static guint signals[LAST_SIGNAL] = { 0 }; | 
					
						
							| 
									
										
										
										
											2019-01-23 16:07:51 +00:00
										 |  |  | static GNetworkMonitor *network_monitor_default_singleton = NULL;  /* (owned) (atomic) */ | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * g_network_monitor_get_default: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Gets the default #GNetworkMonitor for the system. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-11-13 17:19:42 +02:00
										 |  |  |  * Returns: (not nullable) (transfer none): a #GNetworkMonitor, which will be | 
					
						
							|  |  |  |  *     a dummy object if no network monitor is available | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Since: 2.32 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | GNetworkMonitor * | 
					
						
							|  |  |  | g_network_monitor_get_default (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-11 23:59:52 -07:00
										 |  |  |   if (g_once_init_enter_pointer (&network_monitor_default_singleton)) | 
					
						
							| 
									
										
										
										
											2019-01-23 16:07:51 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       GNetworkMonitor *singleton; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       singleton = _g_io_module_get_default (G_NETWORK_MONITOR_EXTENSION_POINT_NAME, | 
					
						
							|  |  |  |                                             "GIO_USE_NETWORK_MONITOR", | 
					
						
							|  |  |  |                                             NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-11 23:59:52 -07:00
										 |  |  |       g_once_init_leave_pointer (&network_monitor_default_singleton, singleton); | 
					
						
							| 
									
										
										
										
											2019-01-23 16:07:51 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return network_monitor_default_singleton; | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * g_network_monitor_get_network_available: | 
					
						
							|  |  |  |  * @monitor: the #GNetworkMonitor | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Checks if the network is available. "Available" here means that the | 
					
						
							|  |  |  |  * system has a default route available for at least one of IPv4 or | 
					
						
							|  |  |  |  * IPv6. It does not necessarily imply that the public Internet is | 
					
						
							|  |  |  |  * reachable. See #GNetworkMonitor:network-available for more details. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-02-19 19:35:23 -05:00
										 |  |  |  * Returns: whether the network is available | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Since: 2.32 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | gboolean | 
					
						
							|  |  |  | g_network_monitor_get_network_available (GNetworkMonitor *monitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gboolean available = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_get (G_OBJECT (monitor), "network-available", &available, NULL); | 
					
						
							|  |  |  |   return available; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * g_network_monitor_get_network_metered: | 
					
						
							|  |  |  |  * @monitor: the #GNetworkMonitor | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |  * Checks if the network is metered. | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |  * See #GNetworkMonitor:network-metered for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Returns: whether the connection is metered | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Since: 2.46 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | gboolean | 
					
						
							|  |  |  | g_network_monitor_get_network_metered (GNetworkMonitor *monitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gboolean metered = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_get (G_OBJECT (monitor), "network-metered", &metered, NULL); | 
					
						
							|  |  |  |   return metered; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 10:39:12 -04:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * g_network_monitor_get_connectivity: | 
					
						
							|  |  |  |  * @monitor: the #GNetworkMonitor | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Gets a more detailed networking state than | 
					
						
							|  |  |  |  * g_network_monitor_get_network_available(). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * If #GNetworkMonitor:network-available is %FALSE, then the | 
					
						
							|  |  |  |  * connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * If #GNetworkMonitor:network-available is %TRUE, then the | 
					
						
							|  |  |  |  * connectivity state will be %G_NETWORK_CONNECTIVITY_FULL (if there | 
					
						
							|  |  |  |  * is full Internet connectivity), %G_NETWORK_CONNECTIVITY_LIMITED (if | 
					
						
							|  |  |  |  * the host has a default route, but appears to be unable to actually | 
					
						
							|  |  |  |  * reach the full Internet), or %G_NETWORK_CONNECTIVITY_PORTAL (if the | 
					
						
							|  |  |  |  * host is trapped behind a "captive portal" that requires some sort | 
					
						
							|  |  |  |  * of login or acknowledgement before allowing full Internet access). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note that in the case of %G_NETWORK_CONNECTIVITY_LIMITED and | 
					
						
							|  |  |  |  * %G_NETWORK_CONNECTIVITY_PORTAL, it is possible that some sites are | 
					
						
							|  |  |  |  * reachable but others are not. In this case, applications can | 
					
						
							|  |  |  |  * attempt to connect to remote servers, but should gracefully fall | 
					
						
							|  |  |  |  * back to their "offline" behavior if the connection attempt fails. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Return value: the network connectivity state | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-12-10 18:39:21 +01:00
										 |  |  |  * Since: 2.44 | 
					
						
							| 
									
										
										
										
											2014-04-16 10:39:12 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | GNetworkConnectivity | 
					
						
							|  |  |  | g_network_monitor_get_connectivity (GNetworkMonitor *monitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GNetworkConnectivity connectivity; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_get (G_OBJECT (monitor), "connectivity", &connectivity, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return connectivity; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * g_network_monitor_can_reach: | 
					
						
							|  |  |  |  * @monitor: a #GNetworkMonitor | 
					
						
							|  |  |  |  * @connectable: a #GSocketConnectable | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  * @cancellable: (nullable): a #GCancellable, or %NULL | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  * @error: return location for a #GError, or %NULL | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Attempts to determine whether or not the host pointed to by | 
					
						
							|  |  |  |  * @connectable can be reached, without actually trying to connect to | 
					
						
							|  |  |  |  * it. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This may return %TRUE even when #GNetworkMonitor:network-available | 
					
						
							|  |  |  |  * is %FALSE, if, for example, @monitor can determine that | 
					
						
							|  |  |  |  * @connectable refers to a host on a local network. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * If @monitor believes that an attempt to connect to @connectable | 
					
						
							|  |  |  |  * will succeed, it will return %TRUE. Otherwise, it will return | 
					
						
							|  |  |  |  * %FALSE and set @error to an appropriate error (such as | 
					
						
							|  |  |  |  * %G_IO_ERROR_HOST_UNREACHABLE). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note that although this does not attempt to connect to | 
					
						
							|  |  |  |  * @connectable, it may still block for a brief period of time (eg, | 
					
						
							|  |  |  |  * trying to do multicast DNS on the local network), so if you do not | 
					
						
							|  |  |  |  * want to block, you should use g_network_monitor_can_reach_async(). | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-02-19 19:35:23 -05:00
										 |  |  |  * Returns: %TRUE if @connectable is reachable, %FALSE if not. | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Since: 2.32 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | gboolean | 
					
						
							|  |  |  | g_network_monitor_can_reach (GNetworkMonitor     *monitor, | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                              GSocketConnectable  *connectable, | 
					
						
							|  |  |  |                              GCancellable        *cancellable, | 
					
						
							|  |  |  |                              GError             **error) | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   GNetworkMonitorInterface *iface; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   iface = G_NETWORK_MONITOR_GET_INTERFACE (monitor); | 
					
						
							|  |  |  |   return iface->can_reach (monitor, connectable, cancellable, error); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_real_can_reach_async (GNetworkMonitor     *monitor, | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                                         GSocketConnectable  *connectable, | 
					
						
							|  |  |  |                                         GCancellable        *cancellable, | 
					
						
							|  |  |  |                                         GAsyncReadyCallback  callback, | 
					
						
							|  |  |  |                                         gpointer             user_data) | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   GTask *task; | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |   GError *error = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   task = g_task_new (monitor, cancellable, callback, user_data); | 
					
						
							| 
									
										
										
										
											2016-06-16 19:39:38 -04:00
										 |  |  |   g_task_set_source_tag (task, g_network_monitor_real_can_reach_async); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |   if (g_network_monitor_can_reach (monitor, connectable, cancellable, &error)) | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |     g_task_return_boolean (task, TRUE); | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |     g_task_return_error (task, error); | 
					
						
							|  |  |  |   g_object_unref (task); | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-30 15:59:38 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * g_network_monitor_can_reach_async: | 
					
						
							|  |  |  |  * @monitor: a #GNetworkMonitor | 
					
						
							|  |  |  |  * @connectable: a #GSocketConnectable | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  * @cancellable: (nullable): a #GCancellable, or %NULL | 
					
						
							| 
									
										
										
										
											2023-02-20 14:43:02 -06:00
										 |  |  |  * @callback: (scope async): a #GAsyncReadyCallback | 
					
						
							|  |  |  |  *     to call when the request is satisfied | 
					
						
							|  |  |  |  * @user_data: the data to pass to callback function | 
					
						
							| 
									
										
										
										
											2012-01-30 15:59:38 -05:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Asynchronously attempts to determine whether or not the host | 
					
						
							|  |  |  |  * pointed to by @connectable can be reached, without actually | 
					
						
							|  |  |  |  * trying to connect to it. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * For more details, see g_network_monitor_can_reach(). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * When the operation is finished, @callback will be called. | 
					
						
							|  |  |  |  * You can then call g_network_monitor_can_reach_finish() | 
					
						
							|  |  |  |  * to get the result of the operation. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | void | 
					
						
							|  |  |  | g_network_monitor_can_reach_async (GNetworkMonitor     *monitor, | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                                    GSocketConnectable  *connectable, | 
					
						
							|  |  |  |                                    GCancellable        *cancellable, | 
					
						
							|  |  |  |                                    GAsyncReadyCallback  callback, | 
					
						
							|  |  |  |                                    gpointer             user_data) | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   GNetworkMonitorInterface *iface; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   iface = G_NETWORK_MONITOR_GET_INTERFACE (monitor); | 
					
						
							|  |  |  |   iface->can_reach_async (monitor, connectable, cancellable, callback, user_data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static gboolean | 
					
						
							|  |  |  | g_network_monitor_real_can_reach_finish (GNetworkMonitor  *monitor, | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                                          GAsyncResult     *result, | 
					
						
							|  |  |  |                                          GError          **error) | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   g_return_val_if_fail (g_task_is_valid (result, monitor), FALSE); | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   return g_task_propagate_boolean (G_TASK (result), error); | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-30 15:59:38 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * g_network_monitor_can_reach_finish: | 
					
						
							|  |  |  |  * @monitor: a #GNetworkMonitor | 
					
						
							|  |  |  |  * @result: a #GAsyncResult | 
					
						
							|  |  |  |  * @error: return location for errors, or %NULL | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Finishes an async network connectivity test. | 
					
						
							|  |  |  |  * See g_network_monitor_can_reach_async(). | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-02-19 19:35:23 -05:00
										 |  |  |  * Returns: %TRUE if network is reachable, %FALSE if not. | 
					
						
							| 
									
										
										
										
											2012-01-30 15:59:38 -05:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | gboolean | 
					
						
							|  |  |  | g_network_monitor_can_reach_finish (GNetworkMonitor     *monitor, | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                                     GAsyncResult        *result, | 
					
						
							|  |  |  |                                     GError             **error) | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   GNetworkMonitorInterface *iface; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   iface = G_NETWORK_MONITOR_GET_INTERFACE (monitor); | 
					
						
							|  |  |  |   return iface->can_reach_finish (monitor, result, error); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_default_init (GNetworkMonitorInterface *iface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   iface->can_reach_async  = g_network_monitor_real_can_reach_async; | 
					
						
							|  |  |  |   iface->can_reach_finish = g_network_monitor_real_can_reach_finish; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * GNetworkMonitor::network-changed: | 
					
						
							|  |  |  |    * @monitor: a #GNetworkMonitor | 
					
						
							| 
									
										
										
										
											2017-12-14 23:17:37 +01:00
										 |  |  |    * @network_available: the current value of #GNetworkMonitor:network-available | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |    * | 
					
						
							| 
									
										
										
										
											2017-12-14 23:17:37 +01:00
										 |  |  |    * Emitted when the network configuration changes. | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |    * | 
					
						
							|  |  |  |    * Since: 2.32 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   signals[NETWORK_CHANGED] = | 
					
						
							|  |  |  |     g_signal_new (I_("network-changed"), | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                   G_TYPE_NETWORK_MONITOR, | 
					
						
							|  |  |  |                   G_SIGNAL_RUN_LAST, | 
					
						
							|  |  |  |                   G_STRUCT_OFFSET (GNetworkMonitorInterface, network_changed), | 
					
						
							|  |  |  |                   NULL, NULL, | 
					
						
							| 
									
										
										
										
											2019-05-30 19:13:37 -07:00
										 |  |  |                   NULL, | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                   G_TYPE_NONE, 1, | 
					
						
							|  |  |  |                   G_TYPE_BOOLEAN); | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * GNetworkMonitor:network-available: | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Whether the network is considered available. That is, whether the | 
					
						
							|  |  |  |    * system has a default route for at least one of IPv4 or IPv6. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Real-world networks are of course much more complicated than | 
					
						
							|  |  |  |    * this; the machine may be connected to a wifi hotspot that | 
					
						
							|  |  |  |    * requires payment before allowing traffic through, or may be | 
					
						
							|  |  |  |    * connected to a functioning router that has lost its own upstream | 
					
						
							|  |  |  |    * connectivity. Some hosts might only be accessible when a VPN is | 
					
						
							|  |  |  |    * active. Other hosts might only be accessible when the VPN is | 
					
						
							| 
									
										
										
										
											2014-01-31 20:34:33 -05:00
										 |  |  |    * not active. Thus, it is best to use g_network_monitor_can_reach() | 
					
						
							|  |  |  |    * or g_network_monitor_can_reach_async() to test for reachability | 
					
						
							|  |  |  |    * on a host-by-host basis. (On the other hand, when the property is | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  |    * %FALSE, the application can reasonably expect that no remote | 
					
						
							|  |  |  |    * hosts at all are reachable, and should indicate this to the user | 
					
						
							|  |  |  |    * in its UI.) | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * See also #GNetworkMonitor::network-changed. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Since: 2.32 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   g_object_interface_install_property (iface, | 
					
						
							| 
									
										
										
										
											2023-04-28 01:59:26 +02:00
										 |  |  |                                        g_param_spec_boolean ("network-available", NULL, NULL, | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                                                              FALSE, | 
					
						
							|  |  |  |                                                              G_PARAM_READABLE | | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |                                                              G_PARAM_STATIC_STRINGS)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * GNetworkMonitor:network-metered: | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2023-07-29 15:22:15 +03:00
										 |  |  |    * Whether the network is considered metered. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * That is, whether the | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |    * system has traffic flowing through the default connection that is | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |    * subject to limitations set by service providers. For example, traffic | 
					
						
							|  |  |  |    * might be billed by the amount of data transmitted, or there might be a | 
					
						
							|  |  |  |    * quota on the amount of traffic per month. This is typical with tethered | 
					
						
							|  |  |  |    * connections (3G and 4G) and in such situations, bandwidth intensive | 
					
						
							|  |  |  |    * applications may wish to avoid network activity where possible if it will | 
					
						
							| 
									
										
										
										
											2023-07-29 15:22:15 +03:00
										 |  |  |    * cost the user money or use up their limited quota. Anything more than a | 
					
						
							|  |  |  |    * few hundreds of kilobytes of data usage per hour should be avoided without | 
					
						
							|  |  |  |    * asking permission from the user. | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |    * | 
					
						
							|  |  |  |    * If more information is required about specific devices then the | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |    * system network management API should be used instead (for example, | 
					
						
							|  |  |  |    * NetworkManager or ConnMan). | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |    * | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |    * If this information is not available then no networks will be | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |    * marked as metered. | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |    * See also #GNetworkMonitor:network-available. | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |    * | 
					
						
							|  |  |  |    * Since: 2.46 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   g_object_interface_install_property (iface, | 
					
						
							| 
									
										
										
										
											2023-04-28 01:59:26 +02:00
										 |  |  |                                        g_param_spec_boolean ("network-metered", NULL, NULL, | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |                                                              FALSE, | 
					
						
							|  |  |  |                                                              G_PARAM_READABLE | | 
					
						
							| 
									
										
										
										
											2011-12-10 21:46:13 -05:00
										 |  |  |                                                              G_PARAM_STATIC_STRINGS)); | 
					
						
							| 
									
										
										
										
											2014-04-16 10:39:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * GNetworkMonitor:connectivity: | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * More detailed information about the host's network connectivity. | 
					
						
							|  |  |  |    * See g_network_monitor_get_connectivity() and | 
					
						
							|  |  |  |    * #GNetworkConnectivity for more details. | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2014-12-10 18:39:21 +01:00
										 |  |  |    * Since: 2.44 | 
					
						
							| 
									
										
										
										
											2014-04-16 10:39:12 -04:00
										 |  |  |    */ | 
					
						
							|  |  |  |   g_object_interface_install_property (iface, | 
					
						
							| 
									
										
										
										
											2023-04-28 01:59:26 +02:00
										 |  |  |                                        g_param_spec_enum ("connectivity", NULL, NULL, | 
					
						
							| 
									
										
										
										
											2014-04-16 10:39:12 -04:00
										 |  |  |                                                           G_TYPE_NETWORK_CONNECTIVITY, | 
					
						
							|  |  |  |                                                           G_NETWORK_CONNECTIVITY_FULL, | 
					
						
							|  |  |  |                                                           G_PARAM_READABLE | | 
					
						
							|  |  |  |                                                           G_PARAM_STATIC_STRINGS)); | 
					
						
							| 
									
										
										
										
											2011-06-12 15:59:36 -04:00
										 |  |  | } |