2007-03-02 Tambet Ingo <tambet@ximian.com>
* libnm-glib/nm-device-802-11-wireless.c (nm_device_802_11_wireless_get_capabilities): Implement. * libnm-glib/nm-device.c (nm_device_get_capabilities): Implement. * src/nm-device-802-11-wireless.c: Add "WirelessCapabilities" property. * src/named-manager/nm-named-manager.c (remove_one_zone_from_named): Unref the reply only if it's not NULL. Not sure why this started happening right now. * src/nm-manager.c (device_stop_and_free): Remove. No need to have different code paths for when devices get removed on shutdown or when a device is just removed. (finalize): Don't use a g_slist_foreach() when removing devices, the list data gets freed so any signal from a device (disconnected for instance) would invoke NMState update which would crash. (nm_manager_remove_device): Bring the device down when it gets removed. * src/NetworkManagerPolicy.c (nm_policy_auto_get_best_device): Remove the unused dev_type. * src/nm-hal-manager.c (create_device_and_add_to_list): Don't keep the reference to the added device, NMManager will own it (if it wants). * test/nm-tool.c: Rewrite using libnm-glib. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2417 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
26
ChangeLog
26
ChangeLog
@@ -1,5 +1,31 @@
|
|||||||
2007-03-02 Tambet Ingo <tambet@ximian.com>
|
2007-03-02 Tambet Ingo <tambet@ximian.com>
|
||||||
|
|
||||||
|
* libnm-glib/nm-device-802-11-wireless.c
|
||||||
|
(nm_device_802_11_wireless_get_capabilities): Implement.
|
||||||
|
|
||||||
|
* libnm-glib/nm-device.c (nm_device_get_capabilities): Implement.
|
||||||
|
|
||||||
|
* src/nm-device-802-11-wireless.c: Add "WirelessCapabilities" property.
|
||||||
|
|
||||||
|
* src/named-manager/nm-named-manager.c (remove_one_zone_from_named): Unref the
|
||||||
|
reply only if it's not NULL. Not sure why this started happening right now.
|
||||||
|
|
||||||
|
* src/nm-manager.c (device_stop_and_free): Remove. No need to have different
|
||||||
|
code paths for when devices get removed on shutdown or when a device is just
|
||||||
|
removed.
|
||||||
|
(finalize): Don't use a g_slist_foreach() when removing devices, the list data
|
||||||
|
gets freed so any signal from a device (disconnected for instance) would invoke
|
||||||
|
NMState update which would crash.
|
||||||
|
(nm_manager_remove_device): Bring the device down when it gets removed.
|
||||||
|
|
||||||
|
* src/NetworkManagerPolicy.c (nm_policy_auto_get_best_device): Remove
|
||||||
|
the unused dev_type.
|
||||||
|
|
||||||
|
* src/nm-hal-manager.c (create_device_and_add_to_list): Don't keep the
|
||||||
|
reference to the added device, NMManager will own it (if it wants).
|
||||||
|
|
||||||
|
* test/nm-tool.c: Rewrite using libnm-glib.
|
||||||
|
|
||||||
* libnm-glib/nm-device-802-11-wireless.c: Cache networks (bssids) list.
|
* libnm-glib/nm-device-802-11-wireless.c: Cache networks (bssids) list.
|
||||||
We get signalled when it changes.
|
We get signalled when it changes.
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
<property name="Mode" type="i" access="read"/>
|
<property name="Mode" type="i" access="read"/>
|
||||||
<property name="Bitrate" type="i" access="read"/>
|
<property name="Bitrate" type="i" access="read"/>
|
||||||
<property name="ActiveNetwork" type="o" access="read"/>
|
<property name="ActiveNetwork" type="o" access="read"/>
|
||||||
|
<property name="WirelessCapabilities" type="u" access="read"/>
|
||||||
|
|
||||||
<signal name="NetworkAdded">
|
<signal name="NetworkAdded">
|
||||||
<arg name="network" type="o"/>
|
<arg name="network" type="o"/>
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
<property name="Udi" type="s" access="read"/>
|
<property name="Udi" type="s" access="read"/>
|
||||||
<property name="Interface" type="s" access="read"/>
|
<property name="Interface" type="s" access="read"/>
|
||||||
<property name="Driver" type="s" access="read"/>
|
<property name="Driver" type="s" access="read"/>
|
||||||
<property name="Capabilities" type="i" access="read"/>
|
<property name="Capabilities" type="u" access="read"/>
|
||||||
<property name="Ip4Address" type="i" access="read"/>
|
<property name="Ip4Address" type="i" access="read"/>
|
||||||
<property name="State" type="u" access="read"/>
|
<property name="State" type="u" access="read"/>
|
||||||
<property name="Ip4Config" type="o" access="read"/>
|
<property name="Ip4Config" type="o" access="read"/>
|
||||||
|
@@ -161,6 +161,23 @@ nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device)
|
|||||||
return bitrate;
|
return bitrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guint32
|
||||||
|
nm_device_802_11_wireless_get_capabilities (NMDevice80211Wireless *device)
|
||||||
|
{
|
||||||
|
guint32 caps = 0;
|
||||||
|
GValue value = {0,};
|
||||||
|
|
||||||
|
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
|
||||||
|
|
||||||
|
if (nm_dbus_get_property (DBUS_G_PROXY (device),
|
||||||
|
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
|
||||||
|
"WirelessCapabilities",
|
||||||
|
&value))
|
||||||
|
caps = g_value_get_uint (&value);
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
static NMAccessPoint *
|
static NMAccessPoint *
|
||||||
get_network (NMDevice80211Wireless *device, const char *path, gboolean create_if_not_found)
|
get_network (NMDevice80211Wireless *device, const char *path, gboolean create_if_not_found)
|
||||||
{
|
{
|
||||||
|
@@ -31,6 +31,7 @@ NMDevice80211Wireless *nm_device_802_11_wireless_new (DBusGConnection *c
|
|||||||
char *nm_device_802_11_wireless_get_hw_address (NMDevice80211Wireless *device);
|
char *nm_device_802_11_wireless_get_hw_address (NMDevice80211Wireless *device);
|
||||||
int nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device);
|
int nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device);
|
||||||
int nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device);
|
int nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device);
|
||||||
|
guint32 nm_device_802_11_wireless_get_capabilities (NMDevice80211Wireless *device);
|
||||||
NMAccessPoint *nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device);
|
NMAccessPoint *nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device);
|
||||||
|
|
||||||
GSList *nm_device_802_11_wireless_get_networks (NMDevice80211Wireless *device);
|
GSList *nm_device_802_11_wireless_get_networks (NMDevice80211Wireless *device);
|
||||||
|
@@ -160,6 +160,23 @@ nm_device_get_driver (NMDevice *device)
|
|||||||
return driver;
|
return driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guint32
|
||||||
|
nm_device_get_capabilities (NMDevice *device)
|
||||||
|
{
|
||||||
|
guint32 caps = 0;
|
||||||
|
GValue value = {0,};
|
||||||
|
|
||||||
|
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
|
||||||
|
|
||||||
|
if (nm_dbus_get_property (DBUS_G_PROXY (device),
|
||||||
|
NM_DBUS_INTERFACE_DEVICE,
|
||||||
|
"Capabilities",
|
||||||
|
&value))
|
||||||
|
caps = g_value_get_uint (&value);
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
guint32
|
guint32
|
||||||
nm_device_get_ip4_address (NMDevice *device)
|
nm_device_get_ip4_address (NMDevice *device)
|
||||||
{
|
{
|
||||||
|
@@ -34,6 +34,7 @@ void nm_device_deactivate (NMDevice *device);
|
|||||||
char *nm_device_get_iface (NMDevice *device);
|
char *nm_device_get_iface (NMDevice *device);
|
||||||
char *nm_device_get_udi (NMDevice *device);
|
char *nm_device_get_udi (NMDevice *device);
|
||||||
char *nm_device_get_driver (NMDevice *device);
|
char *nm_device_get_driver (NMDevice *device);
|
||||||
|
guint32 nm_device_get_capabilities (NMDevice *device);
|
||||||
guint32 nm_device_get_ip4_address (NMDevice *device);
|
guint32 nm_device_get_ip4_address (NMDevice *device);
|
||||||
NMIP4Config *nm_device_get_ip4_config (NMDevice *device);
|
NMIP4Config *nm_device_get_ip4_config (NMDevice *device);
|
||||||
NMDeviceState nm_device_get_state (NMDevice *device);
|
NMDeviceState nm_device_get_state (NMDevice *device);
|
||||||
|
@@ -80,13 +80,11 @@ static NMDevice * nm_policy_auto_get_best_device (NMPolicy *policy, NMAccessPoin
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) {
|
for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) {
|
||||||
guint dev_type;
|
|
||||||
gboolean link_active;
|
gboolean link_active;
|
||||||
guint prio = 0;
|
guint prio = 0;
|
||||||
NMDevice * dev = (NMDevice *)(elt->data);
|
NMDevice * dev = (NMDevice *)(elt->data);
|
||||||
guint32 caps;
|
guint32 caps;
|
||||||
|
|
||||||
dev_type = nm_device_get_device_type (dev);
|
|
||||||
link_active = nm_device_has_active_link (dev);
|
link_active = nm_device_has_active_link (dev);
|
||||||
caps = nm_device_get_capabilities (dev);
|
caps = nm_device_get_capabilities (dev);
|
||||||
|
|
||||||
|
@@ -498,7 +498,9 @@ remove_one_zone_from_named (NMNamedManager *mgr, const char *zone)
|
|||||||
out:
|
out:
|
||||||
if (dbus_error_is_set (&error))
|
if (dbus_error_is_set (&error))
|
||||||
dbus_error_free (&error);
|
dbus_error_free (&error);
|
||||||
dbus_message_unref (reply);
|
if (reply)
|
||||||
|
dbus_message_unref (reply);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -79,6 +79,7 @@ enum {
|
|||||||
PROP_MODE,
|
PROP_MODE,
|
||||||
PROP_BITRATE,
|
PROP_BITRATE,
|
||||||
PROP_ACTIVE_NETWORK,
|
PROP_ACTIVE_NETWORK,
|
||||||
|
PROP_CAPABILITIES,
|
||||||
|
|
||||||
LAST_PROP
|
LAST_PROP
|
||||||
};
|
};
|
||||||
@@ -3048,6 +3049,7 @@ get_property (GObject *object, guint prop_id,
|
|||||||
GValue *value, GParamSpec *pspec)
|
GValue *value, GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
NMDevice80211Wireless *device = NM_DEVICE_802_11_WIRELESS (object);
|
NMDevice80211Wireless *device = NM_DEVICE_802_11_WIRELESS (object);
|
||||||
|
NMDevice80211WirelessPrivate *priv = NM_DEVICE_802_11_WIRELESS_GET_PRIVATE (device);
|
||||||
struct ether_addr hw_addr;
|
struct ether_addr hw_addr;
|
||||||
char hw_addr_buf[20];
|
char hw_addr_buf[20];
|
||||||
NMAccessPoint *ap;
|
NMAccessPoint *ap;
|
||||||
@@ -3066,6 +3068,9 @@ get_property (GObject *object, guint prop_id,
|
|||||||
case PROP_BITRATE:
|
case PROP_BITRATE:
|
||||||
g_value_set_int (value, nm_device_802_11_wireless_get_bitrate (device));
|
g_value_set_int (value, nm_device_802_11_wireless_get_bitrate (device));
|
||||||
break;
|
break;
|
||||||
|
case PROP_CAPABILITIES:
|
||||||
|
g_value_set_uint (value, priv->capabilities);
|
||||||
|
break;
|
||||||
case PROP_ACTIVE_NETWORK:
|
case PROP_ACTIVE_NETWORK:
|
||||||
req = nm_device_get_act_request (NM_DEVICE (device));
|
req = nm_device_get_act_request (NM_DEVICE (device));
|
||||||
if (req && (ap = nm_act_request_get_ap (req))) {
|
if (req && (ap = nm_act_request_get_ap (req))) {
|
||||||
@@ -3140,6 +3145,13 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass)
|
|||||||
"Currently active network",
|
"Currently active network",
|
||||||
G_TYPE_OBJECT,
|
G_TYPE_OBJECT,
|
||||||
G_PARAM_READABLE));
|
G_PARAM_READABLE));
|
||||||
|
g_object_class_install_property
|
||||||
|
(object_class, PROP_CAPABILITIES,
|
||||||
|
g_param_spec_uint (NM_DEVICE_802_11_WIRELESS_CAPABILITIES,
|
||||||
|
"Wireless Capabilities",
|
||||||
|
"Wireless Capabilities",
|
||||||
|
0, G_MAXUINT32, NM_802_11_CAP_NONE,
|
||||||
|
G_PARAM_READABLE));
|
||||||
|
|
||||||
/* Signals */
|
/* Signals */
|
||||||
signals[NETWORK_ADDED] =
|
signals[NETWORK_ADDED] =
|
||||||
|
@@ -47,6 +47,7 @@ G_BEGIN_DECLS
|
|||||||
#define NM_DEVICE_802_11_WIRELESS_MODE "mode"
|
#define NM_DEVICE_802_11_WIRELESS_MODE "mode"
|
||||||
#define NM_DEVICE_802_11_WIRELESS_BITRATE "bitrate"
|
#define NM_DEVICE_802_11_WIRELESS_BITRATE "bitrate"
|
||||||
#define NM_DEVICE_802_11_WIRELESS_ACTIVE_NETWORK "active-network"
|
#define NM_DEVICE_802_11_WIRELESS_ACTIVE_NETWORK "active-network"
|
||||||
|
#define NM_DEVICE_802_11_WIRELESS_CAPABILITIES "wireless-capabilities"
|
||||||
|
|
||||||
#ifndef NM_DEVICE_802_11_WIRELESS_DEFINED
|
#ifndef NM_DEVICE_802_11_WIRELESS_DEFINED
|
||||||
#define NM_DEVICE_802_11_WIRELESS_DEFINED
|
#define NM_DEVICE_802_11_WIRELESS_DEFINED
|
||||||
|
@@ -130,6 +130,7 @@ create_device_and_add_to_list (NMHalManager *manager, const char *udi, const cha
|
|||||||
nm_device_get_iface (dev));
|
nm_device_get_iface (dev));
|
||||||
|
|
||||||
nm_manager_add_device (manager->nm_manager, dev);
|
nm_manager_add_device (manager->nm_manager, dev);
|
||||||
|
g_object_unref (dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
|
@@ -53,24 +53,14 @@ nm_manager_init (NMManager *manager)
|
|||||||
priv->sleeping = FALSE;
|
priv->sleeping = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
device_stop_and_free (gpointer data, gpointer user_data)
|
|
||||||
{
|
|
||||||
NMDevice *device = NM_DEVICE (data);
|
|
||||||
|
|
||||||
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device));
|
|
||||||
g_object_unref (device);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
finalize (GObject *object)
|
finalize (GObject *object)
|
||||||
{
|
{
|
||||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object);
|
NMManager *manager = NM_MANAGER (object);
|
||||||
|
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||||
|
|
||||||
g_slist_foreach (priv->devices,
|
while (g_slist_length (priv->devices))
|
||||||
device_stop_and_free,
|
nm_manager_remove_device (manager, NM_DEVICE (priv->devices->data));
|
||||||
NULL);
|
|
||||||
g_slist_free (priv->devices);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (nm_manager_parent_class)->finalize (object);
|
G_OBJECT_CLASS (nm_manager_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
@@ -283,6 +273,7 @@ nm_manager_remove_device (NMManager *manager, NMDevice *device)
|
|||||||
|
|
||||||
g_signal_handlers_disconnect_by_func (device, manager_device_state_changed, manager);
|
g_signal_handlers_disconnect_by_func (device, manager_device_state_changed, manager);
|
||||||
|
|
||||||
|
nm_device_bring_down (device, FALSE);
|
||||||
manager_device_removed (manager, device);
|
manager_device_removed (manager, device);
|
||||||
g_object_unref (device);
|
g_object_unref (device);
|
||||||
break;
|
break;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
SUBDIRS=test-common libnm-util
|
SUBDIRS=test-common libnm-util
|
||||||
|
|
||||||
INCLUDES = -I${top_srcdir} \
|
INCLUDES = -I${top_srcdir} \
|
||||||
|
-I${top_srcdir}/libnm-glib \
|
||||||
-I${top_srcdir}/gnome/libnm_glib \
|
-I${top_srcdir}/gnome/libnm_glib \
|
||||||
-I${top_srcdir}/utils \
|
-I${top_srcdir}/utils \
|
||||||
-I${top_srcdir}/include
|
-I${top_srcdir}/include
|
||||||
@@ -23,7 +24,7 @@ noinst_PROGRAMS = nm-tool \
|
|||||||
|
|
||||||
nm_tool_SOURCES = nm-tool.c
|
nm_tool_SOURCES = nm-tool.c
|
||||||
nm_tool_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
nm_tool_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
||||||
$(top_builddir)/utils/libnmutils.la
|
$(top_builddir)/libnm-glib/libnm-glib.la
|
||||||
|
|
||||||
nm_online_SOURCES = nm-online.c
|
nm_online_SOURCES = nm-online.c
|
||||||
nm_online_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
nm_online_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
||||||
|
632
test/nm-tool.c
632
test/nm-tool.c
@@ -28,68 +28,57 @@
|
|||||||
|
|
||||||
#include <iwlib.h>
|
#include <iwlib.h>
|
||||||
|
|
||||||
#include "NetworkManager.h"
|
#include <sys/socket.h>
|
||||||
#include "nm-utils.h"
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <nm-client.h>
|
||||||
|
#include <nm-device.h>
|
||||||
|
#include <nm-device-802-3-ethernet.h>
|
||||||
|
#include <nm-device-802-11-wireless.h>
|
||||||
|
|
||||||
|
|
||||||
static gboolean get_nm_state (DBusConnection *connection)
|
|
||||||
|
static gboolean
|
||||||
|
get_nm_state (NMClient *client)
|
||||||
{
|
{
|
||||||
dbus_uint32_t uint32_state;
|
NMState state;
|
||||||
char * state_string = NULL;
|
char *state_string;
|
||||||
gboolean success = TRUE;
|
gboolean success = TRUE;
|
||||||
DBusMessage * message = NULL;
|
|
||||||
DBusMessage * reply = NULL;
|
|
||||||
|
|
||||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state")))
|
state = nm_client_get_state (client);
|
||||||
{
|
|
||||||
fprintf (stderr, "get_nm_state(): couldn't create new dbus message.\n");
|
switch (state) {
|
||||||
return FALSE;
|
case NM_STATE_ASLEEP:
|
||||||
|
state_string = "asleep";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NM_STATE_CONNECTING:
|
||||||
|
state_string = "connecting";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NM_STATE_CONNECTED:
|
||||||
|
state_string = "connected";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NM_STATE_DISCONNECTED:
|
||||||
|
state_string = "disconnected";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NM_STATE_UNKNOWN:
|
||||||
|
default:
|
||||||
|
state_string = "unknown";
|
||||||
|
success = FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, NULL);
|
|
||||||
dbus_message_unref (message);
|
|
||||||
if (!reply)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "get_nm_state(): didn't get a reply from NetworkManager.\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &uint32_state, DBUS_TYPE_INVALID))
|
|
||||||
{
|
|
||||||
fprintf (stderr, "get_nm_state(): unexpected reply from NetworkManager.\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ((NMState) uint32_state)
|
|
||||||
{
|
|
||||||
case NM_STATE_ASLEEP:
|
|
||||||
state_string = "asleep";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NM_STATE_CONNECTING:
|
|
||||||
state_string = "connecting";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NM_STATE_CONNECTED:
|
|
||||||
state_string = "connected";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NM_STATE_DISCONNECTED:
|
|
||||||
state_string = "disconnected";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NM_STATE_UNKNOWN:
|
|
||||||
default:
|
|
||||||
state_string = "unknown";
|
|
||||||
success = FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
printf ("State: %s\n\n", state_string);
|
printf ("State: %s\n\n", state_string);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_string (const char *label, const char *data)
|
static void
|
||||||
|
print_string (const char *label, const char *data)
|
||||||
{
|
{
|
||||||
#define SPACING 18
|
#define SPACING 18
|
||||||
int label_len = 0;
|
int label_len = 0;
|
||||||
@@ -110,375 +99,256 @@ static void print_string (const char *label, const char *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void detail_network (DBusConnection *connection, const char *path, const char *active_path)
|
static void
|
||||||
|
detail_network (gpointer data, gpointer user_data)
|
||||||
{
|
{
|
||||||
DBusMessage * message = NULL;
|
NMAccessPoint *ap = NM_ACCESS_POINT (data);
|
||||||
DBusMessage * reply = NULL;
|
const char *active_bssid = (const char *) user_data;
|
||||||
const char * op = NULL;
|
GString *str;
|
||||||
const char * essid = NULL;
|
gboolean active = FALSE;
|
||||||
const char * hw_addr = NULL;
|
guint32 capabilities;
|
||||||
dbus_int32_t strength = -1;
|
char *essid;
|
||||||
double freq = 0;
|
char *tmp;
|
||||||
dbus_int32_t rate = 0;
|
|
||||||
dbus_int32_t capabilities = NM_802_11_CAP_NONE;
|
|
||||||
dbus_uint32_t mode = 0;
|
|
||||||
gboolean broadcast = TRUE;
|
|
||||||
|
|
||||||
g_return_if_fail (connection != NULL);
|
capabilities = nm_access_point_get_capabilities (ap);
|
||||||
g_return_if_fail (path != NULL);
|
|
||||||
|
|
||||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getProperties")))
|
if (active_bssid) {
|
||||||
{
|
char *current_bssid = nm_access_point_get_hw_address (ap);
|
||||||
fprintf (stderr, "detail_network(): couldn't create new dbus message.\n");
|
if (current_bssid && !strcmp (current_bssid, active_bssid))
|
||||||
return;
|
active = TRUE;
|
||||||
|
|
||||||
|
g_free (current_bssid);
|
||||||
}
|
}
|
||||||
|
|
||||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, NULL);
|
str = g_string_new (NULL);
|
||||||
dbus_message_unref (message);
|
g_string_append_printf (str,
|
||||||
if (!reply)
|
"%s Mode, Freq %.3f MHz, Rate %d Mb/s, Strength %d",
|
||||||
{
|
(nm_access_point_get_mode (ap) == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc",
|
||||||
fprintf (stderr, "detail_network(): didn't get a reply from NetworkManager for device %s.\n", path);
|
nm_access_point_get_frequency (ap) / 1000000000,
|
||||||
return;
|
nm_access_point_get_rate (ap) / 1024,
|
||||||
}
|
nm_access_point_get_strength (ap));
|
||||||
|
|
||||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &op,
|
if (nm_access_point_is_encrypted (ap))
|
||||||
DBUS_TYPE_STRING, &essid,
|
g_string_append (str, ", Encrypted: ");
|
||||||
DBUS_TYPE_STRING, &hw_addr,
|
|
||||||
DBUS_TYPE_INT32, &strength,
|
|
||||||
DBUS_TYPE_DOUBLE, &freq,
|
|
||||||
DBUS_TYPE_INT32, &rate,
|
|
||||||
DBUS_TYPE_INT32, &mode,
|
|
||||||
DBUS_TYPE_INT32, &capabilities,
|
|
||||||
DBUS_TYPE_BOOLEAN, &broadcast,
|
|
||||||
DBUS_TYPE_INVALID))
|
|
||||||
{
|
|
||||||
char *temp = NULL;
|
|
||||||
char *temp_essid = NULL;
|
|
||||||
float flt_freq = freq / 1000000000;
|
|
||||||
gboolean active = (active_path && !strcmp (active_path, path)) ? TRUE : FALSE;
|
|
||||||
GString *enc_string = g_string_new (NULL);
|
|
||||||
|
|
||||||
if (capabilities & NM_802_11_CAP_PROTO_WEP)
|
if (capabilities & NM_802_11_CAP_PROTO_WEP)
|
||||||
enc_string = g_string_append (enc_string, "WEP");
|
g_string_append (str, " WEP");
|
||||||
if (capabilities & NM_802_11_CAP_PROTO_WPA)
|
if (capabilities & NM_802_11_CAP_PROTO_WPA)
|
||||||
{
|
g_string_append (str, " WPA");
|
||||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
if (capabilities & NM_802_11_CAP_PROTO_WPA2)
|
||||||
enc_string = g_string_append_c (enc_string, ' ');
|
g_string_append (str, " WPA2");
|
||||||
enc_string = g_string_append (enc_string, "WPA");
|
if (capabilities & NM_802_11_CAP_KEY_MGMT_802_1X)
|
||||||
}
|
g_string_append (str, " Enterprise");
|
||||||
if (capabilities & NM_802_11_CAP_PROTO_WPA2)
|
|
||||||
{
|
|
||||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
|
||||||
enc_string = g_string_append_c (enc_string, ' ');
|
|
||||||
enc_string = g_string_append (enc_string, "WPA2");
|
|
||||||
}
|
|
||||||
if (capabilities & NM_802_11_CAP_KEY_MGMT_802_1X)
|
|
||||||
{
|
|
||||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
|
||||||
enc_string = g_string_append_c (enc_string, ' ');
|
|
||||||
enc_string = g_string_append (enc_string, "Enterprise");
|
|
||||||
}
|
|
||||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
|
||||||
{
|
|
||||||
enc_string = g_string_prepend (enc_string, ", Encrypted (");
|
|
||||||
enc_string = g_string_append (enc_string, ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = g_strdup_printf ("%s Mode, Freq %.3f MHz, Rate %d Mb/s, Strength %d%%%s%s",
|
/* FIXME: broadcast/hidden */
|
||||||
(mode == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc",
|
|
||||||
flt_freq,
|
essid = nm_access_point_get_essid (ap);
|
||||||
rate / 1024,
|
tmp = g_strdup_printf (" %s%s", active ? "*" : "", essid);
|
||||||
strength,
|
g_free (essid);
|
||||||
(enc_string && strlen (enc_string->str)) ? enc_string->str : "",
|
|
||||||
!broadcast ? ", Hidden" : "");
|
print_string (tmp, str->str);
|
||||||
temp_essid = g_strdup_printf (" %s%s", active ? "*" : "", essid);
|
|
||||||
print_string (temp_essid, temp);
|
g_string_free (str, TRUE);
|
||||||
g_string_free (enc_string, TRUE);
|
g_free (tmp);
|
||||||
g_free (temp_essid);
|
}
|
||||||
g_free (temp);
|
|
||||||
}
|
static gchar *
|
||||||
|
ip4_address_as_string (guint32 ip)
|
||||||
|
{
|
||||||
|
struct in_addr tmp_addr;
|
||||||
|
gchar *ip_string;
|
||||||
|
|
||||||
|
tmp_addr.s_addr = ip;
|
||||||
|
ip_string = inet_ntoa (tmp_addr);
|
||||||
|
|
||||||
|
return g_strdup (ip_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
detail_device (gpointer data, gpointer user_data)
|
||||||
|
{
|
||||||
|
NMDevice *device = NM_DEVICE (data);
|
||||||
|
char *tmp;
|
||||||
|
NMDeviceState state;
|
||||||
|
int caps;
|
||||||
|
int speed;
|
||||||
|
GArray *array;
|
||||||
|
|
||||||
|
state = nm_device_get_state (device);
|
||||||
|
|
||||||
|
tmp = nm_device_get_iface (device);
|
||||||
|
printf ("- Device: %s ----------------------------------------------------------------\n", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
/* General information */
|
||||||
|
if (NM_IS_DEVICE_802_3_ETHERNET (device))
|
||||||
|
print_string ("Type", "Wired");
|
||||||
|
else if (NM_IS_DEVICE_802_11_WIRELESS (device))
|
||||||
|
print_string ("Type", "802.11 Wireless");
|
||||||
|
|
||||||
|
tmp = nm_device_get_driver (device);
|
||||||
|
if (tmp) {
|
||||||
|
print_string ("Driver", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
} else
|
||||||
|
print_string ("Driver", "(unknown)");
|
||||||
|
|
||||||
|
if (state == NM_DEVICE_STATE_ACTIVATED)
|
||||||
|
print_string ("Active", "yes");
|
||||||
else
|
else
|
||||||
fprintf (stderr, "detail_network(): unexpected reply from NetworkManager for device %s.\n", path);
|
print_string ("Active", "no");
|
||||||
|
|
||||||
dbus_message_unref (reply);
|
tmp = NULL;
|
||||||
}
|
if (NM_IS_DEVICE_802_3_ETHERNET (device))
|
||||||
|
tmp = nm_device_802_3_ethernet_get_hw_address (NM_DEVICE_802_3_ETHERNET (device));
|
||||||
|
else if (NM_IS_DEVICE_802_11_WIRELESS (device))
|
||||||
|
tmp = nm_device_802_11_wireless_get_hw_address (NM_DEVICE_802_11_WIRELESS (device));
|
||||||
|
|
||||||
|
if (tmp) {
|
||||||
static char *
|
print_string ("HW Address", tmp);
|
||||||
get_driver_name (DBusConnection *connection, const char *path)
|
g_free (tmp);
|
||||||
{
|
|
||||||
DBusMessage * message;
|
|
||||||
DBusMessage * reply;
|
|
||||||
char * driver = NULL;
|
|
||||||
DBusError error;
|
|
||||||
|
|
||||||
g_return_val_if_fail (path != NULL, NULL);
|
|
||||||
|
|
||||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getDriver")))
|
|
||||||
{
|
|
||||||
nm_warning ("%s(): Couldn't allocate the dbus message", __func__);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_error_init (&error);
|
/* Capabilities */
|
||||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
caps = nm_device_get_capabilities (device);
|
||||||
dbus_message_unref (message);
|
printf ("\n Capabilities:\n");
|
||||||
if (dbus_error_is_set (&error))
|
if (caps & NM_DEVICE_CAP_NM_SUPPORTED)
|
||||||
dbus_error_free (&error);
|
print_string (" Supported", "yes");
|
||||||
else if (reply)
|
|
||||||
{
|
|
||||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &driver, DBUS_TYPE_INVALID))
|
|
||||||
driver = g_strdup (driver);
|
|
||||||
dbus_message_unref (reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
return driver;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void detail_device (DBusConnection *connection, const char *path)
|
|
||||||
{
|
|
||||||
DBusMessage * message = NULL;
|
|
||||||
DBusMessage * reply = NULL;
|
|
||||||
char * op = NULL;
|
|
||||||
const char * iface = NULL;
|
|
||||||
dbus_uint32_t type = 0;
|
|
||||||
const char * udi = NULL;
|
|
||||||
dbus_bool_t active = FALSE;
|
|
||||||
const char * ip4_address = NULL;
|
|
||||||
const char * broadcast = NULL;
|
|
||||||
const char * subnetmask = NULL;
|
|
||||||
const char * hw_addr = NULL;
|
|
||||||
const char * route = NULL;
|
|
||||||
const char * primary_dns = NULL;
|
|
||||||
const char * secondary_dns = NULL;
|
|
||||||
dbus_uint32_t mode = 0;
|
|
||||||
dbus_int32_t strength = -1;
|
|
||||||
char * active_network_path = NULL;
|
|
||||||
dbus_bool_t link_active = FALSE;
|
|
||||||
dbus_int32_t speed = 0;
|
|
||||||
dbus_uint32_t caps = NM_DEVICE_CAP_NONE;
|
|
||||||
dbus_uint32_t type_caps = NM_DEVICE_CAP_NONE;
|
|
||||||
char ** networks = NULL;
|
|
||||||
int num_networks = 0;
|
|
||||||
NMActStage act_stage = NM_ACT_STAGE_UNKNOWN;
|
|
||||||
|
|
||||||
g_return_if_fail (connection != NULL);
|
|
||||||
g_return_if_fail (path != NULL);
|
|
||||||
|
|
||||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getProperties")))
|
|
||||||
{
|
|
||||||
fprintf (stderr, "detail_device(): couldn't create new dbus message.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, NULL);
|
|
||||||
dbus_message_unref (message);
|
|
||||||
if (!reply)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "detail_device(): didn't get a reply from NetworkManager for device %s.\n", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &op,
|
|
||||||
DBUS_TYPE_STRING, &iface,
|
|
||||||
DBUS_TYPE_UINT32, &type,
|
|
||||||
DBUS_TYPE_STRING, &udi,
|
|
||||||
DBUS_TYPE_BOOLEAN,&active,
|
|
||||||
DBUS_TYPE_UINT32, &act_stage,
|
|
||||||
DBUS_TYPE_STRING, &ip4_address,
|
|
||||||
DBUS_TYPE_STRING, &subnetmask,
|
|
||||||
DBUS_TYPE_STRING, &broadcast,
|
|
||||||
DBUS_TYPE_STRING, &hw_addr,
|
|
||||||
DBUS_TYPE_STRING, &route,
|
|
||||||
DBUS_TYPE_STRING, &primary_dns,
|
|
||||||
DBUS_TYPE_STRING, &secondary_dns,
|
|
||||||
DBUS_TYPE_INT32, &mode,
|
|
||||||
DBUS_TYPE_INT32, &strength,
|
|
||||||
DBUS_TYPE_BOOLEAN,&link_active,
|
|
||||||
DBUS_TYPE_INT32, &speed,
|
|
||||||
DBUS_TYPE_UINT32, &caps,
|
|
||||||
DBUS_TYPE_UINT32, &type_caps,
|
|
||||||
DBUS_TYPE_STRING, &active_network_path,
|
|
||||||
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &networks, &num_networks,
|
|
||||||
DBUS_TYPE_INVALID))
|
|
||||||
{
|
|
||||||
char * driver;
|
|
||||||
|
|
||||||
printf ("- Device: %s ----------------------------------------------------------------\n", iface);
|
|
||||||
|
|
||||||
/* General information */
|
|
||||||
print_string ("NM Path", op);
|
|
||||||
if (type == DEVICE_TYPE_802_11_WIRELESS)
|
|
||||||
print_string ("Type", "802.11 Wireless");
|
|
||||||
else if (type == DEVICE_TYPE_802_3_ETHERNET)
|
|
||||||
print_string ("Type", "Wired");
|
|
||||||
|
|
||||||
if ((driver = get_driver_name (connection, path)))
|
|
||||||
print_string ("Driver", driver);
|
|
||||||
else
|
|
||||||
print_string ("Driver", "(unknown)");
|
|
||||||
|
|
||||||
if (active)
|
|
||||||
print_string ("Active", "yes");
|
|
||||||
else
|
|
||||||
print_string ("Active", "no");
|
|
||||||
|
|
||||||
print_string ("HW Address", hw_addr);
|
|
||||||
|
|
||||||
/* Capabilities */
|
|
||||||
printf ("\n Capabilities:\n");
|
|
||||||
if (caps & NM_DEVICE_CAP_NM_SUPPORTED)
|
|
||||||
print_string (" Supported", "yes");
|
|
||||||
else
|
|
||||||
print_string (" Supported", "no");
|
|
||||||
if (caps & NM_DEVICE_CAP_CARRIER_DETECT)
|
|
||||||
print_string (" Carrier Detect", "yes");
|
|
||||||
|
|
||||||
if (speed)
|
|
||||||
{
|
|
||||||
char *speed_string;
|
|
||||||
|
|
||||||
speed_string = g_strdup_printf ("%d Mb/s", speed);
|
|
||||||
print_string (" Speed", speed_string);
|
|
||||||
g_free (speed_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wireless specific information */
|
|
||||||
if (type == DEVICE_TYPE_802_11_WIRELESS)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf ("\n Wireless Settings\n");
|
|
||||||
|
|
||||||
if (caps & NM_DEVICE_CAP_WIRELESS_SCAN)
|
|
||||||
print_string (" Scanning", "yes");
|
|
||||||
|
|
||||||
if (type_caps & NM_802_11_CAP_PROTO_WEP)
|
|
||||||
print_string (" WEP Encryption", "yes");
|
|
||||||
if (type_caps & NM_802_11_CAP_PROTO_WPA)
|
|
||||||
print_string (" WPA Encryption", "yes");
|
|
||||||
if (type_caps & NM_802_11_CAP_PROTO_WPA2)
|
|
||||||
print_string (" WPA2 Encryption", "yes");
|
|
||||||
|
|
||||||
/*
|
|
||||||
printf ("\n Wireless Settings\n");
|
|
||||||
if (mode == IW_MODE_INFRA)
|
|
||||||
print_string (" Mode", "Infrastructure");
|
|
||||||
else if (mode == IW_MODE_ADHOC)
|
|
||||||
print_string (" Mode", "Ad-Hoc");
|
|
||||||
str_strength = g_strdup_printf ("%d%%", strength);
|
|
||||||
print_string (" Strength", str_strength);
|
|
||||||
g_free (str_strength);
|
|
||||||
*/
|
|
||||||
|
|
||||||
printf ("\n Wireless Networks (* = Current Network)\n");
|
|
||||||
for (i = 0; i < num_networks; i++)
|
|
||||||
detail_network (connection, networks[i], active_network_path);
|
|
||||||
}
|
|
||||||
else if (type == DEVICE_TYPE_802_3_ETHERNET)
|
|
||||||
{
|
|
||||||
printf ("\n Wired Settings\n");
|
|
||||||
if (link_active)
|
|
||||||
print_string (" Hardware Link", "yes");
|
|
||||||
else
|
|
||||||
print_string (" Hardware Link", "no");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* IP Setup info */
|
|
||||||
if (active)
|
|
||||||
{
|
|
||||||
printf ("\n IP Settings:\n");
|
|
||||||
print_string (" IP Address", ip4_address);
|
|
||||||
print_string (" Subnet Mask", subnetmask);
|
|
||||||
print_string (" Broadcast", broadcast);
|
|
||||||
print_string (" Gateway", route);
|
|
||||||
print_string (" Primary DNS", primary_dns);
|
|
||||||
print_string (" Secondary DNS", secondary_dns);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
printf ("\n\n");
|
|
||||||
dbus_free_string_array (networks);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
fprintf (stderr, "detail_device(): unexpected reply from NetworkManager for device %s.\n", path);
|
print_string (" Supported", "no");
|
||||||
|
if (caps & NM_DEVICE_CAP_CARRIER_DETECT)
|
||||||
|
print_string (" Carrier Detect", "yes");
|
||||||
|
|
||||||
dbus_message_unref (reply);
|
speed = 0;
|
||||||
}
|
if (NM_IS_DEVICE_802_3_ETHERNET (device))
|
||||||
|
speed = nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (device));
|
||||||
|
else if (NM_IS_DEVICE_802_11_WIRELESS (device))
|
||||||
|
speed = nm_device_802_11_wireless_get_bitrate (NM_DEVICE_802_11_WIRELESS (device));
|
||||||
|
|
||||||
|
if (speed) {
|
||||||
|
char *speed_string;
|
||||||
|
|
||||||
static void print_devices (DBusConnection *connection)
|
speed_string = g_strdup_printf ("%d Mb/s", speed);
|
||||||
{
|
print_string (" Speed", speed_string);
|
||||||
DBusMessage * message = NULL;
|
g_free (speed_string);
|
||||||
DBusMessage * reply = NULL;
|
|
||||||
DBusError error;
|
|
||||||
char ** paths = NULL;
|
|
||||||
int num = -1;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices")))
|
|
||||||
{
|
|
||||||
fprintf (stderr, "print_devices(): couldn't create new dbus message.\n");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_error_init (&error);
|
/* Wireless specific information */
|
||||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
if ((NM_IS_DEVICE_802_11_WIRELESS (device))) {
|
||||||
dbus_message_unref (message);
|
guint32 wireless_caps;
|
||||||
if (!reply)
|
NMAccessPoint *active_ap;
|
||||||
{
|
char *active_bssid;
|
||||||
fprintf (stderr, "print_devices(): didn't get a reply from NetworkManager.\n");
|
GSList *networks;
|
||||||
if (dbus_error_is_set (&error))
|
|
||||||
{
|
printf ("\n Wireless Settings\n");
|
||||||
if (dbus_error_has_name (&error, NM_DBUS_NO_DEVICES_ERROR))
|
|
||||||
fprintf (stderr, "There are no available network devices.\n");
|
if (caps & NM_DEVICE_CAP_WIRELESS_SCAN)
|
||||||
}
|
print_string (" Scanning", "yes");
|
||||||
|
|
||||||
|
wireless_caps = nm_device_802_11_wireless_get_capabilities (NM_DEVICE_802_11_WIRELESS (device));
|
||||||
|
|
||||||
|
if (wireless_caps & NM_802_11_CAP_PROTO_WEP)
|
||||||
|
print_string (" WEP Encryption", "yes");
|
||||||
|
if (wireless_caps & NM_802_11_CAP_PROTO_WPA)
|
||||||
|
print_string (" WPA Encryption", "yes");
|
||||||
|
if (wireless_caps & NM_802_11_CAP_PROTO_WPA2)
|
||||||
|
print_string (" WPA2 Encryption", "yes");
|
||||||
|
|
||||||
|
active_ap = nm_device_802_11_wireless_get_active_network (NM_DEVICE_802_11_WIRELESS (device));
|
||||||
|
active_bssid = active_ap ? nm_access_point_get_hw_address (active_ap) : NULL;
|
||||||
|
|
||||||
|
printf ("\n Wireless Networks%s\n", active_ap ? "(* = Current Network)" : "");
|
||||||
|
|
||||||
|
networks = nm_device_802_11_wireless_get_networks (NM_DEVICE_802_11_WIRELESS (device));
|
||||||
|
g_slist_foreach (networks, detail_network, active_bssid);
|
||||||
|
g_free (active_bssid);
|
||||||
|
g_slist_free (networks);
|
||||||
|
} else if (NM_IS_DEVICE_802_3_ETHERNET (device)) {
|
||||||
|
printf ("\n Wired Settings\n");
|
||||||
|
/* FIXME */
|
||||||
|
#if 0
|
||||||
|
if (link_active)
|
||||||
|
print_string (" Hardware Link", "yes");
|
||||||
else
|
else
|
||||||
fprintf (stderr, "print_devices(): NetworkManager returned an error: '%s'\n", error.message);
|
print_string (" Hardware Link", "no");
|
||||||
return;
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID))
|
/* IP Setup info */
|
||||||
{
|
if (state == NM_DEVICE_STATE_ACTIVATED) {
|
||||||
fprintf (stderr, "print_devices(): unexpected reply from NetworkManager.\n");
|
NMIP4Config *cfg = nm_device_get_ip4_config (device);
|
||||||
dbus_message_unref (reply);
|
|
||||||
return;
|
printf ("\n IP Settings:\n");
|
||||||
|
|
||||||
|
tmp = ip4_address_as_string (nm_ip4_config_get_address (cfg));
|
||||||
|
print_string (" IP Address", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
tmp = ip4_address_as_string (nm_ip4_config_get_netmask (cfg));
|
||||||
|
print_string (" Subnet Mask", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
tmp = ip4_address_as_string (nm_ip4_config_get_broadcast (cfg));
|
||||||
|
print_string (" Broadcast", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
tmp = ip4_address_as_string (nm_ip4_config_get_gateway (cfg));
|
||||||
|
print_string (" Gateway", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
|
||||||
|
array = nm_ip4_config_get_nameservers (cfg);
|
||||||
|
if (array) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < array->len; i++) {
|
||||||
|
tmp = ip4_address_as_string (g_array_index (array, guint32, i));
|
||||||
|
print_string (" DNS", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_array_free (array, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num; i++)
|
printf ("\n\n");
|
||||||
detail_device (connection, paths[i]);
|
|
||||||
|
|
||||||
dbus_free_string_array (paths);
|
|
||||||
dbus_message_unref (reply);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
static void
|
||||||
|
print_devices (NMClient *client)
|
||||||
{
|
{
|
||||||
DBusConnection *connection;
|
GSList *devices;
|
||||||
DBusError error;
|
|
||||||
|
devices = nm_client_get_devices (client);
|
||||||
|
g_slist_foreach (devices, detail_device, NULL);
|
||||||
|
g_slist_free (devices);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
NMClient *client;
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
dbus_error_init (&error);
|
client = nm_client_new ();
|
||||||
connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
|
if (!client) {
|
||||||
if (connection == NULL)
|
exit (1);
|
||||||
{
|
|
||||||
fprintf (stderr, "Error connecting to system bus: %s\n", error.message);
|
|
||||||
dbus_error_free (&error);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("\nNetworkManager Tool\n\n");
|
printf ("\nNetworkManager Tool\n\n");
|
||||||
|
|
||||||
if (!get_nm_state (connection))
|
if (!get_nm_state (client)) {
|
||||||
{
|
|
||||||
fprintf (stderr, "\n\nNetworkManager appears not to be running (could not get its state).\n");
|
fprintf (stderr, "\n\nNetworkManager appears not to be running (could not get its state).\n");
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_devices (connection);
|
print_devices (client);
|
||||||
|
|
||||||
|
g_object_unref (client);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user