[network-manager-applet] editor: autofill common IPv4 prefixes



commit 7a47a6aa9b64564bef71c77961917270ddf2119c
Author: cee1 <fykcee1 gmail com>
Date:   Mon Apr 26 23:31:21 2010 -0700

    editor: autofill common IPv4 prefixes

 src/connection-editor/page-ip4.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index ed22ede..8e67157 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -517,6 +517,27 @@ cell_edited (GtkCellRendererText *cell,
 	gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
 	gtk_list_store_set (store, &iter, column, new_text, -1);
 
+	/* Try to autodetect the prefix from the given address if we can */
+	if (column == COL_ADDRESS && new_text && strlen (new_text)) {
+		char *prefix = NULL;
+		const char *guess_prefix = NULL;
+
+		gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path_string);
+		gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, COL_PREFIX, &prefix, -1);
+		if (!prefix || !strlen (prefix)) {
+			if (!strncmp ("10.", new_text, 3))
+				guess_prefix = "8";
+			else if (!strncmp ("172.16.", new_text, 7))
+				guess_prefix = "16";
+			else if (!strncmp ("192.168.", new_text, 8))
+				guess_prefix = "24";
+
+			if (guess_prefix)
+				gtk_list_store_set (store, &iter, COL_PREFIX, guess_prefix, -1);
+		}
+		g_free (prefix);
+	}
+
 	/* Move focus to the next column */
 	column = (column >= COL_LAST) ? 0 : column + 1;
 	next_col = gtk_tree_view_get_column (priv->addr_list, column);



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