diff options
author | Tambet Ingo <tambet@ximian.com> | 2007-03-05 08:49:30 +0000 |
---|---|---|
committer | Tambet Ingo <tambet@gmail.com> | 2007-03-05 08:49:30 +0000 |
commit | 96c246cfc4838d4d746a2add5e36c48654392649 (patch) | |
tree | e5e18506d819411f509a25a3cad1b1c878a9ea4a /test | |
parent | bf6efcaeee4f5b968e5fa48ca84761ce47e15deb (diff) | |
download | NetworkManager-96c246cfc4838d4d746a2add5e36c48654392649.tar.gz |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 3 | ||||
-rw-r--r-- | test/nm-tool.c | 610 |
2 files changed, 242 insertions, 371 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index f0024c4a22..8d3402abe3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,7 @@ SUBDIRS=test-common libnm-util INCLUDES = -I${top_srcdir} \ + -I${top_srcdir}/libnm-glib \ -I${top_srcdir}/gnome/libnm_glib \ -I${top_srcdir}/utils \ -I${top_srcdir}/include @@ -23,7 +24,7 @@ noinst_PROGRAMS = nm-tool \ nm_tool_SOURCES = nm-tool.c 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_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \ diff --git a/test/nm-tool.c b/test/nm-tool.c index bf60351a58..daca46cb30 100644 --- a/test/nm-tool.c +++ b/test/nm-tool.c @@ -28,68 +28,57 @@ #include <iwlib.h> -#include "NetworkManager.h" -#include "nm-utils.h" +#include <sys/socket.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) -{ - dbus_uint32_t uint32_state; - char * state_string = NULL; - 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"))) - { - fprintf (stderr, "get_nm_state(): couldn't create new dbus message.\n"); - return FALSE; - } - 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; +static gboolean +get_nm_state (NMClient *client) +{ + NMState state; + char *state_string; + gboolean success = TRUE; + + state = nm_client_get_state (client); + + switch (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; } - 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); 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 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; - DBusMessage * reply = NULL; - const char * op = NULL; - const char * essid = NULL; - const char * hw_addr = NULL; - dbus_int32_t strength = -1; - double freq = 0; - 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); - 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_network(): couldn't create new dbus message.\n"); - return; + NMAccessPoint *ap = NM_ACCESS_POINT (data); + const char *active_bssid = (const char *) user_data; + GString *str; + gboolean active = FALSE; + guint32 capabilities; + char *essid; + char *tmp; + + capabilities = nm_access_point_get_capabilities (ap); + + if (active_bssid) { + char *current_bssid = nm_access_point_get_hw_address (ap); + if (current_bssid && !strcmp (current_bssid, active_bssid)) + active = TRUE; + + g_free (current_bssid); } - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, NULL); - dbus_message_unref (message); - if (!reply) - { - fprintf (stderr, "detail_network(): didn't get a reply from NetworkManager for device %s.\n", path); - return; - } + str = g_string_new (NULL); + g_string_append_printf (str, + "%s Mode, Freq %.3f MHz, Rate %d Mb/s, Strength %d", + (nm_access_point_get_mode (ap) == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc", + nm_access_point_get_frequency (ap) / 1000000000, + 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, - DBUS_TYPE_STRING, &essid, - 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) - enc_string = g_string_append (enc_string, "WEP"); - if (capabilities & NM_802_11_CAP_PROTO_WPA) - { - if (enc_string->str && (strlen (enc_string->str) > 0)) - enc_string = g_string_append_c (enc_string, ' '); - enc_string = g_string_append (enc_string, "WPA"); - } - 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, ")"); - } + if (nm_access_point_is_encrypted (ap)) + g_string_append (str, ", Encrypted: "); - temp = g_strdup_printf ("%s Mode, Freq %.3f MHz, Rate %d Mb/s, Strength %d%%%s%s", - (mode == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc", - flt_freq, - rate / 1024, - strength, - (enc_string && strlen (enc_string->str)) ? enc_string->str : "", - !broadcast ? ", Hidden" : ""); - temp_essid = g_strdup_printf (" %s%s", active ? "*" : "", essid); - print_string (temp_essid, temp); - g_string_free (enc_string, TRUE); - g_free (temp_essid); - g_free (temp); - } - else - fprintf (stderr, "detail_network(): unexpected reply from NetworkManager for device %s.\n", path); + if (capabilities & NM_802_11_CAP_PROTO_WEP) + g_string_append (str, " WEP"); + if (capabilities & NM_802_11_CAP_PROTO_WPA) + g_string_append (str, " WPA"); + if (capabilities & NM_802_11_CAP_PROTO_WPA2) + g_string_append (str, " WPA2"); + if (capabilities & NM_802_11_CAP_KEY_MGMT_802_1X) + g_string_append (str, " Enterprise"); - dbus_message_unref (reply); -} + /* FIXME: broadcast/hidden */ + essid = nm_access_point_get_essid (ap); + tmp = g_strdup_printf (" %s%s", active ? "*" : "", essid); + g_free (essid); -static char * -get_driver_name (DBusConnection *connection, const char *path) -{ - DBusMessage * message; - DBusMessage * reply; - char * driver = NULL; - DBusError error; + print_string (tmp, str->str); - g_return_val_if_fail (path != NULL, NULL); + g_string_free (str, TRUE); + g_free (tmp); +} - 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; - } +static gchar * +ip4_address_as_string (guint32 ip) +{ + struct in_addr tmp_addr; + gchar *ip_string; - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - dbus_message_unref (message); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - 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); - } + tmp_addr.s_addr = ip; + ip_string = inet_ntoa (tmp_addr); - return driver; + return g_strdup (ip_string); } - -static void detail_device (DBusConnection *connection, const char *path) +static void +detail_device (gpointer data, gpointer user_data) { - 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; + 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 + print_string ("Active", "no"); + + 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) { + print_string ("HW Address", tmp); + g_free (tmp); } - 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; + /* Capabilities */ + caps = nm_device_get_capabilities (device); + 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"); + + 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; + + speed_string = g_strdup_printf ("%d Mb/s", speed); + print_string (" Speed", speed_string); + g_free (speed_string); } - 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"); + /* Wireless specific information */ + if ((NM_IS_DEVICE_802_11_WIRELESS (device))) { + guint32 wireless_caps; + NMAccessPoint *active_ap; + char *active_bssid; + GSList *networks; + + printf ("\n Wireless Settings\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 - print_string ("Active", "no"); + print_string (" Hardware Link", "no"); +#endif + } - print_string ("HW Address", hw_addr); + /* IP Setup info */ + if (state == NM_DEVICE_STATE_ACTIVATED) { + NMIP4Config *cfg = nm_device_get_ip4_config (device); - /* 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"); + printf ("\n IP Settings:\n"); - if (speed) - { - char *speed_string; + tmp = ip4_address_as_string (nm_ip4_config_get_address (cfg)); + print_string (" IP Address", tmp); + g_free (tmp); - speed_string = g_strdup_printf ("%d Mb/s", speed); - print_string (" Speed", speed_string); - g_free (speed_string); - } + tmp = ip4_address_as_string (nm_ip4_config_get_netmask (cfg)); + print_string (" Subnet Mask", tmp); + g_free (tmp); - /* 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"); - } + tmp = ip4_address_as_string (nm_ip4_config_get_broadcast (cfg)); + print_string (" Broadcast", tmp); + g_free (tmp); - /* 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); - } - + tmp = ip4_address_as_string (nm_ip4_config_get_gateway (cfg)); + print_string (" Gateway", tmp); + g_free (tmp); - printf ("\n\n"); - dbus_free_string_array (networks); - } - else - fprintf (stderr, "detail_device(): unexpected reply from NetworkManager for device %s.\n", path); + array = nm_ip4_config_get_nameservers (cfg); + if (array) { + int i; - dbus_message_unref (reply); -} + 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); + } -static void print_devices (DBusConnection *connection) -{ - DBusMessage * message = NULL; - 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; + g_object_unref (cfg); } - dbus_error_init (&error); - reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error); - dbus_message_unref (message); - if (!reply) - { - fprintf (stderr, "print_devices(): didn't get a reply from NetworkManager.\n"); - if (dbus_error_is_set (&error)) - { - if (dbus_error_has_name (&error, NM_DBUS_NO_DEVICES_ERROR)) - fprintf (stderr, "There are no available network devices.\n"); - } - else - fprintf (stderr, "print_devices(): NetworkManager returned an error: '%s'\n", error.message); - return; - } + printf ("\n\n"); +} - if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID)) - { - fprintf (stderr, "print_devices(): unexpected reply from NetworkManager.\n"); - dbus_message_unref (reply); - return; - } - for (i = 0; i < num; i++) - detail_device (connection, paths[i]); +static void +print_devices (NMClient *client) +{ + GSList *devices; - dbus_free_string_array (paths); - dbus_message_unref (reply); + devices = nm_client_get_devices (client); + g_slist_foreach (devices, detail_device, NULL); + g_slist_free (devices); } -int main( int argc, char *argv[] ) +int +main (int argc, char *argv[]) { - DBusConnection *connection; - DBusError error; + NMClient *client; g_type_init (); - dbus_error_init (&error); - connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - if (connection == NULL) - { - fprintf (stderr, "Error connecting to system bus: %s\n", error.message); - dbus_error_free (&error); - return 1; + client = nm_client_new (); + if (!client) { + exit (1); } 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"); exit (1); } - print_devices (connection); + print_devices (client); + + g_object_unref (client); return 0; } |