Commit e4a3f124 authored by Chris Aillon's avatar Chris Aillon Committed by Chris Aillon
Browse files

2005-09-12 Christopher Aillon <caillon@redhat.com>

	* gnome/applet/applet-dbus-devices.c:
	* gnome/applet/applet.c:
	* gnome/applet/nm-device.c:
	* gnome/applet/nm-device.h:
	* src/NetworkManagerUtils.c:
	* src/NetworkManagerUtils.h:
	* src/nm-dbus-device.c:
	I've got a fever, and the only cure for it is less ioctl.
	Make NM push IP data rather than make the applet open a socket
	to the device.


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@960 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 314e6fc4
2005-09-12 Christopher Aillon <caillon@redhat.com>
* gnome/applet/applet-dbus-devices.c:
* gnome/applet/applet.c:
* gnome/applet/nm-device.c:
* gnome/applet/nm-device.h:
* src/NetworkManagerUtils.c:
* src/NetworkManagerUtils.h:
* src/nm-dbus-device.c:
I've got a fever, and the only cure for it is less ioctl.
Make NM push IP data rather than make the applet open a socket
to the device.
2005-09-10 Christopher Aillon <caillon@redhat.com>
* gnome/applet/applet.c:
......
......@@ -658,7 +658,9 @@ static void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_d
dbus_uint32_t type = 0;
const char * udi = NULL;
dbus_bool_t active = FALSE;
dbus_uint32_t ip4_address = 0;
const char * ip4_address = NULL;
const char * broadcast = NULL;
const char * subnetmask = NULL;
const char * hw_addr = NULL;
dbus_uint32_t mode = 0;
dbus_int32_t strength = -1;
......@@ -687,7 +689,9 @@ static void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_d
DBUS_TYPE_STRING, &udi,
DBUS_TYPE_BOOLEAN,&active,
DBUS_TYPE_UINT32, &act_stage,
DBUS_TYPE_UINT32, &ip4_address,
DBUS_TYPE_STRING, &ip4_address,
DBUS_TYPE_STRING, &subnetmask,
DBUS_TYPE_STRING, &broadcast,
DBUS_TYPE_STRING, &hw_addr,
DBUS_TYPE_UINT32, &mode,
DBUS_TYPE_INT32, &strength,
......@@ -706,6 +710,9 @@ static void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_d
network_device_set_link (dev, link_active);
network_device_set_driver_support_level (dev, driver_support_level);
network_device_set_act_stage (dev, act_stage);
network_device_set_ip4_address (dev, ip4_address);
network_device_set_broadcast (dev, broadcast);
network_device_set_netmask (dev, subnetmask);
/* If the device already exists in our list for some reason, remove it so we
* can add the new one with updated data.
......
......@@ -32,23 +32,6 @@
#endif
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <math.h>
#include <dirent.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <net/if.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <libgnomeui/libgnomeui.h>
......@@ -206,13 +189,10 @@ static gboolean nmwa_update_info (NMWirelessApplet *applet)
{
GtkWidget *info_dialog;
char *addr = NULL, *mask = NULL, *broadcast = NULL;
char *dest = NULL, *mac = NULL, *iface_and_type = NULL;
char *mac = NULL, *iface_and_type = NULL;
GtkWidget *label;
struct ifreq ifr;
int fd, flags;
const char *iface = NULL;
NetworkDevice *dev;
gboolean ret = TRUE;
info_dialog = glade_xml_get_widget (applet->info_dialog_xml, "info_dialog");
if (!info_dialog)
......@@ -222,7 +202,6 @@ static gboolean nmwa_update_info (NMWirelessApplet *applet)
g_free (err);
return FALSE;
}
if ((dev = nmwa_get_first_active_device (applet->device_list)))
iface = network_device_get_iface (dev);
......@@ -235,82 +214,22 @@ static gboolean nmwa_update_info (NMWirelessApplet *applet)
return FALSE;
}
fd = socket (AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
{
char *err = g_strdup (_("Could not open socket!"));
nmwa_show_socket_err (info_dialog, err);
g_free (err);
return FALSE;
}
ifr.ifr_addr.sa_family = AF_INET;
g_strlcpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name));
if (ioctl (fd, SIOCGIFADDR, &ifr) == 0)
addr = g_strdup (inet_ntoa (((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr));
g_strlcpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name));
if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0)
{
char *err = g_strdup (_("Failed to get information about the interface!"));
nmwa_show_socket_err (info_dialog, err);
g_free (err);
ret = FALSE;
goto out;
}
flags = ifr.ifr_flags;
g_strlcpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name));
if (flags & IFF_BROADCAST && ioctl (fd, SIOCGIFBRDADDR, &ifr) == 0)
broadcast = g_strdup (inet_ntoa (((struct sockaddr_in *) &ifr.ifr_broadaddr)->sin_addr));
mac = (char*) network_device_get_address (dev);
broadcast = (char*) network_device_get_broadcast (dev);
addr = (char*) network_device_get_ip4_address (dev);
mask = (char*) network_device_get_netmask (dev);
g_strlcpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name));
if (ioctl (fd, SIOCGIFNETMASK, &ifr) == 0)
mask = g_strdup (inet_ntoa (((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr));
g_strlcpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name));
if (flags & IFF_POINTOPOINT && ioctl (fd, SIOCGIFDSTADDR, &ifr) == 0)
dest = g_strdup (inet_ntoa (((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr));
g_strlcpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name));
if (ioctl (fd, SIOCGIFHWADDR, &ifr) == 0)
mac = g_strdup_printf ("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
(unsigned char) ifr.ifr_hwaddr.sa_data[0],
(unsigned char) ifr.ifr_hwaddr.sa_data[1],
(unsigned char) ifr.ifr_hwaddr.sa_data[2],
(unsigned char) ifr.ifr_hwaddr.sa_data[3],
(unsigned char) ifr.ifr_hwaddr.sa_data[4],
(unsigned char) ifr.ifr_hwaddr.sa_data[5]);
label = get_label (info_dialog, applet->info_dialog_xml, "label-interface");
if (network_device_is_wired (dev))
iface_and_type = g_strdup_printf (_("Wired Ethernet (%s)"), iface);
else
iface_and_type = g_strdup_printf (_("Wireless Ethernet (%s)"), iface);
label = get_label (info_dialog, applet->info_dialog_xml, "label-interface");
gtk_label_set_text (GTK_LABEL (label), iface_and_type);
label = get_label (info_dialog, applet->info_dialog_xml, "label-ip-address");
gtk_label_set_text (GTK_LABEL (label), addr);
label = get_label (info_dialog, applet->info_dialog_xml, "label-destination-address");
if (flags & IFF_POINTOPOINT)
{
gtk_label_set_text (GTK_LABEL (label), dest);
gtk_widget_show (label);
}
else
gtk_widget_hide (label);
label = get_label (info_dialog, applet->info_dialog_xml, "label-destination-address-label");
if (flags & IFF_POINTOPOINT)
{
gtk_label_set_text (GTK_LABEL (label), dest);
gtk_widget_show (label);
}
else
gtk_widget_hide (label);
label = get_label (info_dialog, applet->info_dialog_xml, "label-broadcast-address");
gtk_label_set_text (GTK_LABEL (label), broadcast);
......@@ -320,16 +239,9 @@ static gboolean nmwa_update_info (NMWirelessApplet *applet)
label = get_label (info_dialog, applet->info_dialog_xml, "label-hardware-address");
gtk_label_set_text (GTK_LABEL (label), mac);
out:
close (fd);
g_free (addr);
g_free (broadcast);
g_free (mask);
g_free (dest);
g_free (iface_and_type);
g_free (mac);
return ret;
return TRUE;
}
static void nmwa_show_info_cb (GtkMenuItem *mi, NMWirelessApplet *applet)
......
......@@ -41,6 +41,9 @@ struct NetworkDevice
gboolean link;
NMDriverSupportLevel driver_support_level;
char * addr;
char * ip4addr;
char * broadcast;
char * netmask;
char * udi;
gint strength;
GSList * networks;
......@@ -89,6 +92,9 @@ NetworkDevice *network_device_copy (NetworkDevice *src)
dev->type = src->type;
dev->link = src->link;
dev->addr = g_strdup (src->addr);
dev->ip4addr = g_strdup (src->ip4addr);
dev->broadcast = g_strdup (src->broadcast);
dev->netmask = g_strdup (src->netmask);
dev->driver_support_level = src->driver_support_level;
dev->iface = g_strdup (src->iface);
dev->desc = g_strdup (src->desc);
......@@ -145,6 +151,9 @@ void network_device_unref (NetworkDevice *dev)
g_free (dev->udi);
g_free (dev->desc);
g_free (dev->addr);
g_free (dev->broadcast);
g_free (dev->netmask);
g_free (dev->ip4addr);
memset (dev, 0, sizeof (NetworkDevice));
g_free (dev);
}
......@@ -400,12 +409,65 @@ void network_device_set_address (NetworkDevice *dev, const char *addr)
g_return_if_fail (dev != NULL);
if (dev->addr)
{
g_free (dev->addr);
dev->addr = NULL;
}
if (addr)
dev->addr = g_strdup (addr);
dev->addr = addr ? g_strdup (addr) : NULL;
}
/*
* Accessors for broadcast address
*/
const char *network_device_get_broadcast (NetworkDevice *dev)
{
g_return_val_if_fail (dev != NULL, NULL);
return (dev->broadcast);
}
void network_device_set_broadcast (NetworkDevice *dev, const char *addr)
{
g_return_if_fail (dev != NULL);
if (dev->broadcast)
g_free (dev->broadcast);
dev->broadcast = addr ? g_strdup (addr) : NULL;
}
/*
* Accessors for subnet address
*/
const char *network_device_get_netmask (NetworkDevice *dev)
{
g_return_val_if_fail (dev != NULL, NULL);
return (dev->netmask);
}
void network_device_set_netmask (NetworkDevice *dev, const char *addr)
{
g_return_if_fail (dev != NULL);
if (dev->netmask)
g_free (dev->netmask);
dev->netmask = addr ? g_strdup (addr) : NULL;
}
/*
* Accessors for ip4 address
*/
const char *network_device_get_ip4_address (NetworkDevice *dev)
{
g_return_val_if_fail (dev != NULL, NULL);
return (dev->ip4addr);
}
void network_device_set_ip4_address (NetworkDevice *dev, const char *addr)
{
g_return_if_fail (dev != NULL);
if (dev->ip4addr)
g_free (dev->ip4addr);
dev->ip4addr = addr ? g_strdup (addr) : NULL;
}
/*
......
......@@ -60,6 +60,15 @@ guint network_device_get_num_wireless_networks (NetworkDevice *dev);
const char * network_device_get_address (NetworkDevice *dev);
void network_device_set_address (NetworkDevice *dev, const char *addr);
const char * network_device_get_broadcast (NetworkDevice *dev);
void network_device_set_broadcast (NetworkDevice *dev, const char *addr);
const char * network_device_get_netmask (NetworkDevice *dev);
void network_device_set_netmask (NetworkDevice *dev, const char *addr);
const char * network_device_get_ip4_address (NetworkDevice *dev);
void network_device_set_ip4_address (NetworkDevice *dev, const char *addr);
NMDriverSupportLevel network_device_get_driver_support_level (NetworkDevice *dev);
void network_device_set_driver_support_level (NetworkDevice *dev, NMDriverSupportLevel level);
......
......@@ -23,6 +23,8 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/sockios.h>
#include <syslog.h>
#include <stdarg.h>
......@@ -802,3 +804,15 @@ gboolean nm_completion_boolean_function2_test(int tries,
return FALSE;
}
gchar *nm_utils_inet_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);
}
......@@ -102,4 +102,6 @@ gboolean nm_completion_boolean_function2_test(int tries,
nm_completion_args args);
#define nm_completion_boolean_function_test nm_completion_boolean_function1_test
gchar* nm_utils_inet_ip4_address_as_string (guint32 ip);
#endif
......@@ -32,6 +32,7 @@
#include "NetworkManagerDbus.h"
#include "NetworkManagerDbusUtils.h"
#include "NetworkManagerPolicy.h"
#include "NetworkManagerUtils.h"
#include "nm-dbus-device.h"
......@@ -325,7 +326,9 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
const char * iface = nm_device_get_iface (dev);
dbus_uint32_t type = (dbus_uint32_t) nm_device_get_type (dev);
const char * udi = nm_device_get_udi (dev);
dbus_uint32_t ip4_address = (dbus_uint32_t) nm_device_get_ip4_address (dev);
gchar * ip4_address;
gchar * broadcast;
gchar * subnetmask;
struct ether_addr hw_addr;
char hw_addr_buf[20];
char * hw_addr_buf_ptr = &hw_addr_buf[0];
......@@ -338,11 +341,17 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
int num_networks = 0;
dbus_bool_t active = nm_device_get_act_request (dev) ? TRUE : FALSE;
NMActStage act_stage = active ? nm_act_request_get_stage (nm_device_get_act_request (dev)) : NM_ACT_STAGE_UNKNOWN;
NMIP4Config * ip4config;
nm_device_get_hw_address (dev, &hw_addr);
memset (hw_addr_buf, 0, 20);
ether_ntoa_r (&hw_addr, &hw_addr_buf[0]);
ip4config = nm_device_get_ip4_config (dev);
ip4_address = nm_utils_inet_ip4_address_as_string (nm_device_get_ip4_address (dev));
broadcast = nm_utils_inet_ip4_address_as_string (nm_ip4_config_get_broadcast (ip4config));
subnetmask = nm_utils_inet_ip4_address_as_string (nm_ip4_config_get_netmask (ip4config));
if (nm_device_is_wireless (dev))
{
NMActRequest * req = nm_device_get_act_request (dev);
......@@ -391,7 +400,9 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
DBUS_TYPE_STRING, &udi,
DBUS_TYPE_BOOLEAN,&active,
DBUS_TYPE_UINT32, &act_stage,
DBUS_TYPE_UINT32, &ip4_address,
DBUS_TYPE_STRING, &ip4_address,
DBUS_TYPE_STRING, &subnetmask,
DBUS_TYPE_STRING, &broadcast,
DBUS_TYPE_STRING, &hw_addr_buf_ptr,
DBUS_TYPE_UINT32, &mode,
DBUS_TYPE_INT32, &strength,
......@@ -403,6 +414,9 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
g_free (op);
g_free (active_network_path);
g_strfreev (networks);
g_free (ip4_address);
g_free (broadcast);
g_free (subnetmask);
}
return reply;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment