[gnome-network]IPv6 netstat patch



Proposed patch for the netstat IPv6 support.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 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
? gnome-netinfo.diff
? ipv6-netstat.diff
? ipv6-ping-tracer-scan.diff
? ipv6-ping-tracer.diff
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v
retrieving revision 1.93
diff -u -u -r1.93 ChangeLog
--- ChangeLog	2 Oct 2003 21:26:16 -0000	1.93
+++ ChangeLog	6 Oct 2003 12:08:53 -0000
@@ -1,3 +1,8 @@
+2003-10-06  Carlos García Campos <carlosgc gnome org>
+
+	* netstat.c (get_active_option, strip_protocol_line,
+	  strip_route_line): IPv6 support
+
 2003-10-02  Carlos García Campos <carlosgc gnome org>
 
 	* netinfo.c (get_ip_version): added a function to get the 
Index: netstat.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netstat.c,v
retrieving revision 1.10
diff -u -u -r1.10 netstat.c
--- netstat.c	31 Aug 2003 16:18:24 -0000	1.10
+++ netstat.c	6 Oct 2003 12:08:53 -0000
@@ -105,11 +105,11 @@
 	
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->routing))) {
 		/* Works for Solaris and Linux */
-		option = g_strdup ("-r");
+		option = g_strdup ("-rn -A inet -A inet6");
 	}
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->protocol))) {
 		/* Only works for Solaris */
-		option = g_strdup ("-A inet -ln");
+		option = g_strdup ("-A inet -A inet6 -ln");
 	}
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->multicast))) {
 		/* It works for Solaris and Linux */
@@ -270,7 +270,7 @@
 	g_return_if_fail (line != NULL);
 
 	count = strip_protocol_line (line, &data);
-	if (count == 7 || count == 8) {
+	if (count == 5 || count == 6) {
 #ifdef DEBUG
 		g_print ("%s\t%s:%s\t%s\n", data.protocol,
 			data.ip_src, data.port_src, data.state);
@@ -335,17 +335,24 @@
 strip_protocol_line (gchar * line, netstat_protocol_data *data)
 {
 	gint count = 0;
-	gchar s6[30], s7[30];
+	gchar s6[50], laddr[50];
 	gint n2, n3;
-
-	line = g_strdelimit (line, ":", ' ');
+	gchar *port;
 
 	count = sscanf (line, NETSTAT_PROTOCOL_FORMAT,
-			&(data)->protocol, &n2, &n3,
-			&(data)->ip_src, &(data)->port_src, 
-			s6, s7, &(data)->state);
+				 &(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 == 7) {
+	
+	if (count == 5) {
 		bzero (&(data)->state, 30);
 	}
 	
@@ -409,7 +416,8 @@
 	g_return_if_fail (line != NULL);
 
 	count = strip_route_line (line, &data);
-	if (count == 8) {
+
+	if ((count == 8) || (count == 7)) {
 #ifdef DEBUG
 		g_print ("%s\t%s:%s\t%d\t%s\n", data.destination,
 			data.gateway, data.netmask, data.metric,
@@ -477,13 +485,30 @@
 	gint count = 0;
 	gchar flags[30];
 	gint ref, use;
+	gchar dest[50];
+	gchar **items;
 
 	count = sscanf (line, NETSTAT_ROUTE_FORMAT,
 			&(data)->destination,
 			&(data)->gateway, &(data)->netmask, 
 			flags, &(data)->metric, &ref, &use, 
 			&(data)->iface);
-	
+
+	if (count == 6) {
+		   count = sscanf (line, NETSTAT_ROUTE6_FORMAT,
+					    dest, &(data)->netmask,
+					    flags, &(data)->metric,
+					    &ref, &use, &(data)->iface);
+
+		   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);
+		   }
+	}
+
 	return count;
 }
 
Index: netstat.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netstat.h,v
retrieving revision 1.4
diff -u -u -r1.4 netstat.h
--- netstat.h	21 Jul 2003 02:31:57 -0000	1.4
+++ netstat.h	6 Oct 2003 12:08:53 -0000
@@ -25,8 +25,9 @@
 
 #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_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" 
 
 #endif
@@ -42,7 +43,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];
@@ -51,8 +52,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]