[gnome-network][PATCH] gnome-netinfo



Hi, 

I have updated my pending gnome-netinfo patches for the new cvs module.
That patch consists in:

* Adds is_ipv6_enable function to know if IPv6 is enabled in the system
* Changes the cursor to GDK_WATCH when a process is running
* Full IPv6 support in netstat
* The tree_model doesn't change when you toggle between protocol and
route twice in netstat

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Carlos Garcia Campos a.k.a. KaL
   elkalmail yahoo es
   carlosgc gnome org
 Grupo Linups
   Usuarios de SL/Linux de la UPSAM
 http://www.linups.org
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=		  
PGP key: http://pgp.rediris.es:11371/pks/lookup?op=get&search=0x523E6462
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-netinfo/ChangeLog,v
retrieving revision 1.5
diff -u -u -r1.5 ChangeLog
--- ChangeLog	11 Feb 2004 15:40:21 -0000	1.5
+++ ChangeLog	14 Mar 2004 19:08:37 -0000
@@ -1,3 +1,20 @@
+2004-03-14  Carlos García Campos <carlosgc gnome org>
+
+	* src/netinfo.c (toggle_state): change the cursor to GDK_WATCH when
+        a process is running
+	
+	* src/netinfo.[ch] (is_ipv6_enable): added is_ipv6_enable function to
+	know if IPv6 is enabled in the system
+
+	* src/netstat.[ch] (get_active_option, strip_protocol_line, 
+	strip_route_line, *_tree_insert): IPv6 support
+
+	* src/netstat.[ch] (get_active_option): checks if IPv6 is enabled before
+        use inet6 protocol
+
+	* src/netstat.c (*_tree_insert): the tree_model doesn't change when
+        you toggle between protocol and route twice
+		
 2004-02-11  Rodrigo Moya <rodrigo gnome-db org>
 
 	* configure.in: set version to 0.99.0.
Index: src/netinfo.c
===================================================================
RCS file: /cvs/gnome/gnome-netinfo/src/netinfo.c,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 netinfo.c
--- src/netinfo.c	23 Jan 2004 15:48:45 -0000	1.1.1.1
+++ src/netinfo.c	14 Mar 2004 19:08:37 -0000
@@ -75,6 +75,27 @@
 			    host);
 }
 
+gboolean
+netinfo_is_ipv6_enable ()
+{
+	gint sock;
+	struct sockaddr_in6 sin6;
+	guint len;
+
+	if ((sock = socket (PF_INET6, SOCK_STREAM, 0)) == -1) {
+		return FALSE;
+	} else {
+		len = sizeof (struct sockaddr_in6);
+		if (getsockname (sock, (struct sockaddr *)&sin6, (void *)&len) < 0) {
+			close (sock);
+			return FALSE;
+		} else {
+			close (sock);
+			return TRUE;
+		}
+	}
+}
+
 const gchar *
 netinfo_get_user (Netinfo * netinfo)
 {
@@ -338,6 +359,8 @@
 netinfo_toggle_state (Netinfo * netinfo, gboolean state,
 		      gpointer user_data)
 {
+	GdkCursor *cursor;
+	
 	g_assert (netinfo != NULL);
 	g_return_if_fail (netinfo != NULL);
 
@@ -347,8 +370,16 @@
 	}
 
 	if (state) {
+		gdk_window_set_cursor ((netinfo->output)->window, NULL);
 		netinfo->child_pid = 0;
+	} else {
+		cursor = gdk_cursor_new (GDK_WATCH);
+		if (!GTK_WIDGET_REALIZED (netinfo->output))
+			gtk_widget_realize (GTK_WIDGET (netinfo->output));
+		gdk_window_set_cursor ((netinfo->output)->window, cursor);
+		gdk_cursor_destroy (cursor);
 	}
+	
 	netinfo->running = !state;
 
 	netinfo_toggle_button (netinfo);
Index: src/netinfo.h
===================================================================
RCS file: /cvs/gnome/gnome-netinfo/src/netinfo.h,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 netinfo.h
--- src/netinfo.h	23 Jan 2004 15:48:45 -0000	1.1.1.1
+++ src/netinfo.h	14 Mar 2004 19:08:37 -0000
@@ -118,6 +118,7 @@
 const gchar * netinfo_get_host (Netinfo * netinfo);
 const gchar * netinfo_get_user (Netinfo * netinfo);
 void netinfo_set_host (Netinfo * netinfo, const gchar *host);
+gboolean netinfo_is_ipv6_enable ();
 void netinfo_set_user (Netinfo * netinfo, const gchar *user);
 gint netinfo_get_ip_version (Netinfo * netinfo);
 gboolean netinfo_validate_host (Netinfo * netinfo);
Index: src/netstat.c
===================================================================
RCS file: /cvs/gnome/gnome-netinfo/src/netstat.c,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 netstat.c
--- src/netstat.c	23 Jan 2004 15:48:46 -0000	1.1.1.1
+++ src/netstat.c	14 Mar 2004 19:08:37 -0000
@@ -109,14 +109,22 @@
 	
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->routing))) {
 		/* Works for Solaris and Linux */
-		option = g_strdup ("-r");
+		if (netinfo_is_ipv6_enable ()) {
+			option = g_strdup ("-rn -A inet -A inet6");
+		} else {
+			option = g_strdup ("-rn -A inet");
+		}
 	}
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->protocol))) {
 		/* Only works for Solaris */
 #ifdef __FreeBSD__
 	    	option = g_strdup ("-a -f inet -ln");
 #else
-		option = g_strdup ("-A inet -ln");
+		if (netinfo_is_ipv6_enable ()) {
+			option = g_strdup ("-A inet -A inet6 -ln");
+		} else {
+			option = g_strdup ("-A inet -ln");
+		}
 #endif
 	}
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->multicast))) {
@@ -273,7 +281,7 @@
 #ifdef __FreeBSD__
 	if (count == 5 || count == 6 || count == 9 || count == 10) {
 #else
-	if (count == 7 || count == 8) {
+	if (count == 5 || count == 6) {
 #endif
 #ifdef DEBUG
 		g_print ("%s\t%s:%s\t%s\n", data.protocol,
@@ -292,7 +300,7 @@
 		
 		model = gtk_tree_view_get_model (widget);
 		
-		if (protocol_model == NULL || gtk_tree_model_get_n_columns (model) != 4) {
+		if (protocol_model == NULL || protocol_model != model) {
 			clean_gtk_tree_view (widget);
 
 			protocol_model = GTK_TREE_MODEL (gtk_list_store_new
@@ -343,13 +351,16 @@
 	gint a1, a2, a3, a4;
 	gchar s9[30];
 #else
-	gchar s6[30], s7[30];
+	gchar s6[30], laddr[50];
+	gchar *port;
 #endif
 	gint n2, n3;
 
-	line = g_strdelimit (line, ":", ' ');
+	/*line = g_strdelimit (line, ":", ' ');*/
 
 #ifdef __FreeBSD__
+	line = g_strdelimit (line, ":", ' ');
+	
 	count = sscanf (line, NETSTAT_PROTOCOL_FORMAT,
 			data->protocol, &n2, &n3,
 			&a1, &a2, &a3, &a4, data->port_src,
@@ -375,13 +386,29 @@
 	}
 
 #else
-	count = sscanf (line, NETSTAT_PROTOCOL_FORMAT,
+	/*count = sscanf (line, NETSTAT_PROTOCOL_FORMAT,
 			data->protocol, &n2, &n3,
 			data->ip_src, data->port_src, 
 			s6, s7, data->state);
 	
 	if (count == 7) {
 		bzero (&(data)->state, 30);
+		}*/
+	count = sscanf (line, NETSTAT_PROTOCOL_FORMAT,
+			data->protocol, &n2, &n3,
+			laddr, s6, data->state);
+
+	port = g_strrstr (laddr, ":");
+
+	if (port != NULL) {
+		g_strlcpy (data->ip_src, laddr, 50 * sizeof (gchar));
+		data->ip_src[strlen (laddr) - strlen (port)] = '\0';
+		port ++;
+		g_strlcpy (data->port_src, port, 30 * sizeof (gchar));
+	}
+
+	if (count == 5) {
+		bzero (&(data)->state, 30);
 	}
 #endif
 	
@@ -448,7 +475,7 @@
 #ifdef __FreeBSD__
 	if (count == 6) {
 #else
-	if (count == 8) {
+	if ((count == 8) || (count == 7)) {
 #endif
 #ifdef DEBUG
 		g_print ("%s\t%s:%s\t%d\t%s\n", data.destination,
@@ -468,7 +495,7 @@
 		
 		model = gtk_tree_view_get_model (widget);
 		
-		if (route_model == NULL || gtk_tree_model_get_n_columns (model) != 4) {
+		if (route_model == NULL || route_model != model) {
 			clean_gtk_tree_view (widget);
 			
 			route_model = GTK_TREE_MODEL (gtk_list_store_new
@@ -517,6 +544,10 @@
 	gint count = 0;
 	gchar flags[30];
 	gint ref, use;
+#ifndef __FreeBDD__
+	gchar dest[50];
+	gchar **items;
+#endif
 
 #ifdef __FreeBSD__
 	count = sscanf (line, NETSTAT_ROUTE_FORMAT,
@@ -524,14 +555,30 @@
 			data->gateway, flags,
 			&ref, &use, data->iface);
 #else
-
 	count = sscanf (line, NETSTAT_ROUTE_FORMAT,
 			data->destination,
-			data->gateway, data->netmask, 
-			flags, &(data)->metric, &ref, &use, 
+			data->gateway, data->netmask,
+			flags, &(data)->metric, &ref, &use,
 			data->iface);
-#endif
+
+	if (count == 6) {
+		count = sscanf (line, NETSTAT_ROUTE6_FORMAT,
+				dest, data->netmask,
+				flags, &(data)->metric,
+				&ref, &use, data->iface);
+
+		items = NULL;
+
+		items = g_strsplit (dest, "/", 2);
+		if (items != NULL) {
+			g_strlcpy (data->destination, items[0], 50 * sizeof (gchar));
+			g_strlcpy (data->netmask, items[1], 50 * sizeof (gchar));
+
+			g_strfreev (items);
+		}
+	}
 	
+#endif
 	return count;
 }
 
@@ -581,7 +628,6 @@
 netstat_multicast_tree_insert (GtkTreeView *widget, gchar *line)
 {
 	GtkTreeIter iter, sibling;
-	/*GList *columns;*/
 	GtkTreePath *path;
 	GtkTreeModel *model;
 	gint count;
@@ -591,6 +637,7 @@
 	g_return_if_fail (line != NULL);
 
 	count = strip_multicast_line (line, &data);
+
 	if (count == 3) {
 #ifdef DEBUG
 		g_print ("%s\t%s\t%s\n", data.iface,
@@ -609,7 +656,7 @@
 
 		model = gtk_tree_view_get_model (widget);
 		
-		if (multicast_model == NULL || gtk_tree_model_get_n_columns (model) != 3) {
+		if (multicast_model == NULL || multicast_model != model) {
 			clean_gtk_tree_view (widget);
 			
 			multicast_model = GTK_TREE_MODEL (gtk_list_store_new
@@ -661,6 +708,7 @@
 	count = sscanf (line, NETSTAT_MULTICAST_FORMAT,
 			data->iface,
 			&members, data->group);
+
 	snprintf ((data)->members, 30, "%d", members);
 	
 	return count;
Index: src/netstat.h
===================================================================
RCS file: /cvs/gnome/gnome-netinfo/src/netstat.h,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 netstat.h
--- src/netstat.h	23 Jan 2004 15:48:46 -0000	1.1.1.1
+++ src/netstat.h	14 Mar 2004 19:08:38 -0000
@@ -25,9 +25,11 @@
 
 #if defined(__linux__)
 	/* proto 0 0 ip port ip port state */
-#   define NETSTAT_PROTOCOL_FORMAT "%s %d %d %s %s %s %s %s" 
-#   define NETSTAT_ROUTE_FORMAT "%s %s %s %s %d %d %d %s" 
-#   define NETSTAT_MULTICAST_FORMAT "%s %d %s" 
+#   define NETSTAT_PROTOCOL_FORMAT "%s %d %d %s %s %s"
+#   define NETSTAT_ROUTE_FORMAT "%s %s %s %s %d %d %d %s"
+#   define NETSTAT_ROUTE6_FORMAT "%s %s %s %d %d %d %s"
+#   define NETSTAT_MULTICAST_FORMAT "%s %d %s"
+
 #elif defined(__FreeBSD__)
 #   define NETSTAT_PROTOCOL_FORMAT "%s %d %d %d.%d.%d.%d.%s %s %s"
 #   define ALT_NETSTAT_PROTOCOL_FORMAT "%s %d %d *.%s %s %s"
@@ -47,7 +49,7 @@
 	
 struct _netstat_protocol_data {
 	gchar protocol[30];
-	gchar ip_src[30];
+	gchar ip_src[50];
 	gchar port_src[30];
 //	gint  port_src;
 	gchar state[30];
@@ -56,8 +58,8 @@
 typedef struct _netstat_route_data netstat_route_data;
 	
 struct _netstat_route_data {
-	gchar destination[30];
-	gchar gateway[30];
+	gchar destination[50];
+	gchar gateway[50];
 	gchar netmask[30];
 	gint metric;
 	gchar iface[30];

Attachment: signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente



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