Whitespace fixes

And add some missing since tags.
This commit is contained in:
Matthias Clasen 2011-12-10 21:46:13 -05:00
parent d50f77b394
commit 2d6d127c96
3 changed files with 213 additions and 209 deletions

View File

@ -47,7 +47,7 @@
*/ */
G_DEFINE_INTERFACE_WITH_CODE (GNetworkMonitor, g_network_monitor, G_TYPE_OBJECT, G_DEFINE_INTERFACE_WITH_CODE (GNetworkMonitor, g_network_monitor, G_TYPE_OBJECT,
g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE);) g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE);)
enum { enum {
@ -70,8 +70,8 @@ GNetworkMonitor *
g_network_monitor_get_default (void) g_network_monitor_get_default (void)
{ {
return _g_io_module_get_default (G_NETWORK_MONITOR_EXTENSION_POINT_NAME, return _g_io_module_get_default (G_NETWORK_MONITOR_EXTENSION_POINT_NAME,
"GIO_USE_NETWORK_MONITOR", "GIO_USE_NETWORK_MONITOR",
NULL); NULL);
} }
/** /**
@ -127,9 +127,9 @@ g_network_monitor_get_network_available (GNetworkMonitor *monitor)
*/ */
gboolean gboolean
g_network_monitor_can_reach (GNetworkMonitor *monitor, g_network_monitor_can_reach (GNetworkMonitor *monitor,
GSocketConnectable *connectable, GSocketConnectable *connectable,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
GNetworkMonitorInterface *iface; GNetworkMonitorInterface *iface;
@ -139,17 +139,17 @@ g_network_monitor_can_reach (GNetworkMonitor *monitor,
static void static void
g_network_monitor_real_can_reach_async (GNetworkMonitor *monitor, g_network_monitor_real_can_reach_async (GNetworkMonitor *monitor,
GSocketConnectable *connectable, GSocketConnectable *connectable,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple; GSimpleAsyncResult *simple;
GError *error = NULL; GError *error = NULL;
simple = g_simple_async_result_new (G_OBJECT (monitor), simple = g_simple_async_result_new (G_OBJECT (monitor),
callback, user_data, callback, user_data,
g_network_monitor_real_can_reach_async); g_network_monitor_real_can_reach_async);
if (g_network_monitor_can_reach (monitor, connectable, cancellable, &error)) if (g_network_monitor_can_reach (monitor, connectable, cancellable, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE); g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else else
@ -160,10 +160,10 @@ g_network_monitor_real_can_reach_async (GNetworkMonitor *monitor,
void void
g_network_monitor_can_reach_async (GNetworkMonitor *monitor, g_network_monitor_can_reach_async (GNetworkMonitor *monitor,
GSocketConnectable *connectable, GSocketConnectable *connectable,
GCancellable *cancellable, GCancellable *cancellable,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GNetworkMonitorInterface *iface; GNetworkMonitorInterface *iface;
@ -173,8 +173,8 @@ g_network_monitor_can_reach_async (GNetworkMonitor *monitor,
static gboolean static gboolean
g_network_monitor_real_can_reach_finish (GNetworkMonitor *monitor, g_network_monitor_real_can_reach_finish (GNetworkMonitor *monitor,
GAsyncResult *result, GAsyncResult *result,
GError **error) GError **error)
{ {
GSimpleAsyncResult *simple; GSimpleAsyncResult *simple;
@ -189,8 +189,8 @@ g_network_monitor_real_can_reach_finish (GNetworkMonitor *monitor,
gboolean gboolean
g_network_monitor_can_reach_finish (GNetworkMonitor *monitor, g_network_monitor_can_reach_finish (GNetworkMonitor *monitor,
GAsyncResult *result, GAsyncResult *result,
GError **error) GError **error)
{ {
GNetworkMonitorInterface *iface; GNetworkMonitorInterface *iface;
@ -219,13 +219,13 @@ g_network_monitor_default_init (GNetworkMonitorInterface *iface)
*/ */
signals[NETWORK_CHANGED] = signals[NETWORK_CHANGED] =
g_signal_new (I_("network-changed"), g_signal_new (I_("network-changed"),
G_TYPE_NETWORK_MONITOR, G_TYPE_NETWORK_MONITOR,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GNetworkMonitorInterface, network_changed), G_STRUCT_OFFSET (GNetworkMonitorInterface, network_changed),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN, g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_BOOLEAN); G_TYPE_BOOLEAN);
/** /**
* GNetworkMonitor:network-available: * GNetworkMonitor:network-available:
@ -252,10 +252,10 @@ g_network_monitor_default_init (GNetworkMonitorInterface *iface)
* Since: 2.32 * Since: 2.32
*/ */
g_object_interface_install_property (iface, g_object_interface_install_property (iface,
g_param_spec_boolean ("network-available", g_param_spec_boolean ("network-available",
P_("Network available"), P_("Network available"),
P_("Whether the network is available"), P_("Whether the network is available"),
FALSE, FALSE,
G_PARAM_READABLE | G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
} }

View File

@ -36,15 +36,15 @@ static void g_network_monitor_base_iface_init (GNetworkMonitorInterface *iface);
static void g_network_monitor_base_initable_iface_init (GInitableIface *iface); static void g_network_monitor_base_initable_iface_init (GInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorBase, g_network_monitor_base, G_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorBase, g_network_monitor_base, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
g_network_monitor_base_initable_iface_init) g_network_monitor_base_initable_iface_init)
G_IMPLEMENT_INTERFACE (G_TYPE_NETWORK_MONITOR, G_IMPLEMENT_INTERFACE (G_TYPE_NETWORK_MONITOR,
g_network_monitor_base_iface_init) g_network_monitor_base_iface_init)
_g_io_modules_ensure_extension_points_registered (); _g_io_modules_ensure_extension_points_registered ();
g_io_extension_point_implement (G_NETWORK_MONITOR_EXTENSION_POINT_NAME, g_io_extension_point_implement (G_NETWORK_MONITOR_EXTENSION_POINT_NAME,
g_define_type_id, g_define_type_id,
"base", "base",
0)) 0))
enum enum
{ {
@ -73,8 +73,8 @@ static void
g_network_monitor_base_init (GNetworkMonitorBase *monitor) g_network_monitor_base_init (GNetworkMonitorBase *monitor)
{ {
monitor->priv = G_TYPE_INSTANCE_GET_PRIVATE (monitor, monitor->priv = G_TYPE_INSTANCE_GET_PRIVATE (monitor,
G_TYPE_NETWORK_MONITOR_BASE, G_TYPE_NETWORK_MONITOR_BASE,
GNetworkMonitorBasePrivate); GNetworkMonitorBasePrivate);
monitor->priv->networks = g_ptr_array_new_with_free_func (g_object_unref); monitor->priv->networks = g_ptr_array_new_with_free_func (g_object_unref);
monitor->priv->context = g_main_context_get_thread_default (); monitor->priv->context = g_main_context_get_thread_default ();
@ -109,20 +109,20 @@ g_network_monitor_base_constructed (GObject *object)
static void static void
g_network_monitor_base_get_property (GObject *object, g_network_monitor_base_get_property (GObject *object,
guint prop_id, guint prop_id,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GNetworkMonitorBase *monitor = G_NETWORK_MONITOR_BASE (object); GNetworkMonitorBase *monitor = G_NETWORK_MONITOR_BASE (object);
switch (prop_id) switch (prop_id)
{ {
case PROP_NETWORK_AVAILABLE: case PROP_NETWORK_AVAILABLE:
g_value_set_boolean (value, monitor->priv->is_available); g_value_set_boolean (value, monitor->priv->is_available);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
} }
@ -160,9 +160,9 @@ g_network_monitor_base_class_init (GNetworkMonitorBaseClass *monitor_class)
static gboolean static gboolean
g_network_monitor_base_can_reach (GNetworkMonitor *monitor, g_network_monitor_base_can_reach (GNetworkMonitor *monitor,
GSocketConnectable *connectable, GSocketConnectable *connectable,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
GNetworkMonitorBasePrivate *priv = G_NETWORK_MONITOR_BASE (monitor)->priv; GNetworkMonitorBasePrivate *priv = G_NETWORK_MONITOR_BASE (monitor)->priv;
GSocketAddressEnumerator *enumerator; GSocketAddressEnumerator *enumerator;
@ -175,7 +175,7 @@ g_network_monitor_base_can_reach (GNetworkMonitor *monitor,
if (priv->networks->len == 0) if (priv->networks->len == 0)
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NETWORK_UNREACHABLE, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NETWORK_UNREACHABLE,
_("Network unreachable")); _("Network unreachable"));
return FALSE; return FALSE;
} }
@ -191,21 +191,21 @@ g_network_monitor_base_can_reach (GNetworkMonitor *monitor,
while (addr) while (addr)
{ {
if (G_IS_INET_SOCKET_ADDRESS (addr)) if (G_IS_INET_SOCKET_ADDRESS (addr))
{ {
GInetAddress *iaddr; GInetAddress *iaddr;
int i; int i;
iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (addr)); iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (addr));
for (i = 0; i < priv->networks->len; i++) for (i = 0; i < priv->networks->len; i++)
{ {
if (g_inet_address_mask_matches (priv->networks->pdata[i], iaddr)) if (g_inet_address_mask_matches (priv->networks->pdata[i], iaddr))
{ {
g_object_unref (addr); g_object_unref (addr);
g_object_unref (enumerator); g_object_unref (enumerator);
return TRUE; return TRUE;
} }
} }
} }
g_object_unref (addr); g_object_unref (addr);
addr = g_socket_address_enumerator_next (enumerator, cancellable, error); addr = g_socket_address_enumerator_next (enumerator, cancellable, error);
@ -215,7 +215,7 @@ g_network_monitor_base_can_reach (GNetworkMonitor *monitor,
if (error && !*error) if (error && !*error)
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_HOST_UNREACHABLE, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_HOST_UNREACHABLE,
_("Host unreachable")); _("Host unreachable"));
} }
return FALSE; return FALSE;
} }
@ -230,8 +230,8 @@ g_network_monitor_base_iface_init (GNetworkMonitorInterface *monitor_iface)
static gboolean static gboolean
g_network_monitor_base_initable_init (GInitable *initable, g_network_monitor_base_initable_init (GInitable *initable,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
return TRUE; return TRUE;
} }
@ -255,12 +255,12 @@ emit_network_changed (gpointer user_data)
else else
{ {
is_available = (monitor->priv->have_ipv4_default_route || is_available = (monitor->priv->have_ipv4_default_route ||
monitor->priv->have_ipv6_default_route); monitor->priv->have_ipv6_default_route);
if (monitor->priv->is_available != is_available) if (monitor->priv->is_available != is_available)
{ {
monitor->priv->is_available = is_available; monitor->priv->is_available = is_available;
g_object_notify (G_OBJECT (monitor), "network-available"); g_object_notify (G_OBJECT (monitor), "network-available");
} }
g_signal_emit (monitor, network_changed_signal, 0, is_available); g_signal_emit (monitor, network_changed_signal, 0, is_available);
} }
@ -298,7 +298,7 @@ queue_network_changed (GNetworkMonitorBase *monitor)
if (monitor->priv->initializing) if (monitor->priv->initializing)
{ {
monitor->priv->is_available = (monitor->priv->have_ipv4_default_route || monitor->priv->is_available = (monitor->priv->have_ipv4_default_route ||
monitor->priv->have_ipv6_default_route); monitor->priv->have_ipv6_default_route);
} }
} }
@ -308,33 +308,35 @@ queue_network_changed (GNetworkMonitorBase *monitor)
* @network: a #GInetAddressMask * @network: a #GInetAddressMask
* *
* Adds @network to @monitor's list of available networks. * Adds @network to @monitor's list of available networks.
*
* Since: 2.32
*/ */
void void
g_network_monitor_base_add_network (GNetworkMonitorBase *monitor, g_network_monitor_base_add_network (GNetworkMonitorBase *monitor,
GInetAddressMask *network) GInetAddressMask *network)
{ {
int i; int i;
for (i = 0; i < monitor->priv->networks->len; i++) for (i = 0; i < monitor->priv->networks->len; i++)
{ {
if (g_inet_address_mask_equal (monitor->priv->networks->pdata[i], network)) if (g_inet_address_mask_equal (monitor->priv->networks->pdata[i], network))
return; return;
} }
g_ptr_array_add (monitor->priv->networks, g_object_ref (network)); g_ptr_array_add (monitor->priv->networks, g_object_ref (network));
if (g_inet_address_mask_get_length (network) == 0) if (g_inet_address_mask_get_length (network) == 0)
{ {
switch (g_inet_address_mask_get_family (network)) switch (g_inet_address_mask_get_family (network))
{ {
case G_SOCKET_FAMILY_IPV4: case G_SOCKET_FAMILY_IPV4:
monitor->priv->have_ipv4_default_route = TRUE; monitor->priv->have_ipv4_default_route = TRUE;
break; break;
case G_SOCKET_FAMILY_IPV6: case G_SOCKET_FAMILY_IPV6:
monitor->priv->have_ipv6_default_route = TRUE; monitor->priv->have_ipv6_default_route = TRUE;
break; break;
default: default:
break; break;
} }
} }
/* Don't emit network-changed when multicast-link-local routing /* Don't emit network-changed when multicast-link-local routing
@ -353,37 +355,39 @@ g_network_monitor_base_add_network (GNetworkMonitorBase *monitor,
* @network: a #GInetAddressMask * @network: a #GInetAddressMask
* *
* Removes @network from @monitor's list of available networks. * Removes @network from @monitor's list of available networks.
*
* Since: 2.32
*/ */
void void
g_network_monitor_base_remove_network (GNetworkMonitorBase *monitor, g_network_monitor_base_remove_network (GNetworkMonitorBase *monitor,
GInetAddressMask *network) GInetAddressMask *network)
{ {
int i; int i;
for (i = 0; i < monitor->priv->networks->len; i++) for (i = 0; i < monitor->priv->networks->len; i++)
{ {
if (g_inet_address_mask_equal (monitor->priv->networks->pdata[i], network)) if (g_inet_address_mask_equal (monitor->priv->networks->pdata[i], network))
{ {
g_ptr_array_remove_index_fast (monitor->priv->networks, i); g_ptr_array_remove_index_fast (monitor->priv->networks, i);
if (g_inet_address_mask_get_length (network) == 0) if (g_inet_address_mask_get_length (network) == 0)
{ {
switch (g_inet_address_mask_get_family (network)) switch (g_inet_address_mask_get_family (network))
{ {
case G_SOCKET_FAMILY_IPV4: case G_SOCKET_FAMILY_IPV4:
monitor->priv->have_ipv4_default_route = FALSE; monitor->priv->have_ipv4_default_route = FALSE;
break; break;
case G_SOCKET_FAMILY_IPV6: case G_SOCKET_FAMILY_IPV6:
monitor->priv->have_ipv6_default_route = FALSE; monitor->priv->have_ipv6_default_route = FALSE;
break; break;
default: default:
break; break;
} }
} }
queue_network_changed (monitor); queue_network_changed (monitor);
return; return;
} }
} }
} }
@ -398,8 +402,8 @@ g_network_monitor_base_remove_network (GNetworkMonitorBase *monitor,
*/ */
void void
g_network_monitor_base_set_networks (GNetworkMonitorBase *monitor, g_network_monitor_base_set_networks (GNetworkMonitorBase *monitor,
GInetAddressMask **networks, GInetAddressMask **networks,
gint length) gint length)
{ {
int i; int i;

View File

@ -41,15 +41,15 @@ static void g_network_monitor_netlink_initable_iface_init (GInitableIface *iface
#define g_network_monitor_netlink_get_type _g_network_monitor_netlink_get_type #define g_network_monitor_netlink_get_type _g_network_monitor_netlink_get_type
G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorNetlink, g_network_monitor_netlink, G_TYPE_NETWORK_MONITOR_BASE, G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorNetlink, g_network_monitor_netlink, G_TYPE_NETWORK_MONITOR_BASE,
G_IMPLEMENT_INTERFACE (G_TYPE_NETWORK_MONITOR, G_IMPLEMENT_INTERFACE (G_TYPE_NETWORK_MONITOR,
g_network_monitor_netlink_iface_init) g_network_monitor_netlink_iface_init)
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
g_network_monitor_netlink_initable_iface_init) g_network_monitor_netlink_initable_iface_init)
_g_io_modules_ensure_extension_points_registered (); _g_io_modules_ensure_extension_points_registered ();
g_io_extension_point_implement (G_NETWORK_MONITOR_EXTENSION_POINT_NAME, g_io_extension_point_implement (G_NETWORK_MONITOR_EXTENSION_POINT_NAME,
g_define_type_id, g_define_type_id,
"netlink", "netlink",
20)) 20))
struct _GNetworkMonitorNetlinkPrivate struct _GNetworkMonitorNetlinkPrivate
{ {
@ -60,24 +60,24 @@ struct _GNetworkMonitorNetlinkPrivate
}; };
static gboolean read_netlink_messages (GSocket *socket, static gboolean read_netlink_messages (GSocket *socket,
GIOCondition condition, GIOCondition condition,
gpointer user_data); gpointer user_data);
static gboolean request_dump (GNetworkMonitorNetlink *nl, static gboolean request_dump (GNetworkMonitorNetlink *nl,
GError **error); GError **error);
static void static void
g_network_monitor_netlink_init (GNetworkMonitorNetlink *nl) g_network_monitor_netlink_init (GNetworkMonitorNetlink *nl)
{ {
nl->priv = G_TYPE_INSTANCE_GET_PRIVATE (nl, nl->priv = G_TYPE_INSTANCE_GET_PRIVATE (nl,
G_TYPE_NETWORK_MONITOR_NETLINK, G_TYPE_NETWORK_MONITOR_NETLINK,
GNetworkMonitorNetlinkPrivate); GNetworkMonitorNetlinkPrivate);
} }
static gboolean static gboolean
g_network_monitor_netlink_initable_init (GInitable *initable, g_network_monitor_netlink_initable_init (GInitable *initable,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
GNetworkMonitorNetlink *nl = G_NETWORK_MONITOR_NETLINK (initable); GNetworkMonitorNetlink *nl = G_NETWORK_MONITOR_NETLINK (initable);
gint sockfd, val; gint sockfd, val;
@ -91,8 +91,8 @@ g_network_monitor_netlink_initable_init (GInitable *initable,
{ {
int errsv = errno; int errsv = errno;
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Could not create network monitor: %s"), _("Could not create network monitor: %s"),
g_strerror (errno)); g_strerror (errno));
return FALSE; return FALSE;
} }
@ -103,8 +103,8 @@ g_network_monitor_netlink_initable_init (GInitable *initable,
{ {
int errsv = errno; int errsv = errno;
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Could not create network monitor: %s"), _("Could not create network monitor: %s"),
g_strerror (errno)); g_strerror (errno));
close (sockfd); close (sockfd);
return FALSE; return FALSE;
} }
@ -114,8 +114,8 @@ g_network_monitor_netlink_initable_init (GInitable *initable,
{ {
int errsv = errno; int errsv = errno;
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Could not create network monitor: %s"), _("Could not create network monitor: %s"),
g_strerror (errno)); g_strerror (errno));
close (sockfd); close (sockfd);
return FALSE; return FALSE;
} }
@ -138,22 +138,22 @@ g_network_monitor_netlink_initable_init (GInitable *initable,
while (nl->priv->dump_networks) while (nl->priv->dump_networks)
{ {
if (!read_netlink_messages (NULL, G_IO_IN, nl)) if (!read_netlink_messages (NULL, G_IO_IN, nl))
break; break;
} }
g_socket_set_blocking (nl->priv->sock, FALSE); g_socket_set_blocking (nl->priv->sock, FALSE);
nl->priv->source = g_socket_create_source (nl->priv->sock, G_IO_IN, NULL); nl->priv->source = g_socket_create_source (nl->priv->sock, G_IO_IN, NULL);
g_source_set_callback (nl->priv->source, g_source_set_callback (nl->priv->source,
(GSourceFunc) read_netlink_messages, nl, NULL); (GSourceFunc) read_netlink_messages, nl, NULL);
g_source_attach (nl->priv->source, g_source_attach (nl->priv->source,
g_main_context_get_thread_default ()); g_main_context_get_thread_default ());
return TRUE; return TRUE;
} }
static gboolean static gboolean
request_dump (GNetworkMonitorNetlink *nl, request_dump (GNetworkMonitorNetlink *nl,
GError **error) GError **error)
{ {
struct nlmsghdr *n; struct nlmsghdr *n;
struct rtgenmsg *gen; struct rtgenmsg *gen;
@ -169,7 +169,7 @@ request_dump (GNetworkMonitorNetlink *nl,
gen->rtgen_family = AF_UNSPEC; gen->rtgen_family = AF_UNSPEC;
if (g_socket_send (nl->priv->sock, buf, sizeof (buf), if (g_socket_send (nl->priv->sock, buf, sizeof (buf),
NULL, error) < 0) NULL, error) < 0)
{ {
g_prefix_error (error, "%s", _("Could not get network status: ")); g_prefix_error (error, "%s", _("Could not get network status: "));
return FALSE; return FALSE;
@ -207,17 +207,17 @@ queue_request_dump (GNetworkMonitorNetlink *nl)
nl->priv->dump_source = g_timeout_source_new (1000); nl->priv->dump_source = g_timeout_source_new (1000);
g_source_set_callback (nl->priv->dump_source, g_source_set_callback (nl->priv->dump_source,
(GSourceFunc) timeout_request_dump, nl, NULL); (GSourceFunc) timeout_request_dump, nl, NULL);
g_source_attach (nl->priv->dump_source, g_source_attach (nl->priv->dump_source,
g_main_context_get_thread_default ()); g_main_context_get_thread_default ());
} }
static void static void
add_network (GNetworkMonitorNetlink *nl, add_network (GNetworkMonitorNetlink *nl,
GSocketFamily family, GSocketFamily family,
gint dest_len, gint dest_len,
guint8 *dest, guint8 *dest,
guint8 *gateway) guint8 *gateway)
{ {
GInetAddress *dest_addr; GInetAddress *dest_addr;
GInetAddressMask *network; GInetAddressMask *network;
@ -241,10 +241,10 @@ add_network (GNetworkMonitorNetlink *nl,
static void static void
remove_network (GNetworkMonitorNetlink *nl, remove_network (GNetworkMonitorNetlink *nl,
GSocketFamily family, GSocketFamily family,
gint dest_len, gint dest_len,
guint8 *dest, guint8 *dest,
guint8 *gateway) guint8 *gateway)
{ {
GInetAddress *dest_addr; GInetAddress *dest_addr;
GInetAddressMask *network; GInetAddressMask *network;
@ -263,10 +263,10 @@ remove_network (GNetworkMonitorNetlink *nl,
int i; int i;
for (i = 0; i < nl->priv->dump_networks->len; i++) for (i = 0; i < nl->priv->dump_networks->len; i++)
{ {
if (g_inet_address_mask_equal (network, dump_networks[i])) if (g_inet_address_mask_equal (network, dump_networks[i]))
g_ptr_array_remove_index_fast (nl->priv->dump_networks, i--); g_ptr_array_remove_index_fast (nl->priv->dump_networks, i--);
} }
g_object_unref (network); g_object_unref (network);
} }
else else
@ -280,16 +280,16 @@ static void
finish_dump (GNetworkMonitorNetlink *nl) finish_dump (GNetworkMonitorNetlink *nl)
{ {
g_network_monitor_base_set_networks (G_NETWORK_MONITOR_BASE (nl), g_network_monitor_base_set_networks (G_NETWORK_MONITOR_BASE (nl),
(GInetAddressMask **)nl->priv->dump_networks->pdata, (GInetAddressMask **)nl->priv->dump_networks->pdata,
nl->priv->dump_networks->len); nl->priv->dump_networks->len);
g_ptr_array_free (nl->priv->dump_networks, FALSE); g_ptr_array_free (nl->priv->dump_networks, FALSE);
nl->priv->dump_networks = NULL; nl->priv->dump_networks = NULL;
} }
static gboolean static gboolean
read_netlink_messages (GSocket *socket, read_netlink_messages (GSocket *socket,
GIOCondition condition, GIOCondition condition,
gpointer user_data) gpointer user_data)
{ {
GNetworkMonitorNetlink *nl = user_data; GNetworkMonitorNetlink *nl = user_data;
GInputVector iv; GInputVector iv;
@ -311,26 +311,26 @@ read_netlink_messages (GSocket *socket,
flags = MSG_PEEK | MSG_TRUNC; flags = MSG_PEEK | MSG_TRUNC;
len = g_socket_receive_message (nl->priv->sock, NULL, &iv, 1, len = g_socket_receive_message (nl->priv->sock, NULL, &iv, 1,
NULL, NULL, &flags, NULL, &error); NULL, NULL, &flags, NULL, &error);
if (len < 0) if (len < 0)
{ {
g_warning ("Error on netlink socket: %s", error->message); g_warning ("Error on netlink socket: %s", error->message);
g_error_free (error); g_error_free (error);
if (nl->priv->dump_networks) if (nl->priv->dump_networks)
finish_dump (nl); finish_dump (nl);
return FALSE; return FALSE;
} }
iv.buffer = g_malloc (len); iv.buffer = g_malloc (len);
iv.size = len; iv.size = len;
len = g_socket_receive_message (nl->priv->sock, NULL, &iv, 1, len = g_socket_receive_message (nl->priv->sock, NULL, &iv, 1,
&cmsgs, &num_cmsgs, NULL, NULL, &error); &cmsgs, &num_cmsgs, NULL, NULL, &error);
if (len < 0) if (len < 0)
{ {
g_warning ("Error on netlink socket: %s", error->message); g_warning ("Error on netlink socket: %s", error->message);
g_error_free (error); g_error_free (error);
if (nl->priv->dump_networks) if (nl->priv->dump_networks)
finish_dump (nl); finish_dump (nl);
return FALSE; return FALSE;
} }
@ -346,63 +346,63 @@ read_netlink_messages (GSocket *socket,
for (; len > 0; msg = NLMSG_NEXT (msg, len)) for (; len > 0; msg = NLMSG_NEXT (msg, len))
{ {
if (!NLMSG_OK (msg, (size_t) len)) if (!NLMSG_OK (msg, (size_t) len))
{ {
g_warning ("netlink message was truncated; shouldn't happen..."); g_warning ("netlink message was truncated; shouldn't happen...");
retval = FALSE; retval = FALSE;
goto done; goto done;
} }
switch (msg->nlmsg_type) switch (msg->nlmsg_type)
{ {
case RTM_NEWROUTE: case RTM_NEWROUTE:
case RTM_DELROUTE: case RTM_DELROUTE:
rtmsg = NLMSG_DATA (msg); rtmsg = NLMSG_DATA (msg);
if (rtmsg->rtm_family != AF_INET && rtmsg->rtm_family != AF_INET6) if (rtmsg->rtm_family != AF_INET && rtmsg->rtm_family != AF_INET6)
continue; continue;
if (rtmsg->rtm_type == RTN_UNREACHABLE) if (rtmsg->rtm_type == RTN_UNREACHABLE)
continue; continue;
attrlen = NLMSG_PAYLOAD (msg, sizeof (struct rtmsg)); attrlen = NLMSG_PAYLOAD (msg, sizeof (struct rtmsg));
attr = RTM_RTA (rtmsg); attr = RTM_RTA (rtmsg);
dest = gateway = NULL; dest = gateway = NULL;
while (RTA_OK (attr, attrlen)) while (RTA_OK (attr, attrlen))
{ {
if (attr->rta_type == RTA_DST) if (attr->rta_type == RTA_DST)
dest = RTA_DATA (attr); dest = RTA_DATA (attr);
else if (attr->rta_type == RTA_GATEWAY) else if (attr->rta_type == RTA_GATEWAY)
gateway = RTA_DATA (attr); gateway = RTA_DATA (attr);
attr = RTA_NEXT (attr, attrlen); attr = RTA_NEXT (attr, attrlen);
} }
if (dest || gateway) if (dest || gateway)
{ {
if (msg->nlmsg_type == RTM_NEWROUTE) if (msg->nlmsg_type == RTM_NEWROUTE)
add_network (nl, rtmsg->rtm_family, rtmsg->rtm_dst_len, dest, gateway); add_network (nl, rtmsg->rtm_family, rtmsg->rtm_dst_len, dest, gateway);
else else
remove_network (nl, rtmsg->rtm_family, rtmsg->rtm_dst_len, dest, gateway); remove_network (nl, rtmsg->rtm_family, rtmsg->rtm_dst_len, dest, gateway);
queue_request_dump (nl); queue_request_dump (nl);
} }
break; break;
case NLMSG_DONE: case NLMSG_DONE:
finish_dump (nl); finish_dump (nl);
goto done; goto done;
case NLMSG_ERROR: case NLMSG_ERROR:
{ {
struct nlmsgerr *e = NLMSG_DATA (msg); struct nlmsgerr *e = NLMSG_DATA (msg);
g_warning ("netlink error: %s", g_strerror (-e->error)); g_warning ("netlink error: %s", g_strerror (-e->error));
} }
retval = FALSE; retval = FALSE;
goto done; goto done;
default: default:
g_warning ("unexpected netlink message %d", msg->nlmsg_type); g_warning ("unexpected netlink message %d", msg->nlmsg_type);
retval = FALSE; retval = FALSE;
goto done; goto done;
} }
} }
done: done: