NetworkManager r3394 - in trunk: . system-settings/plugins/ifcfg-fedora



Author: dcbw
Date: Sat Mar  8 00:12:42 2008
New Revision: 3394
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3394&view=rev

Log:
2008-03-07  Dan Williams  <dcbw redhat com>

	* system-settings/plugins/ifcfg-fedora/parser.c
		- (is_wireless_device): new function; test a device for wireless
			extensions
		- (parser_parse_file): if the ifcfg file doesn't have a TYPE tag,
			test the device for wireless extensions to determine the type



Modified:
   trunk/ChangeLog
   trunk/system-settings/plugins/ifcfg-fedora/parser.c

Modified: trunk/system-settings/plugins/ifcfg-fedora/parser.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/parser.c	(original)
+++ trunk/system-settings/plugins/ifcfg-fedora/parser.c	Sat Mar  8 00:12:42 2008
@@ -26,6 +26,17 @@
 #include <arpa/inet.h>
 #include <ctype.h>
 #include <sys/inotify.h>
+#include <errno.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#ifndef __user
+#define __user
+#endif
+#include <linux/types.h>
+#include <wireless.h>
+#undef __user
 
 #include <glib.h>
 
@@ -764,7 +775,47 @@
 		g_object_unref (wired_setting);
 	return NULL;
 }
-	
+
+static gboolean
+is_wireless_device (const char *iface, gboolean *is_wireless)
+{
+	int fd;
+	struct iw_range range;
+	struct iwreq wrq;
+	gboolean success = FALSE;
+
+	g_return_val_if_fail (iface != NULL, FALSE);
+	g_return_val_if_fail (is_wireless != NULL, FALSE);
+
+	*is_wireless = FALSE;
+
+	fd = socket(AF_INET, SOCK_DGRAM, 0);
+	if (!fd)
+		return FALSE;
+
+	memset (&wrq, 0, sizeof (struct iwreq));
+	memset (&range, 0, sizeof (struct iw_range));
+	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+	wrq.u.data.pointer = (caddr_t) &range;
+	wrq.u.data.length = sizeof (struct iw_range);
+
+	if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) {
+		if (errno == -EOPNOTSUPP)
+			success = TRUE;
+		goto out;
+	}
+
+	*is_wireless = TRUE;
+	success = TRUE;
+
+out:
+	close (fd);
+	return success;
+}
+
+#define TYPE_ETHERNET "Ethernet"
+#define TYPE_WIRELESS "Wireless"
+
 NMConnection *
 parser_parse_file (const char *file, GError **error)
 {
@@ -796,9 +847,34 @@
 
 	type = svGetValue (parsed, "TYPE");
 	if (!type) {
-		g_set_error (error, ifcfg_plugin_error_quark (), 0,
-		             "File '%s' didn't have a TYPE key.", file);
-		goto done;
+		char *device;
+		gboolean is_wireless = FALSE;
+
+		/* If no type, if the device has wireless extensions, it's wifi,
+		 * otherwise it's ethernet.
+		 */
+		device = svGetValue (parsed, "DEVICE");
+		if (!device) {
+			g_set_error (error, ifcfg_plugin_error_quark (), 0,
+			             "File '%s' had neither TYPE nor DEVICE keys.", file);
+			goto done;
+		}
+
+		/* Test wireless extensions */
+		if (!is_wireless_device (device, &is_wireless)) {
+			g_set_error (error, ifcfg_plugin_error_quark (), 0,
+			             "File '%s' specified device '%s', but the device's "
+			             "type could not be determined.", file, device);
+			g_free (device);
+			goto done;
+		}
+
+		if (is_wireless)
+			type = g_strdup (TYPE_WIRELESS);
+		else
+			type = g_strdup (TYPE_ETHERNET);
+
+		g_free (device);
 	}
 
 	nmc = svGetValue (parsed, "NM_CONTROLLED");
@@ -813,9 +889,9 @@
 		g_free (lower);
 	}
 
-	if (!strcmp (type, "Ethernet"))
+	if (!strcmp (type, TYPE_ETHERNET))
 		connection = wired_connection_from_ifcfg (file, parsed, error);
-	else if (!strcmp (type, "Wireless"))
+	else if (!strcmp (type, TYPE_WIRELESS))
 		connection = wireless_connection_from_ifcfg (file, parsed, error);
 	else {
 		g_set_error (error, ifcfg_plugin_error_quark (), 0,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]