NetworkManager/libnm-glib/libnm-glib-test.c

320 lines
6.9 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <iwlib.h>
#include <wireless.h>
#include "nm-client.h"
#include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
2007-10-09 Tambet Ingo <tambet@gmail.com> * src/NetworkManagerUtils.c (nm_utils_is_empty_ssid): (nm_utils_escape_ssid): (nm_utils_same_ssid): Remove. These functions are copied and pasted in a lot of places, so they belong to libnm-utils instead. Now with 100% less compiler warnings: * libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove, * unused. (nm_dbus_unescape_object_path): Ditto. (nm_utils_ssid_to_utf8): Ditto. (nm_utils_is_empty_ssid): Move here from src/NetworkManagerUtils.c (nm_utils_escape_ssid): Ditto. (nm_utils_same_ssid): Ditto. * src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r. (add_one_connection_element): Remove an unused variable. (impl_manager_get_active_connections): Ditto. * src/NetworkManagerPolicy.c (get_device_connection): Remove an * unused variable. * src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove * a leftover from the previous commit. * src/nm-device-802-11-wireless.c (set_current_ap): Remove * unused variable. (real_act_stage1_prepare): Ditto. (activation_success_handler): Ditto. (get_property): Ditto. * src/nm-device-802-3-ethernet.c (real_get_best_connection): * Remove unused variable. * src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check * for 'ifname', it's always set. * src/supplicant-manager/nm-supplicant-config.c (nm_supplicant_config_add_setting_wireless): Cast the GByteArray's 'guint8 *' to expected "char *". (nm_supplicant_config_add_setting_wireless): Ditto. (nm_supplicant_config_remove_option): Remove, not used. * libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is * a guint32, not double. (test_wireless_enabled): Ifdef out unused function. (device_deactivate): Ditto. (device_state_changed): Ditto. (nm_utils_is_empty_ssid): Remove, it's now in libnm-utils. (nm_utils_escape_ssid): Ditto. * test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in * libnm-utils. (nm_utils_is_empty_ssid): Ditto. * libnm-glib/nm-client.c * (nm_client_free_active_connection_element): Remove unused variable. * libnm-util/nm-setting.c (setting_wireless_destroy): Remove * unused variable. (setting_vpn_properties_update_secrets): Ditto. (int_to_gvalue): Ifdef out for now, not used. (byte_to_gvalue): Ditto. * libnm-util/dbus-dict-helpers.c * (_nmu_dbus_add_dict_entry_string_array): Unused, remove. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-09 08:57:35 +00:00
#include "nm-utils.h"
2007-10-09 Tambet Ingo <tambet@gmail.com> * src/NetworkManagerUtils.c (nm_utils_is_empty_ssid): (nm_utils_escape_ssid): (nm_utils_same_ssid): Remove. These functions are copied and pasted in a lot of places, so they belong to libnm-utils instead. Now with 100% less compiler warnings: * libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove, * unused. (nm_dbus_unescape_object_path): Ditto. (nm_utils_ssid_to_utf8): Ditto. (nm_utils_is_empty_ssid): Move here from src/NetworkManagerUtils.c (nm_utils_escape_ssid): Ditto. (nm_utils_same_ssid): Ditto. * src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r. (add_one_connection_element): Remove an unused variable. (impl_manager_get_active_connections): Ditto. * src/NetworkManagerPolicy.c (get_device_connection): Remove an * unused variable. * src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove * a leftover from the previous commit. * src/nm-device-802-11-wireless.c (set_current_ap): Remove * unused variable. (real_act_stage1_prepare): Ditto. (activation_success_handler): Ditto. (get_property): Ditto. * src/nm-device-802-3-ethernet.c (real_get_best_connection): * Remove unused variable. * src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check * for 'ifname', it's always set. * src/supplicant-manager/nm-supplicant-config.c (nm_supplicant_config_add_setting_wireless): Cast the GByteArray's 'guint8 *' to expected "char *". (nm_supplicant_config_add_setting_wireless): Ditto. (nm_supplicant_config_remove_option): Remove, not used. * libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is * a guint32, not double. (test_wireless_enabled): Ifdef out unused function. (device_deactivate): Ditto. (device_state_changed): Ditto. (nm_utils_is_empty_ssid): Remove, it's now in libnm-utils. (nm_utils_escape_ssid): Ditto. * test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in * libnm-utils. (nm_utils_is_empty_ssid): Ditto. * libnm-glib/nm-client.c * (nm_client_free_active_connection_element): Remove unused variable. * libnm-util/nm-setting.c (setting_wireless_destroy): Remove * unused variable. (setting_vpn_properties_update_secrets): Ditto. (int_to_gvalue): Ifdef out for now, not used. (byte_to_gvalue): Ditto. * libnm-util/dbus-dict-helpers.c * (_nmu_dbus_add_dict_entry_string_array): Unused, remove. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-09 08:57:35 +00:00
#if 0
static gboolean
test_wireless_enabled (NMClient *client)
{
gboolean wireless;
wireless = nm_client_wireless_get_enabled (client);
g_print ("Wireless enabled? %s\n", wireless ? "yes" : "no");
nm_client_wireless_set_enabled (client, !wireless);
wireless = nm_client_wireless_get_enabled (client);
g_print ("Wireless enabled? %s\n", wireless ? "yes" : "no");
nm_client_wireless_set_enabled (client, !wireless);
return TRUE;
}
2007-10-09 Tambet Ingo <tambet@gmail.com> * src/NetworkManagerUtils.c (nm_utils_is_empty_ssid): (nm_utils_escape_ssid): (nm_utils_same_ssid): Remove. These functions are copied and pasted in a lot of places, so they belong to libnm-utils instead. Now with 100% less compiler warnings: * libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove, * unused. (nm_dbus_unescape_object_path): Ditto. (nm_utils_ssid_to_utf8): Ditto. (nm_utils_is_empty_ssid): Move here from src/NetworkManagerUtils.c (nm_utils_escape_ssid): Ditto. (nm_utils_same_ssid): Ditto. * src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r. (add_one_connection_element): Remove an unused variable. (impl_manager_get_active_connections): Ditto. * src/NetworkManagerPolicy.c (get_device_connection): Remove an * unused variable. * src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove * a leftover from the previous commit. * src/nm-device-802-11-wireless.c (set_current_ap): Remove * unused variable. (real_act_stage1_prepare): Ditto. (activation_success_handler): Ditto. (get_property): Ditto. * src/nm-device-802-3-ethernet.c (real_get_best_connection): * Remove unused variable. * src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check * for 'ifname', it's always set. * src/supplicant-manager/nm-supplicant-config.c (nm_supplicant_config_add_setting_wireless): Cast the GByteArray's 'guint8 *' to expected "char *". (nm_supplicant_config_add_setting_wireless): Ditto. (nm_supplicant_config_remove_option): Remove, not used. * libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is * a guint32, not double. (test_wireless_enabled): Ifdef out unused function. (device_deactivate): Ditto. (device_state_changed): Ditto. (nm_utils_is_empty_ssid): Remove, it's now in libnm-utils. (nm_utils_escape_ssid): Ditto. * test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in * libnm-utils. (nm_utils_is_empty_ssid): Ditto. * libnm-glib/nm-client.c * (nm_client_free_active_connection_element): Remove unused variable. * libnm-util/nm-setting.c (setting_wireless_destroy): Remove * unused variable. (setting_vpn_properties_update_secrets): Ditto. (int_to_gvalue): Ifdef out for now, not used. (byte_to_gvalue): Ditto. * libnm-util/dbus-dict-helpers.c * (_nmu_dbus_add_dict_entry_string_array): Unused, remove. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-09 08:57:35 +00:00
#endif
static gboolean
test_get_state (NMClient *client)
{
guint state;
state = nm_client_get_state (client);
g_print ("Current state: %d\n", state);
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);
}
}
2007-02-19 Tambet Ingo <tambet@ximian.com> * src/vpn-manager/nm-vpn-manager.c: Handle the DBUS state changes itself. Handle device state changes and disconnect VPN if it's device deactivates. * src/nm-dbus-nm.c: * src/nm-dbus-nm.h: * src/nm-dbus-device.c: * src/nm-dbus-device.c: * src/nm-dbus-net.c: * src/nm-dbus-net.h: Remove. All of it is implemented byt the new dbus API. * src/NetworkManagerMain.h: Get rid of all but 3 properties of NMData. * src/nm-device.c (nm_device_get_by_udi): (nm_device_get_by_iface): Remove. This doesn't belong here and is already implemented in the correct location (NMManager). Rip out all the test_device stuff. * src/NetworkManagerPolicy.c: Remove the leftover activation success and failure handlers, it's all done by NMDevice already. * src/NetworkManager.c: Move the signal handling here from nm-logging.c Remove the iochannel hack to route the unix signals to the main thread since we're not threaded anymore. * src/NetworkManagerAP.c: Implement HWAddress property. * src/NetworkManagerDbus.c: Remove the dbus signal sending code, it happens automatically with dbus-glib. * src/nm-netlink-monitor.c: * src/nm-netlink-monitor.h: - Move it low in the class hierarchy, don't reference any NM types. - Remove private data from the header. - Use type safe checks in public API methods. - Make it a singleton so we don't have to pass the single reference around. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2339 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-02-19 13:09:32 +00:00
static void
dump_access_point (NMAccessPoint *ap)
{
const GByteArray * ssid;
const char * str;
2007-02-19 Tambet Ingo <tambet@ximian.com> * src/vpn-manager/nm-vpn-manager.c: Handle the DBUS state changes itself. Handle device state changes and disconnect VPN if it's device deactivates. * src/nm-dbus-nm.c: * src/nm-dbus-nm.h: * src/nm-dbus-device.c: * src/nm-dbus-device.c: * src/nm-dbus-net.c: * src/nm-dbus-net.h: Remove. All of it is implemented byt the new dbus API. * src/NetworkManagerMain.h: Get rid of all but 3 properties of NMData. * src/nm-device.c (nm_device_get_by_udi): (nm_device_get_by_iface): Remove. This doesn't belong here and is already implemented in the correct location (NMManager). Rip out all the test_device stuff. * src/NetworkManagerPolicy.c: Remove the leftover activation success and failure handlers, it's all done by NMDevice already. * src/NetworkManager.c: Move the signal handling here from nm-logging.c Remove the iochannel hack to route the unix signals to the main thread since we're not threaded anymore. * src/NetworkManagerAP.c: Implement HWAddress property. * src/NetworkManagerDbus.c: Remove the dbus signal sending code, it happens automatically with dbus-glib. * src/nm-netlink-monitor.c: * src/nm-netlink-monitor.h: - Move it low in the class hierarchy, don't reference any NM types. - Remove private data from the header. - Use type safe checks in public API methods. - Make it a singleton so we don't have to pass the single reference around. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2339 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-02-19 13:09:32 +00:00
ssid = nm_access_point_get_ssid (ap);
g_print ("\tSsid: %s\n",
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)");
2007-02-19 Tambet Ingo <tambet@ximian.com> * src/vpn-manager/nm-vpn-manager.c: Handle the DBUS state changes itself. Handle device state changes and disconnect VPN if it's device deactivates. * src/nm-dbus-nm.c: * src/nm-dbus-nm.h: * src/nm-dbus-device.c: * src/nm-dbus-device.c: * src/nm-dbus-net.c: * src/nm-dbus-net.h: Remove. All of it is implemented byt the new dbus API. * src/NetworkManagerMain.h: Get rid of all but 3 properties of NMData. * src/nm-device.c (nm_device_get_by_udi): (nm_device_get_by_iface): Remove. This doesn't belong here and is already implemented in the correct location (NMManager). Rip out all the test_device stuff. * src/NetworkManagerPolicy.c: Remove the leftover activation success and failure handlers, it's all done by NMDevice already. * src/NetworkManager.c: Move the signal handling here from nm-logging.c Remove the iochannel hack to route the unix signals to the main thread since we're not threaded anymore. * src/NetworkManagerAP.c: Implement HWAddress property. * src/NetworkManagerDbus.c: Remove the dbus signal sending code, it happens automatically with dbus-glib. * src/nm-netlink-monitor.c: * src/nm-netlink-monitor.h: - Move it low in the class hierarchy, don't reference any NM types. - Remove private data from the header. - Use type safe checks in public API methods. - Make it a singleton so we don't have to pass the single reference around. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2339 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-02-19 13:09:32 +00:00
str = nm_access_point_get_hw_address (ap);
g_print ("\tMAC Address: %s\n", str);
2007-08-28 Dan Williams <dcbw@redhat.com> Remove NMAPSecurity objects, they are replaced with flags on the APs for each AP's capabilities, and by NMConnection/NMSettings objects for user defined connections. * include/NetworkManager.h - Redefine 802.11 security properties. There are now device capabilities and AP flags and AP security flags. It was way to unclear before. * src/Makefile.am src/nm-ap-security-leap.h src/nm-ap-security-leap.c src/nm-ap-security-wpa-eap.c src/nm-ap-security-wpa-eap.h src/nm-ap-security-private.h src/nm-ap-security-wpa-psk.c src/nm-ap-security-wpa-psk.h src/nm-ap-security-wep.c src/nm-ap-security-wep.h src/nm-ap-security.c src/nm-ap-security.h - Removed, to be replaced with NMConnection/NMSettings objects * src/nm-dbus-nmi.c src/nm-dbus-nmi.h - Removed, to be replaced by code that talks to the new info daemon interface and gets NMConnection/NMSettings objects * src/backends/NetworkManagerSuSE.c - Remove usage of NMAPSecurity; should be replaced by a system-level info-daemon that does the same thing but talks the new info-daemon D-Bus interface * src/NetworkManagerAP.h src/NetworkManagerAP.c src/NetworkManagerAPList.c libnm-glib/libnm-glib-test.c - Remove usage of NMAPSecurity objects and adjust to new flags for WPA/RSN * libnm-glib/nm-access-point.c libnm-glib/nm-access-point.h introspection/nm-access-point.xml test/nm-tool.c - Adjust to new flags for AP security * utils/nm-utils.c utils/nm-utils.h src/vpn-manager/nm-dbus-vpn.c - Remove D-Bus pending call stuff from nm-utils and put it in the VPN stuff which is the only place it's used * src/nm-device-interface.c src/nm-device-interface.h introspection/nm-device.xml src/nm-activation-request.c src/nm-activation-request.h src/nm-device.c - Add a new 'specific_object' argument that hints to NM what actual AP or other device-specific thing the connection should apply to. NMConnection objects can apply to more than one actual device/AP. * libnm-util/nm-connection.c * libnm-util/nm-connection.h - Add 'have_secrets" call stubs * libnm-util/cipher.h - Move NM_AUTH_TYPE_* defines here for now * src/nm-device-802-11-wireless.c - Remove usage of NMAPSecurity, to be replaced with NMConnection/ NMSettings objects * src/NetworkManagerDbus.c * src/NetworkManagerPolicy.c - Remove usage of update_allowed_networks, should be pushing data in a different manner git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2738 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-08-28 14:47:31 +00:00
g_print ("\tFlags: 0x%X\n", nm_access_point_get_flags (ap));
g_print ("\tWPA Flags: 0x%X\n", nm_access_point_get_wpa_flags (ap));
g_print ("\tRSN Flags: 0x%X\n", nm_access_point_get_rsn_flags (ap));
2007-10-09 Tambet Ingo <tambet@gmail.com> * src/NetworkManagerUtils.c (nm_utils_is_empty_ssid): (nm_utils_escape_ssid): (nm_utils_same_ssid): Remove. These functions are copied and pasted in a lot of places, so they belong to libnm-utils instead. Now with 100% less compiler warnings: * libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove, * unused. (nm_dbus_unescape_object_path): Ditto. (nm_utils_ssid_to_utf8): Ditto. (nm_utils_is_empty_ssid): Move here from src/NetworkManagerUtils.c (nm_utils_escape_ssid): Ditto. (nm_utils_same_ssid): Ditto. * src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r. (add_one_connection_element): Remove an unused variable. (impl_manager_get_active_connections): Ditto. * src/NetworkManagerPolicy.c (get_device_connection): Remove an * unused variable. * src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove * a leftover from the previous commit. * src/nm-device-802-11-wireless.c (set_current_ap): Remove * unused variable. (real_act_stage1_prepare): Ditto. (activation_success_handler): Ditto. (get_property): Ditto. * src/nm-device-802-3-ethernet.c (real_get_best_connection): * Remove unused variable. * src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check * for 'ifname', it's always set. * src/supplicant-manager/nm-supplicant-config.c (nm_supplicant_config_add_setting_wireless): Cast the GByteArray's 'guint8 *' to expected "char *". (nm_supplicant_config_add_setting_wireless): Ditto. (nm_supplicant_config_remove_option): Remove, not used. * libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is * a guint32, not double. (test_wireless_enabled): Ifdef out unused function. (device_deactivate): Ditto. (device_state_changed): Ditto. (nm_utils_is_empty_ssid): Remove, it's now in libnm-utils. (nm_utils_escape_ssid): Ditto. * test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in * libnm-utils. (nm_utils_is_empty_ssid): Ditto. * libnm-glib/nm-client.c * (nm_client_free_active_connection_element): Remove unused variable. * libnm-util/nm-setting.c (setting_wireless_destroy): Remove * unused variable. (setting_vpn_properties_update_secrets): Ditto. (int_to_gvalue): Ifdef out for now, not used. (byte_to_gvalue): Ditto. * libnm-util/dbus-dict-helpers.c * (_nmu_dbus_add_dict_entry_string_array): Unused, remove. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-09 08:57:35 +00:00
g_print ("\tFrequency: %u\n", nm_access_point_get_frequency (ap));
2007-02-19 Tambet Ingo <tambet@ximian.com> * src/vpn-manager/nm-vpn-manager.c: Handle the DBUS state changes itself. Handle device state changes and disconnect VPN if it's device deactivates. * src/nm-dbus-nm.c: * src/nm-dbus-nm.h: * src/nm-dbus-device.c: * src/nm-dbus-device.c: * src/nm-dbus-net.c: * src/nm-dbus-net.h: Remove. All of it is implemented byt the new dbus API. * src/NetworkManagerMain.h: Get rid of all but 3 properties of NMData. * src/nm-device.c (nm_device_get_by_udi): (nm_device_get_by_iface): Remove. This doesn't belong here and is already implemented in the correct location (NMManager). Rip out all the test_device stuff. * src/NetworkManagerPolicy.c: Remove the leftover activation success and failure handlers, it's all done by NMDevice already. * src/NetworkManager.c: Move the signal handling here from nm-logging.c Remove the iochannel hack to route the unix signals to the main thread since we're not threaded anymore. * src/NetworkManagerAP.c: Implement HWAddress property. * src/NetworkManagerDbus.c: Remove the dbus signal sending code, it happens automatically with dbus-glib. * src/nm-netlink-monitor.c: * src/nm-netlink-monitor.h: - Move it low in the class hierarchy, don't reference any NM types. - Remove private data from the header. - Use type safe checks in public API methods. - Make it a singleton so we don't have to pass the single reference around. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2339 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-02-19 13:09:32 +00:00
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));
}
static void
dump_wireless (NMDevice80211Wireless *device)
{
const char *str;
GSList *iter;
GSList *aps;
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_print ("AccessPoints:\n");
aps = nm_device_802_11_wireless_get_access_points (device);
for (iter = aps; iter; iter = iter->next) {
2007-02-19 Tambet Ingo <tambet@ximian.com> * src/vpn-manager/nm-vpn-manager.c: Handle the DBUS state changes itself. Handle device state changes and disconnect VPN if it's device deactivates. * src/nm-dbus-nm.c: * src/nm-dbus-nm.h: * src/nm-dbus-device.c: * src/nm-dbus-device.c: * src/nm-dbus-net.c: * src/nm-dbus-net.h: Remove. All of it is implemented byt the new dbus API. * src/NetworkManagerMain.h: Get rid of all but 3 properties of NMData. * src/nm-device.c (nm_device_get_by_udi): (nm_device_get_by_iface): Remove. This doesn't belong here and is already implemented in the correct location (NMManager). Rip out all the test_device stuff. * src/NetworkManagerPolicy.c: Remove the leftover activation success and failure handlers, it's all done by NMDevice already. * src/NetworkManager.c: Move the signal handling here from nm-logging.c Remove the iochannel hack to route the unix signals to the main thread since we're not threaded anymore. * src/NetworkManagerAP.c: Implement HWAddress property. * src/NetworkManagerDbus.c: Remove the dbus signal sending code, it happens automatically with dbus-glib. * src/nm-netlink-monitor.c: * src/nm-netlink-monitor.h: - Move it low in the class hierarchy, don't reference any NM types. - Remove private data from the header. - Use type safe checks in public API methods. - Make it a singleton so we don't have to pass the single reference around. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2339 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-02-19 13:09:32 +00:00
dump_access_point (NM_ACCESS_POINT (iter->data));
g_print ("\n");
}
g_slist_foreach (aps, (GFunc) g_object_unref, NULL);
g_slist_free (aps);
}
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;
guint32 u;
NMDeviceState state;
str = nm_device_get_iface (device);
g_print ("Interface: %s\n", str);
g_free (str);
str = nm_device_get_udi (device);
g_print ("Udi: %s\n", str);
g_free (str);
str = nm_device_get_driver (device);
g_print ("Driver: %s\n", str);
g_free (str);
u = nm_device_get_ip4_address (device);
g_print ("IP address: %d\n", u);
state = nm_device_get_state (device);
g_print ("State: %d\n", state);
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
test_devices (NMClient *client)
{
GSList *list, *iter;
list = nm_client_get_devices (client);
g_print ("Got devices:\n");
for (iter = list; iter; iter = iter->next) {
NMDevice *device = NM_DEVICE (iter->data);
dump_device (device);
g_print ("\n");
}
g_slist_free (list);
return TRUE;
}
static void
device_added_cb (NMClient *client, NMDevice *device, gpointer user_data)
{
g_print ("New device added\n");
dump_device (device);
}
static void
device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data)
{
g_print ("Device removed\n");
dump_device (device);
}
2007-10-09 Tambet Ingo <tambet@gmail.com> * src/NetworkManagerUtils.c (nm_utils_is_empty_ssid): (nm_utils_escape_ssid): (nm_utils_same_ssid): Remove. These functions are copied and pasted in a lot of places, so they belong to libnm-utils instead. Now with 100% less compiler warnings: * libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove, * unused. (nm_dbus_unescape_object_path): Ditto. (nm_utils_ssid_to_utf8): Ditto. (nm_utils_is_empty_ssid): Move here from src/NetworkManagerUtils.c (nm_utils_escape_ssid): Ditto. (nm_utils_same_ssid): Ditto. * src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r. (add_one_connection_element): Remove an unused variable. (impl_manager_get_active_connections): Ditto. * src/NetworkManagerPolicy.c (get_device_connection): Remove an * unused variable. * src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove * a leftover from the previous commit. * src/nm-device-802-11-wireless.c (set_current_ap): Remove * unused variable. (real_act_stage1_prepare): Ditto. (activation_success_handler): Ditto. (get_property): Ditto. * src/nm-device-802-3-ethernet.c (real_get_best_connection): * Remove unused variable. * src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check * for 'ifname', it's always set. * src/supplicant-manager/nm-supplicant-config.c (nm_supplicant_config_add_setting_wireless): Cast the GByteArray's 'guint8 *' to expected "char *". (nm_supplicant_config_add_setting_wireless): Ditto. (nm_supplicant_config_remove_option): Remove, not used. * libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is * a guint32, not double. (test_wireless_enabled): Ifdef out unused function. (device_deactivate): Ditto. (device_state_changed): Ditto. (nm_utils_is_empty_ssid): Remove, it's now in libnm-utils. (nm_utils_escape_ssid): Ditto. * test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in * libnm-utils. (nm_utils_is_empty_ssid): Ditto. * libnm-glib/nm-client.c * (nm_client_free_active_connection_element): Remove unused variable. * libnm-util/nm-setting.c (setting_wireless_destroy): Remove * unused variable. (setting_vpn_properties_update_secrets): Ditto. (int_to_gvalue): Ifdef out for now, not used. (byte_to_gvalue): Ditto. * libnm-util/dbus-dict-helpers.c * (_nmu_dbus_add_dict_entry_string_array): Unused, remove. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-09 08:57:35 +00:00
#if 0
static gboolean
device_deactivate (gpointer user_data)
{
NMDevice *device = NM_DEVICE (user_data);
nm_device_deactivate (device);
return FALSE;
}
static void
device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data)
{
char *str;
str = nm_device_get_iface (device);
g_print ("Device state changed: %s %d\n", str, state);
g_free (str);
if (state == NM_DEVICE_STATE_ACTIVATED) {
g_print ("Scheduling device deactivation\n");
g_timeout_add (5 * 1000,
device_deactivate,
device);
}
}
2007-10-09 Tambet Ingo <tambet@gmail.com> * src/NetworkManagerUtils.c (nm_utils_is_empty_ssid): (nm_utils_escape_ssid): (nm_utils_same_ssid): Remove. These functions are copied and pasted in a lot of places, so they belong to libnm-utils instead. Now with 100% less compiler warnings: * libnm-util/nm-utils.c (nm_dbus_escape_object_path): Remove, * unused. (nm_dbus_unescape_object_path): Ditto. (nm_utils_ssid_to_utf8): Ditto. (nm_utils_is_empty_ssid): Move here from src/NetworkManagerUtils.c (nm_utils_escape_ssid): Ditto. (nm_utils_same_ssid): Ditto. * src/nm-manager.c: Include 'netinet/ether.h' for ether_aton_r. (add_one_connection_element): Remove an unused variable. (impl_manager_get_active_connections): Ditto. * src/NetworkManagerPolicy.c (get_device_connection): Remove an * unused variable. * src/nm-dbus-manager.c (nm_dbus_manager_start_service): Remove * a leftover from the previous commit. * src/nm-device-802-11-wireless.c (set_current_ap): Remove * unused variable. (real_act_stage1_prepare): Ditto. (activation_success_handler): Ditto. (get_property): Ditto. * src/nm-device-802-3-ethernet.c (real_get_best_connection): * Remove unused variable. * src/ppp-manager/nm-pppd-plugin.c (nm_ip_up): Remove the check * for 'ifname', it's always set. * src/supplicant-manager/nm-supplicant-config.c (nm_supplicant_config_add_setting_wireless): Cast the GByteArray's 'guint8 *' to expected "char *". (nm_supplicant_config_add_setting_wireless): Ditto. (nm_supplicant_config_remove_option): Remove, not used. * libnm-glib/libnm-glib-test.c (dump_access_point): Frequency is * a guint32, not double. (test_wireless_enabled): Ifdef out unused function. (device_deactivate): Ditto. (device_state_changed): Ditto. (nm_utils_is_empty_ssid): Remove, it's now in libnm-utils. (nm_utils_escape_ssid): Ditto. * test/nm-tool.c (nm_utils_escape_ssid): Remove, it's now in * libnm-utils. (nm_utils_is_empty_ssid): Ditto. * libnm-glib/nm-client.c * (nm_client_free_active_connection_element): Remove unused variable. * libnm-util/nm-setting.c (setting_wireless_destroy): Remove * unused variable. (setting_vpn_properties_update_secrets): Ditto. (int_to_gvalue): Ifdef out for now, not used. (byte_to_gvalue): Ditto. * libnm-util/dbus-dict-helpers.c * (_nmu_dbus_add_dict_entry_string_array): Unused, remove. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2007-10-09 08:57:35 +00:00
#endif
static void
manager_running (NMClient *client, gboolean running, gpointer user_data)
{
if (running) {
g_print ("NM appeared\n");
/* test_wireless_enabled (client); */
test_get_state (client);
test_devices (client);
} else
g_print ("NM disappeared\n");
}
int
main (int argc, char *argv[])
{
NMClient *client;
g_type_init ();
client = nm_client_new ();
if (!client) {
exit (1);
}
g_signal_connect (client, "manager-running", G_CALLBACK (manager_running), NULL);
manager_running (client, nm_client_manager_is_running (client), NULL);
g_signal_connect (client, "device-added",
G_CALLBACK (device_added_cb), NULL);
g_signal_connect (client, "device-removed",
G_CALLBACK (device_removed_cb), NULL);
g_main_loop_run (g_main_loop_new (NULL, FALSE));
g_object_unref (client);
return 0;
}