summaryrefslogtreecommitdiff
path: root/libnm-glib/libnm-glib-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-glib/libnm-glib-test.c')
-rw-r--r--libnm-glib/libnm-glib-test.c173
1 files changed, 154 insertions, 19 deletions
diff --git a/libnm-glib/libnm-glib-test.c b/libnm-glib/libnm-glib-test.c
index a03b3a2060..b3c67c7cbd 100644
--- a/libnm-glib/libnm-glib-test.c
+++ b/libnm-glib/libnm-glib-test.c
@@ -1,4 +1,9 @@
#include <stdlib.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"
@@ -33,12 +38,150 @@ test_get_state (NMClient *client)
return TRUE;
}
+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
+dump_ip4_config (NMIP4Config *cfg)
+{
+ char *tmp;
+ GArray *array;
+ char **ptr_array;
+ int i;
+
+ tmp = ip4_address_as_string (nm_ip4_config_get_address (cfg));
+ g_print ("IP4 address: %s\n", tmp);
+ g_free (tmp);
+
+ tmp = ip4_address_as_string (nm_ip4_config_get_gateway (cfg));
+ g_print ("IP4 gateway: %s\n", tmp);
+ g_free (tmp);
+
+ tmp = ip4_address_as_string (nm_ip4_config_get_netmask (cfg));
+ g_print ("IP4 netmask: %s\n", tmp);
+ g_free (tmp);
+
+ tmp = ip4_address_as_string (nm_ip4_config_get_broadcast (cfg));
+ g_print ("IP4 broadcast: %s\n", tmp);
+ g_free (tmp);
+
+ tmp = nm_ip4_config_get_hostname (cfg);
+ g_print ("IP4 hostname: %s\n", tmp);
+ g_free (tmp);
+
+ array = nm_ip4_config_get_nameservers (cfg);
+ if (array) {
+ g_print ("IP4 DNS:\n");
+ for (i = 0; i < array->len; i++) {
+ tmp = ip4_address_as_string (g_array_index (array, guint32, i));
+ g_print ("\t%s\n", tmp);
+ g_free (tmp);
+ }
+
+ g_array_free (array, TRUE);
+ }
+
+ ptr_array = nm_ip4_config_get_domains (cfg);
+ if (ptr_array) {
+ g_print ("IP4 domains:\n");
+ for (i = 0; ptr_array[i]; i++) {
+ g_print ("\t%s\n", ptr_array[i]);
+ }
+
+ g_strfreev (ptr_array);
+ }
+
+ tmp = nm_ip4_config_get_nis_domain (cfg);
+ g_print ("IP4 NIS domain: %s\n", tmp);
+ g_free (tmp);
+
+ array = nm_ip4_config_get_nis_servers (cfg);
+ if (array) {
+ g_print ("IP4 NIS servers:\n");
+ for (i = 0; i < array->len; i++) {
+ tmp = ip4_address_as_string (g_array_index (array, guint32, i));
+ g_print ("\t%s\n", tmp);
+ g_free (tmp);
+ }
+
+ g_array_free (array, TRUE);
+ }
+}
+
+static void
+dump_wireless (NMDevice80211Wireless *device)
+{
+ char *str;
+ GSList *iter;
+ GSList *networks;
+
+ g_print ("Mode: %d\n", nm_device_802_11_wireless_get_mode (device));
+ g_print ("Bitrate: %d\n", nm_device_802_11_wireless_get_bitrate (device));
+
+ str = nm_device_802_11_wireless_get_hw_address (device);
+ g_print ("MAC: %s\n", str);
+ g_free (str);
+
+ g_print ("Networks:\n");
+ networks = nm_device_802_11_wireless_get_networks (device);
+ for (iter = networks; iter; iter = iter->next) {
+ NMAccessPoint *ap = NM_ACCESS_POINT (iter->data);
+
+ str = nm_access_point_get_essid (ap);
+ g_print ("\tEssid: %s\n", str);
+ g_free (str);
+
+ /* This is not provided by NM yet */
+#if 0
+ str = nm_access_point_get_address (ap);
+ g_print ("\tAddress: %s\n", str);
+ g_free (str);
+
+ str = nm_access_point_get_hw_address (ap);
+ g_print ("\tMAC Address: %s\n", str);
+ g_free (str);
+#endif
+
+ g_print ("\tCapabilities: %d\n", nm_access_point_get_capabilities (ap));
+ g_print ("\tEncrypted: %d\n", nm_access_point_is_encrypted (ap));
+ g_print ("\tFrequency: %f\n", nm_access_point_get_frequency (ap));
+
+ g_print ("\tMode: %d\n", nm_access_point_get_mode (ap));
+ g_print ("\tRate: %d\n", nm_access_point_get_rate (ap));
+ g_print ("\tStrength: %d\n", nm_access_point_get_strength (ap));
+
+ g_print ("\n");
+ }
+
+ g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (networks);
+}
+
+static void
+dump_wired (NMDevice8023Ethernet *device)
+{
+ char *str;
+
+ g_print ("Speed: %d\n", nm_device_802_3_ethernet_get_speed (device));
+
+ str = nm_device_802_3_ethernet_get_hw_address (device);
+ g_print ("MAC: %s\n", str);
+ g_free (str);
+}
static void
dump_device (NMDevice *device)
{
char *str;
- gboolean b;
guint32 u;
NMDeviceState state;
@@ -60,24 +203,16 @@ dump_device (NMDevice *device)
state = nm_device_get_state (device);
g_print ("State: %d\n", state);
- if (NM_IS_DEVICE_802_3_ETHERNET (device)) {
- int speed = nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (device));
- g_print ("Speed: %d\n", speed);
- } else if (NM_IS_DEVICE_802_11_WIRELESS (device)) {
- GSList *iter;
- GSList *networks = nm_device_802_11_wireless_get_networks (NM_DEVICE_802_11_WIRELESS (device));
-
- g_print ("Networks:\n");
- for (iter = networks; iter; iter = iter->next) {
- NMAccessPoint *ap = NM_ACCESS_POINT (iter->data);
-
- str = nm_access_point_get_essid (ap);
- g_print ("\tEssid: %s\n", str);
- g_free (str);
- }
- g_slist_foreach (networks, (GFunc) g_object_unref, NULL);
- g_slist_free (networks);
+ if (state == NM_DEVICE_STATE_ACTIVATED) {
+ NMIP4Config *cfg = nm_device_get_ip4_config (device);
+ dump_ip4_config (cfg);
+ g_object_unref (cfg);
}
+
+ if (NM_IS_DEVICE_802_3_ETHERNET (device))
+ dump_wired (NM_DEVICE_802_3_ETHERNET (device));
+ else if (NM_IS_DEVICE_802_11_WIRELESS (device))
+ dump_wireless (NM_DEVICE_802_11_WIRELESS (device));
}
static gboolean
@@ -181,7 +316,7 @@ main (int argc, char *argv[])
exit (1);
}
- test_wireless_enabled (client);
+/* test_wireless_enabled (client); */
test_get_state (client);
test_devices (client);