[gnome-network]IPv6 support



I have attached to bug #121755 and to this mail a proposed patch to add
IPv6 support for ping and traceroute tools.
I'm working to add IPv6 support for the other tools

KaL
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 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-ping-tracer.diff
Index: netinfo.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.c,v
retrieving revision 1.13
diff -u -u -r1.13 netinfo.c
--- netinfo.c	31 Jul 2003 20:34:40 -0000	1.13
+++ netinfo.c	29 Sep 2003 19:34:53 -0000
@@ -23,6 +23,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <sys/wait.h>
+#include <netdb.h>
 
 #include "netinfo.h"
 #include "utils.h"
@@ -76,6 +77,107 @@
 	    gtk_entry_get_text (GTK_ENTRY
 				(gnome_entry_gtk_entry
 				 (GNOME_ENTRY (netinfo->user))));
+}
+
+/*static gboolean
+netinfo_ipv4_address_validation (const gchar *ip)
+{
+	gchar **items;
+	gint i;
+
+	items = g_strsplit (ip, ".", 4);
+	if (items == NULL)
+		return FALSE;
+
+	for (i=0; i<4; i++)
+	{
+		if (items[i] == NULL)
+		{
+			g_strfreev (items);
+			return FALSE;
+		}
+		
+		if ((atoi (items[i]) < 0) ||
+		    (atoi (items[i]) > 255))
+		{
+			g_strfreev (items);
+			return FALSE;
+		}
+	}
+
+	g_strfreev (items);
+	return TRUE;
+}
+
+static gboolean
+netinfo_ipv6_address_validation (const gchar *ip)
+{
+	gchar **items;
+	gint i, j;
+
+	items = g_strsplit (ip, ":", 8);
+	if (items == NULL)
+		return FALSE;
+
+	i = 0;
+	while (items[i] != NULL)
+	{
+		for (j=0; j<strlen (items[i]); j++)
+			if (!g_ascii_isxdigit (items[i][j]))
+			{
+				g_strfreev (items);
+				return FALSE;
+			}
+		i++;
+	}
+
+	g_strfreev (items);
+	return TRUE;
+}*/
+	
+gint
+netinfo_get_ip_version (Netinfo * netinfo)
+{
+	gchar *ip;
+	struct hostent *host;
+
+	g_return_val_if_fail (netinfo != NULL, -1);
+	g_return_val_if_fail (GTK_IS_ENTRY
+			      (gnome_entry_gtk_entry
+			       (GNOME_ENTRY (netinfo->host))), -1);
+
+	ip = g_strdup (gtk_entry_get_text
+		       (GTK_ENTRY (gnome_entry_gtk_entry
+				   (GNOME_ENTRY (netinfo->host)))));
+
+	if (strlen (ip) > 0)
+	{
+		host = gethostbyname2 (ip, AF_INET6);
+		if (host == NULL)
+		{
+			host = gethostbyname2 (ip, AF_INET);
+			if (host == NULL)
+				return -1;
+			else
+			{
+				g_free (ip);
+				return IPV4;
+			}
+			
+			return -1;
+		}
+		else
+		{
+			g_free (ip);
+			return IPV6;
+		}
+
+	}
+
+	if (ip != NULL)
+		g_free (ip);
+	
+	return -1;
 }
 
 void
Index: netinfo.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.h,v
retrieving revision 1.13
diff -u -u -r1.13 netinfo.h
--- netinfo.h	31 Jul 2003 20:34:40 -0000	1.13
+++ netinfo.h	29 Sep 2003 19:34:53 -0000
@@ -100,6 +100,11 @@
 	NUM_PAGES
 };
 
+enum {
+	IPV4,
+	IPV6
+};
+
 #endif  /* __NETINFO__ */
 
 /* Generic functions */
@@ -110,6 +115,7 @@
 gushort netinfo_get_count (Netinfo * netinfo);
 const gchar * netinfo_get_host (Netinfo * netinfo);
 const gchar * netinfo_get_user (Netinfo * netinfo);
+gint netinfo_get_ip_version (Netinfo * netinfo);
 void netinfo_toggle_button (Netinfo * netinfo);
 void netinfo_toggle_state (Netinfo * netinfo, gboolean state,
 			   gpointer user_data);
Index: ping.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ping.c,v
retrieving revision 1.19
diff -u -u -r1.19 ping.c
--- ping.c	31 Aug 2003 16:18:24 -0000	1.19
+++ ping.c	29 Sep 2003 19:34:53 -0000
@@ -26,7 +26,7 @@
 #include "ping.h"
 #include "utils.h"
 
-static gint strip_line (gchar * line, ping_data * data);
+static gint strip_line (gchar * line, ping_data * data, Netinfo * netinfo);
 static gint strip_total_line (gchar * line, gint * packet_total);
 static GtkTreeModel *ping_create_model (GtkTreeView * widget);
 static gboolean ping_output_foreach (GtkTreeModel * model, GtkTreePath * path,
@@ -59,6 +59,7 @@
 	gchar stmp[128];
 	gchar *program;
 	GtkWidget *parent;
+	gint ip_version;
 
 	g_return_if_fail (netinfo != NULL);
 
@@ -104,20 +105,43 @@
 	gtk_text_buffer_delete (buffer, &start, &end);
 */
 	parent = gtk_widget_get_toplevel (netinfo->output);
-	
-	program = util_find_program_dialog ("ping", parent);
+
+	ip_version = netinfo_get_ip_version (netinfo);
+	switch (ip_version)
+	{
+	case IPV4:
+		program = util_find_program_dialog ("ping", parent);
+		break;
+	case IPV6:
+		program = util_find_program_dialog ("ping6", parent);
+		
+		break;
+	case -1:
+		/*invalid host or ip address*/
+		return;
+	}
 	
 	if (program != NULL) {
 #if defined(__sun__) || defined(__hpux__)
-		command =
-			g_strdup_printf (PING_PROGRAM_FORMAT, program, host,
-	//	    g_strdup_printf (PING_PROGRAM_FORMAT, PING_PROGRAM, host,
-					 count);
+		if (ip_version == IPV4)
+			command =
+				g_strdup_printf (PING_PROGRAM_FORMAT, program, host,
+	 //	    g_strdup_printf (PING_PROGRAM_FORMAT, PING_PROGRAM, host,	
+						 count);
+		else
+			command =
+				g_strdup_printf (PING_PROGRAM_FORMAT_6, program, host,
+						 count);
 #else
-		command =
-			g_strdup_printf (PING_PROGRAM_FORMAT, program, count,
+		if (ip_version == IPV4)
+			command =
+				g_strdup_printf (PING_PROGRAM_FORMAT, program, count,
 	//	    g_strdup_printf (PING_PROGRAM_FORMAT, PING_PROGRAM, count,
-					 host);
+						 host);
+		else
+			command =
+				g_strdup_printf (PING_PROGRAM_FORMAT_6, program, count,
+						 host);
 #endif
 
 /*	command =
@@ -195,7 +219,7 @@
 	pkt_loss = GTK_LABEL (netinfo->packets_loss);
 
 	if (len > 0) {		/* there are data to show */
-		count = strip_line (line, &data);
+		count = strip_line (line, &data, netinfo);
 		if ((count == 5) || (count == 6)) {
 
 			/* Creation of GtkTreeView */
@@ -303,11 +327,13 @@
 }
 
 static gint
-strip_line (gchar * line, ping_data * data)
+strip_line (gchar * line, ping_data * data, Netinfo * netinfo)
 {
 	gint count;
 
-	line = g_strdelimit (line, ":", ' ');
+	if (netinfo_get_ip_version (netinfo) == IPV4)
+		line = g_strdelimit (line, ":", ' ');
+
 #ifdef PING_PARAMS_5
 	count = sscanf (line, PING_FORMAT,
 			&(data)->bytes, data->ip, &(data)->icmp_seq,
@@ -321,6 +347,7 @@
 	if (count != 5 && count != 6) {
 
 	}
+	/*printf ("DBG: bytes: %d, ip: %s, icmp_seq: %d\n", data->bytes, data->ip, data->icmp_seq);*/
 	return count;
 }
 
Index: ping.h
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ping.h,v
retrieving revision 1.11
diff -u -u -r1.11 ping.h
--- ping.h	21 Jul 2003 01:13:52 -0000	1.11
+++ ping.h	29 Sep 2003 19:34:53 -0000
@@ -27,6 +27,7 @@
 /* FIXME: Add BSD support */
 #if defined(__linux__) || defined(__OSF__)
 #   define PING_PROGRAM_FORMAT "%s ping -c %d -n %s"
+#   define PING_PROGRAM_FORMAT_6 "%s ping6 -c %d -n %s"
 #   define PING_FORMAT "%d bytes from %s icmp_seq=%d ttl=%d time=%s %s"
 #   define PING_PARAMS_6
 #elif defined(__sun__) 
Index: traceroute.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/traceroute.c,v
retrieving revision 1.16
diff -u -u -r1.16 traceroute.c
--- traceroute.c	31 Aug 2003 16:18:24 -0000	1.16
+++ traceroute.c	29 Sep 2003 19:34:53 -0000
@@ -64,13 +64,25 @@
 
 	parent = gtk_widget_get_toplevel (netinfo->output);
 	
-	program = util_find_program_in_path ("tcptraceroute", NULL);
-	g_print ("tcptraceroute: %s\n", program);
-	if (program != NULL) {
-		program_name = g_strdup ("tcptraceroute");
-	} else {
-		program = util_find_program_dialog ("traceroute", parent);
-		program_name = g_strdup ("traceroute");
+	switch (netinfo_get_ip_version (netinfo))
+	{
+	case IPV4:
+		program = util_find_program_in_path ("tcptraceroute", NULL);
+		g_print ("tcptraceroute: %s\n", program);
+		if (program != NULL) {
+			program_name = g_strdup ("tcptraceroute");
+		} else {
+			program = util_find_program_dialog ("traceroute", parent);
+			program_name = g_strdup ("traceroute");
+		}
+		break;
+	case IPV6:
+		program = util_find_program_in_path ("traceroute6", NULL);
+		program_name = g_strdup ("traceroute6");
+		break;
+	default:
+		program = NULL;
+		break;
 	}
 
 	if (program != NULL) {

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]