2008-11-14 17:41:16 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* libnm_glib -- Access network status & information from glib applications
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 - 2008 Novell, Inc.
|
|
|
|
* Copyright (C) 2007 - 2008 Red Hat, Inc.
|
|
|
|
*/
|
|
|
|
|
2007-02-12 09:23:43 +00:00
|
|
|
#include <stdlib.h>
|
2008-03-24 15:17:30 +00:00
|
|
|
#include <signal.h>
|
2008-06-26 19:33:13 +00:00
|
|
|
#include <string.h>
|
2007-02-16 11:23:49 +00:00
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2008-03-14 Dan Williams <dcbw@redhat.com>
* include/wireless-helper.h
include/Makefile.am
- One place for all the junk needed for #including wireless.h
* test/nm-tool.c
src/NetworkManagerAP.c
src/wpa.c
src/Makefile.am
libnm-util/nm-utils.c
libnm-util/nm-setting-wireless.c
libnm-glib/nm-device-802-11-wireless.c
libnm-glib/nm-access-point.c
libnm-glib/libnm-glib-test.c
- include wireless-helper.h, not iwlib.h
* configure.in
- Don't need libiw really, just need to check for wireless.h
* src/kernel-types.h
- Remove; used types moved into wpa.c
* src/nm-device-802-11-wireless.c
- (nm_device_802_11_wireless_update_signal_strength,
real_get_generic_capabilities, nm_device_802_11_wireless_get_mode,
nm_device_802_11_wireless_set_mode,
nm_device_802_11_wireless_get_frequency,
nm_device_802_11_wireless_get_ssid,
nm_device_802_11_wireless_set_ssid,
nm_device_802_11_wireless_get_bitrate,
nm_device_802_11_wireless_get_bssid,
nm_device_802_11_wireless_disable_encryption): use ioctl() directly
instead of iwlib functions
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3462 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-14 21:12:03 +00:00
|
|
|
|
2007-02-12 09:23:43 +00:00
|
|
|
#include "nm-client.h"
|
|
|
|
#include "nm-device.h"
|
2008-06-10 15:54:23 +00:00
|
|
|
#include "nm-device-ethernet.h"
|
2008-06-10 16:32:39 +00:00
|
|
|
#include "nm-device-wifi.h"
|
2007-10-09 08:57:35 +00:00
|
|
|
#include "nm-utils.h"
|
2008-03-24 15:17:30 +00:00
|
|
|
#include "nm-active-connection.h"
|
2010-03-12 09:49:59 +00:00
|
|
|
#include "nm-vpn-connection.h"
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
#include "nm-setting-ip4-config.h"
|
2007-02-12 09:23:43 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
// nm_client_wireless_set_enabled (client, !wireless);
|
2007-02-12 09:23:43 +00:00
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
wireless = nm_client_wireless_hardware_get_enabled (client);
|
|
|
|
g_print ("Wireless HW enabled? %s\n", wireless ? "yes" : "no");
|
2007-02-12 09:23:43 +00:00
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
// nm_client_wireless_set_enabled (client, !wireless);
|
2007-02-12 09:23:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_get_state (NMClient *client)
|
|
|
|
{
|
|
|
|
guint state;
|
|
|
|
|
|
|
|
state = nm_client_get_state (client);
|
|
|
|
g_print ("Current state: %d\n", state);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
static gchar *
|
|
|
|
ip4_address_as_string (guint32 ip)
|
|
|
|
{
|
2008-06-26 19:33:13 +00:00
|
|
|
char buf[INET_ADDRSTRLEN+1];
|
2007-02-16 11:23:49 +00:00
|
|
|
struct in_addr tmp_addr;
|
|
|
|
|
2008-06-26 19:33:13 +00:00
|
|
|
memset (&buf, '\0', sizeof (buf));
|
2007-02-16 11:23:49 +00:00
|
|
|
tmp_addr.s_addr = ip;
|
|
|
|
|
2008-06-26 19:33:13 +00:00
|
|
|
if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) {
|
|
|
|
return g_strdup (buf);
|
|
|
|
} else {
|
2011-02-23 17:42:04 +00:00
|
|
|
g_warning ("%s: error converting IP4 address 0x%X",
|
|
|
|
__func__, ntohl (tmp_addr.s_addr));
|
2008-06-26 19:33:13 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-02-16 11:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_ip4_config (NMIP4Config *cfg)
|
|
|
|
{
|
|
|
|
char *tmp;
|
2008-03-24 15:17:30 +00:00
|
|
|
const GArray *array;
|
|
|
|
const GPtrArray *ptr_array;
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
GSList *iter;
|
2007-02-16 11:23:49 +00:00
|
|
|
int i;
|
|
|
|
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
for (iter = (GSList *) nm_ip4_config_get_addresses (cfg); iter; iter = g_slist_next (iter)) {
|
2008-10-29 14:35:25 +00:00
|
|
|
NMIP4Address *addr = iter->data;
|
|
|
|
guint32 u;
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
tmp = ip4_address_as_string (nm_ip4_address_get_address (addr));
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
g_print ("IP4 address: %s\n", tmp);
|
|
|
|
g_free (tmp);
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
u = nm_ip4_address_get_prefix (addr);
|
|
|
|
tmp = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (u));
|
|
|
|
g_print ("IP4 prefix: %d (%s)\n", u, tmp);
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
g_free (tmp);
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-10-29 14:35:25 +00:00
|
|
|
tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr));
|
2008-05-06 Dan Williams <dcbw@redhat.com>
* src/dhcp-manager/nm-dhcp-manager.c
- (nm_dhcp_manager_get_ip4_config): clean up; update for changes to
NMIP4Config to support multiple IP addresses
* src/NetworkManagerUtils.c
- (nm_utils_merge_ip4_config): update for multiple IP addresses
* src/nm-ip4-config.c
src/nm-ip4-config.h
- Store a list of IPv4 address/netmask/gateway tuples
- (nm_ip4_config_get_gateway, nm_ip4_config_set_gateway,
nm_ip4_config_get_netmask, nm_ip4_config_set_netmask,
nm_ip4_config_get_broadcast, nm_ip4_config_set_broadcast,
nm_ip4_config_set_address): remove
- (nm_ip4_config_take_address, nm_ip4_config_add_address,
nm_ip4_config_replace_address, nm_ip4_config_get_num_addresses):
new functions; handle multiple IPv4 addresses
* src/nm-device.c
src/ppp-manager/nm-ppp-manager.c
src/vpn-manager/nm-vpn-connection.c
src/NetworkManagerPolicy.c
test/nm-tool.c
libnm-glib/libnm-glib-test.c
- update for changes to NMIP4Config for multiple IPv4 addresses
* src/NetworkManagerSystem.c
- (nm_system_device_set_ip4_route): don't add the route if any address
is on the same subnet as the destination
- (check_one_address): ignore the exact match, just match family and
interface index
- (add_ip4_addresses): add all IPv4 addresses in an NMIP4Config to
an interface
- (nm_system_device_set_from_ip4_config): use add_ip4_addresses()
- (nm_system_vpn_device_set_from_ip4_config): use add_ip4_addresses()
* introspection/nm-ip4-config.xml
- Remove 'address', 'gateway', 'netmask', and 'broadcast' properties
- Add 'addresses' property which is an array of (uuu) tuples of
address/netmask/gateway
* libnm-util/nm-setting-ip4-config.c
- (set_property): use ip-address <-> GValue converters from nm-utils.c
* libnm-glib/nm-ip4-config.c
libnm-glib/nm-ip4-config.h
- Handle D-Bus interface changes to support multiple IP addresses
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3637 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-05-06 21:53:22 +00:00
|
|
|
g_print ("IP4 gateway: %s\n\n", tmp);
|
|
|
|
g_free (tmp);
|
|
|
|
}
|
2007-02-16 11:23:49 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr_array = nm_ip4_config_get_domains (cfg);
|
|
|
|
if (ptr_array) {
|
|
|
|
g_print ("IP4 domains:\n");
|
2008-03-24 15:17:30 +00:00
|
|
|
for (i = 0; i < ptr_array->len; i++)
|
|
|
|
g_print ("\t%s\n", (const char *) g_ptr_array_index (ptr_array, i));
|
2007-02-16 11:23:49 +00:00
|
|
|
}
|
2008-12-19 22:01:06 +00:00
|
|
|
|
|
|
|
array = nm_ip4_config_get_wins_servers (cfg);
|
|
|
|
if (array) {
|
|
|
|
g_print ("IP4 WINS:\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);
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 11:23:49 +00:00
|
|
|
}
|
|
|
|
|
2008-08-07 15:26:32 +00:00
|
|
|
static void
|
|
|
|
print_one_dhcp4_option (gpointer key, gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
const char *option = (const char *) key;
|
|
|
|
const char *value = (const char *) data;
|
|
|
|
|
|
|
|
g_print (" %s: %s\n", option, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_dhcp4_config (NMDHCP4Config *config)
|
|
|
|
{
|
|
|
|
GHashTable *options = NULL;
|
|
|
|
|
|
|
|
if (!config)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_print ("\nDHCP4 Options:\n");
|
|
|
|
g_print ("-------------------------------------\n");
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (config), NM_DHCP4_CONFIG_OPTIONS, &options, NULL);
|
|
|
|
g_hash_table_foreach (options, print_one_dhcp4_option, NULL);
|
|
|
|
}
|
|
|
|
|
2007-02-19 13:09:32 +00:00
|
|
|
static void
|
|
|
|
dump_access_point (NMAccessPoint *ap)
|
|
|
|
{
|
2007-09-24 14:58:52 +00:00
|
|
|
const GByteArray * ssid;
|
2007-10-05 16:00:06 +00:00
|
|
|
const char * str;
|
2007-02-19 13:09:32 +00:00
|
|
|
|
2007-06-27 16:18:52 +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 13:09:32 +00:00
|
|
|
|
|
|
|
str = nm_access_point_get_hw_address (ap);
|
|
|
|
g_print ("\tMAC Address: %s\n", str);
|
|
|
|
|
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 08:57:35 +00:00
|
|
|
g_print ("\tFrequency: %u\n", nm_access_point_get_frequency (ap));
|
2007-02-19 13:09:32 +00:00
|
|
|
|
|
|
|
g_print ("\tMode: %d\n", nm_access_point_get_mode (ap));
|
2008-03-12 17:44:39 +00:00
|
|
|
g_print ("\tRate: %d\n", nm_access_point_get_max_bitrate (ap));
|
2007-02-19 13:09:32 +00:00
|
|
|
g_print ("\tStrength: %d\n", nm_access_point_get_strength (ap));
|
|
|
|
}
|
|
|
|
|
2007-02-16 11:23:49 +00:00
|
|
|
static void
|
2008-06-10 16:32:39 +00:00
|
|
|
dump_wireless (NMDeviceWifi *device)
|
2007-02-16 11:23:49 +00:00
|
|
|
{
|
2007-11-13 20:03:31 +00:00
|
|
|
const char *str;
|
2008-03-27 14:10:43 +00:00
|
|
|
const GPtrArray *aps;
|
2008-03-24 15:17:30 +00:00
|
|
|
int i;
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-06-10 16:32:39 +00:00
|
|
|
g_print ("Mode: %d\n", nm_device_wifi_get_mode (device));
|
|
|
|
g_print ("Bitrate: %d\n", nm_device_wifi_get_bitrate (device));
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-06-10 16:32:39 +00:00
|
|
|
str = nm_device_wifi_get_hw_address (device);
|
2007-02-16 11:23:49 +00:00
|
|
|
g_print ("MAC: %s\n", str);
|
|
|
|
|
2007-10-03 18:20:35 +00:00
|
|
|
g_print ("AccessPoints:\n");
|
2008-06-10 16:32:39 +00:00
|
|
|
aps = nm_device_wifi_get_access_points (device);
|
2011-02-18 17:30:36 +00:00
|
|
|
for (i = 0; aps && (i < aps->len); i++) {
|
2008-03-24 15:17:30 +00:00
|
|
|
dump_access_point (NM_ACCESS_POINT (g_ptr_array_index (aps, i)));
|
2007-02-16 11:23:49 +00:00
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-10 15:54:23 +00:00
|
|
|
dump_wired (NMDeviceEthernet *device)
|
2007-02-16 11:23:49 +00:00
|
|
|
{
|
2008-03-12 Dan Williams <dcbw@redhat.com>
Move the 'carrier' property from NMDevice to NMDevice8023Ethernet;
convert the libnm-glib NMDevice8023Ethernet to cached properties
* introspection/nm-device-802-3-ethernet.xml
- New 'Carrier' property
- New 'PropertiesChanged' signal
* introspection/nm-device.xml
- Remove 'Carrier' property
- Remove 'CarrierChanged' signal
* src/nm-device-interface.c
src/nm-device-interface.h
- (nm_device_interface_init): remove 'carrier' property and
'carrier-changed' signal
* src/nm-device.c
src/nm-device.h
- (nm_device_get_carrier, nm_device_set_carrier): remove
- (nm_device_activate_stage5_ip_config_commit): don't bother updating
the link here; wired device will handle that
- (handle_dhcp_lease_change): don't bother updating link here
- (get_property, nm_device_class_init): remove carrier property
* src/nm-device-802-11-wireless.c
- (real_update_link, nm_device_802_11_wireless_class_init): remove
real_update_link(); wireless devices don't use carrier at all
- (link_timeout_cb, supplicant_iface_state_cb_handler,
supplicant_iface_connection_state_cb_handler,
supplicant_mgr_state_cb_handler): remove anything to do with carrier
* src/nm-device-802-3-ethernet.c
src/nm-device-802-3-ethernet.h
- (nm_device_802_3_ethernet_carrier_on,
nm_device_802_3_ethernet_carrier_off, constructor): use set_carrier()
instead of nm_device_set_carrier()
- (device_state_changed): update link from sysfs on activation;
replaces real_update_link()
- (real_update_link): remove, replaced by device_state_changed()
- (nm_device_802_3_ethernet_get_carrier, set_carrier): new functions
- (nm_device_802_3_ethernet_get_speed): move up with other getters/setters
- (real_get_generic_capabilities, real_can_interrupt_activation): use
new get_carrier function
- (get_property): add 'carrier' property
- (nm_device_802_3_ethernet_class_init): add 'carrier' property and
hook into property-changed signal helper
* src/NetworkManagerPolicy.c
- (device_carrier_changed): will only ever be called with a wired device
- (device_added): only hook up to carrier-changed for wired devices
* libnm-glib/nm-device.c
libnm-glib/nm-device.h
- (constructor, nm_device_class_init): remove carrier-changed signal
- (device_carrier_changed_proxy): remove; unused
- (nm_device_get_carrier): remove; carrier a property of wired devices
* libnm-glib/nm-device-802-3-ethernet.c
libnm-glib/nm-device-802-3-ethernet.h
- Convert to cached properties like AP and Wireless objects
- (nm_device_802_3_ethernet_get_hw_address): now returns a 'const char *'
instead of a 'char *', return value should not be freed
- (nm_device_802_3_ethernet_get_carrier): return current carrier status
- (constructor): hook into properties-changed helper
- (set_property, get_property): new functions
- (nm_device_802_3_ethernet_class_init): export GObject properties
* test/nm-tool.c
- (detail_device): strdup the wired hardware address too since it's
cached now
* libnm-glib/libnm-glib-test.c
- (dump_wired): strdup the wired hardware address too since it's
cached now
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3428 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-12 16:12:39 +00:00
|
|
|
const char *str;
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-06-10 15:54:23 +00:00
|
|
|
g_print ("Speed: %d\n", nm_device_ethernet_get_speed (device));
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-06-10 15:54:23 +00:00
|
|
|
str = nm_device_ethernet_get_hw_address (device);
|
2007-02-16 11:23:49 +00:00
|
|
|
g_print ("MAC: %s\n", str);
|
|
|
|
}
|
2007-02-12 09:23:43 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
dump_device (NMDevice *device)
|
|
|
|
{
|
2008-03-24 15:17:30 +00:00
|
|
|
const char *str;
|
2007-02-12 09:23:43 +00:00
|
|
|
NMDeviceState state;
|
|
|
|
|
|
|
|
str = nm_device_get_iface (device);
|
|
|
|
g_print ("Interface: %s\n", str);
|
|
|
|
|
|
|
|
str = nm_device_get_udi (device);
|
|
|
|
g_print ("Udi: %s\n", str);
|
|
|
|
|
|
|
|
str = nm_device_get_driver (device);
|
|
|
|
g_print ("Driver: %s\n", str);
|
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
str = nm_device_get_vendor (device);
|
|
|
|
g_print ("Vendor: %s\n", str);
|
|
|
|
|
|
|
|
str = nm_device_get_product (device);
|
|
|
|
g_print ("Product: %s\n", str);
|
2007-02-12 09:23:43 +00:00
|
|
|
|
|
|
|
state = nm_device_get_state (device);
|
|
|
|
g_print ("State: %d\n", state);
|
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
if (state == NM_DEVICE_STATE_ACTIVATED)
|
|
|
|
dump_ip4_config (nm_device_get_ip4_config (device));
|
2007-02-16 11:23:49 +00:00
|
|
|
|
2008-06-10 15:54:23 +00:00
|
|
|
if (NM_IS_DEVICE_ETHERNET (device))
|
|
|
|
dump_wired (NM_DEVICE_ETHERNET (device));
|
2008-06-10 16:32:39 +00:00
|
|
|
else if (NM_IS_DEVICE_WIFI (device))
|
|
|
|
dump_wireless (NM_DEVICE_WIFI (device));
|
2008-08-07 15:26:32 +00:00
|
|
|
|
|
|
|
dump_dhcp4_config (nm_device_get_dhcp4_config (device));
|
2007-02-12 09:23:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
test_devices (NMClient *client)
|
|
|
|
{
|
2008-03-27 14:10:43 +00:00
|
|
|
const GPtrArray *devices;
|
2008-03-24 15:17:30 +00:00
|
|
|
int i;
|
2007-02-12 09:23:43 +00:00
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
devices = nm_client_get_devices (client);
|
2007-02-12 09:23:43 +00:00
|
|
|
g_print ("Got devices:\n");
|
2008-03-24 15:17:30 +00:00
|
|
|
if (!devices) {
|
|
|
|
g_print (" NONE\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < devices->len; i++) {
|
|
|
|
NMDevice *device = g_ptr_array_index (devices, i);
|
2007-02-12 09:23:43 +00:00
|
|
|
dump_device (device);
|
|
|
|
g_print ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-03-24 15:17:30 +00:00
|
|
|
active_connections_changed (NMClient *client, GParamSpec *pspec, gpointer user_data)
|
2007-02-12 09:23:43 +00:00
|
|
|
{
|
2008-03-24 15:17:30 +00:00
|
|
|
const GPtrArray *connections;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
g_print ("Active connections changed:\n");
|
|
|
|
connections = nm_client_get_active_connections (client);
|
2008-08-07 15:26:32 +00:00
|
|
|
for (i = 0; connections && (i < connections->len); i++) {
|
2008-03-24 15:17:30 +00:00
|
|
|
NMActiveConnection *connection;
|
|
|
|
const GPtrArray *devices;
|
|
|
|
|
|
|
|
connection = g_ptr_array_index (connections, i);
|
|
|
|
g_print (" %s\n", nm_object_get_path (NM_OBJECT (connection)));
|
|
|
|
devices = nm_active_connection_get_devices (connection);
|
2010-03-12 09:49:59 +00:00
|
|
|
for (j = 0; devices && j < devices->len; j++)
|
2008-03-24 15:17:30 +00:00
|
|
|
g_print (" %s\n", nm_device_get_udi (g_ptr_array_index (devices, j)));
|
2010-03-12 09:49:59 +00:00
|
|
|
if (NM_IS_VPN_CONNECTION (connection))
|
|
|
|
g_print (" VPN base connection: %s\n", nm_active_connection_get_specific_object (connection));
|
2008-03-24 15:17:30 +00:00
|
|
|
}
|
2007-02-12 09:23:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-03-24 15:17:30 +00:00
|
|
|
show_active_connection_device (gpointer data, gpointer user_data)
|
2007-02-12 09:23:43 +00:00
|
|
|
{
|
2008-03-24 15:17:30 +00:00
|
|
|
NMDevice *device = NM_DEVICE (data);
|
|
|
|
|
|
|
|
g_print (" %s\n", nm_device_get_udi (device));
|
2007-02-12 09:23:43 +00:00
|
|
|
}
|
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
static void
|
|
|
|
test_get_active_connections (NMClient *client)
|
2007-02-12 09:23:43 +00:00
|
|
|
{
|
2008-03-24 15:17:30 +00:00
|
|
|
const GPtrArray *connections;
|
|
|
|
int i;
|
2007-02-12 09:23:43 +00:00
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
g_print ("Active connections:\n");
|
|
|
|
connections = nm_client_get_active_connections (client);
|
2008-08-07 15:26:32 +00:00
|
|
|
for (i = 0; connections && (i < connections->len); i++) {
|
2008-03-24 15:17:30 +00:00
|
|
|
const GPtrArray *devices;
|
2007-02-12 09:23:43 +00:00
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
g_print (" %s\n", nm_object_get_path (g_ptr_array_index (connections, i)));
|
|
|
|
devices = nm_active_connection_get_devices (g_ptr_array_index (connections, i));
|
2011-02-18 17:31:45 +00:00
|
|
|
if (devices)
|
|
|
|
g_ptr_array_foreach ((GPtrArray *) devices, show_active_connection_device, NULL);
|
2008-03-24 15:17:30 +00:00
|
|
|
}
|
2007-02-12 09:23:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-03-24 15:17:30 +00:00
|
|
|
device_state_changed (NMDevice *device, GParamSpec *pspec, gpointer user_data)
|
2007-02-12 09:23:43 +00:00
|
|
|
{
|
2008-03-24 15:17:30 +00:00
|
|
|
g_print ("Device state changed: %s %d\n",
|
|
|
|
nm_device_get_iface (device),
|
|
|
|
nm_device_get_state (device));
|
|
|
|
}
|
2007-02-12 09:23:43 +00:00
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
static void
|
|
|
|
device_added_cb (NMClient *client, NMDevice *device, gpointer user_data)
|
|
|
|
{
|
|
|
|
g_print ("New device added\n");
|
|
|
|
dump_device (device);
|
|
|
|
g_signal_connect (G_OBJECT (device), "notify::state",
|
|
|
|
(GCallback) device_state_changed, NULL);
|
2007-02-12 09:23:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-16 09:37:53 +00:00
|
|
|
static void
|
2008-03-24 15:17:30 +00:00
|
|
|
device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data)
|
2007-03-16 09:37:53 +00:00
|
|
|
{
|
2008-03-24 15:17:30 +00:00
|
|
|
g_print ("Device removed\n");
|
|
|
|
dump_device (device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
manager_running (NMClient *client, GParamSpec *pspec, gpointer user_data)
|
|
|
|
{
|
|
|
|
if (nm_client_get_manager_running (client)) {
|
2007-03-16 09:37:53 +00:00
|
|
|
g_print ("NM appeared\n");
|
2008-03-24 15:17:30 +00:00
|
|
|
test_wireless_enabled (client);
|
2007-03-16 09:37:53 +00:00
|
|
|
test_get_state (client);
|
2008-03-24 15:17:30 +00:00
|
|
|
test_get_active_connections (client);
|
2007-03-16 09:37:53 +00:00
|
|
|
test_devices (client);
|
|
|
|
} else
|
|
|
|
g_print ("NM disappeared\n");
|
|
|
|
}
|
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
static GMainLoop *loop = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
signal_handler (int signo)
|
|
|
|
{
|
|
|
|
if (signo == SIGINT || signo == SIGTERM) {
|
|
|
|
g_message ("Caught signal %d, shutting down...", signo);
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_signals (void)
|
|
|
|
{
|
|
|
|
struct sigaction action;
|
|
|
|
sigset_t mask;
|
|
|
|
|
|
|
|
sigemptyset (&mask);
|
|
|
|
action.sa_handler = signal_handler;
|
|
|
|
action.sa_mask = mask;
|
|
|
|
action.sa_flags = 0;
|
|
|
|
sigaction (SIGTERM, &action, NULL);
|
|
|
|
sigaction (SIGINT, &action, NULL);
|
|
|
|
}
|
|
|
|
|
2007-02-12 09:23:43 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
NMClient *client;
|
|
|
|
|
|
|
|
g_type_init ();
|
|
|
|
|
|
|
|
client = nm_client_new ();
|
|
|
|
if (!client) {
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
g_signal_connect (client, "notify::" NM_CLIENT_MANAGER_RUNNING,
|
|
|
|
G_CALLBACK (manager_running), NULL);
|
|
|
|
g_signal_connect (client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS,
|
|
|
|
G_CALLBACK (active_connections_changed), NULL);
|
|
|
|
manager_running (client, NULL, NULL);
|
2007-02-12 09:23:43 +00:00
|
|
|
|
|
|
|
g_signal_connect (client, "device-added",
|
|
|
|
G_CALLBACK (device_added_cb), NULL);
|
|
|
|
g_signal_connect (client, "device-removed",
|
|
|
|
G_CALLBACK (device_removed_cb), NULL);
|
|
|
|
|
2008-03-24 15:17:30 +00:00
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
setup_signals ();
|
|
|
|
g_main_loop_run (loop);
|
2007-02-12 09:23:43 +00:00
|
|
|
|
|
|
|
g_object_unref (client);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|