Re: [gnome-network]IPv6 support



El mar, 30-09-2003 a las 23:07, Rodrigo Moya escribió:
> On Mon, 2003-09-29 at 21:49 +0200, Carlos Garcia Campos wrote:
> > 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
> > 
> cool! Since Germán is not approving this patch, I'll approve it
> myself :-)

thanks ;-)

> It looks good to me, although it's missing a ChangeLog entry and it
> doesn't use GNOME coding guidelines in some places, like the { for an if
> starting in its own line (it should be in the same line as the if
> sentence).

ok, I fixed it

> Apart from that, it looks good, and when you send the fixed patch, if
> Germán or William dont say anything, I'll apply it.
> 
> thanks again for the patch, and sorry for the delay

I have attached another patch to this mail that fixes GNOME coding
guidelines errors and includes a Changelog entry. It also includes IPv6
support for the scanning tool

Currently, the IPv6 situation in gnome-network is:

info: None
ping: full IPv6 support
netstat: I am working on it. I think is better to use -putan parameters
instead of -A inet for the active services view. What do you think?
traceroute: full IPv6 support
scan: full IPv6 support
lookup: full IPv6 support, is not necessary to do any changes because
dig supports IPv6 natively


-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 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-scan.diff
? ipv6-ping-tracer.diff
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v
retrieving revision 1.92
diff -u -u -r1.92 ChangeLog
--- ChangeLog	31 Aug 2003 16:18:24 -0000	1.92
+++ ChangeLog	2 Oct 2003 19:29:55 -0000
@@ -1,3 +1,10 @@
+2003-10-02  Carlos García Campos <carlosgc gnome org>
+	* netinfo.c (get_ip_version): added a function to get the 
+	  ip version (IPv4 or IPv6) of a host or ip address
+	* ping.c (ping_do, strip_line): IPv6 support
+	* scan.c (scan_do): IPv6 support
+	* traceroute.c (traceroute_do): IPv6 support
+	  
 2003-08-31  German Poo-Caaman~o  <gpoo ubiobio cl>
 
 	* lookup.c (lookup_create_model):
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	2 Oct 2003 19:29:55 -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,47 @@
 	    gtk_entry_get_text (GTK_ENTRY
 				(gnome_entry_gtk_entry
 				 (GNOME_ENTRY (netinfo->user))));
+}
+
+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	2 Oct 2003 19:29:55 -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	2 Oct 2003 19:29:55 -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	2 Oct 2003 19:29:55 -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: scan.c
===================================================================
RCS file: /cvs/gnome/gnome-network/gnome-netinfo/scan.c,v
retrieving revision 1.5
diff -u -u -r1.5 scan.c
--- scan.c	25 Jul 2003 13:33:54 -0000	1.5
+++ scan.c	2 Oct 2003 19:29:55 -0000
@@ -52,6 +52,7 @@
 	GtkTreeModel *model;
 	
 	struct sockaddr_in addr;
+	struct sockaddr_in6 addr6;
 	struct hostent *hp = NULL;
 	struct servent *service = NULL;
 	gint i, sock, start_port = 1, end_port = 7000;
@@ -62,6 +63,7 @@
 	gint nread;
 	gchar buf[SIZE];
 	gchar *service_name = NULL;
+	gint ip_version, pf;
 
 	g_return_if_fail (netinfo != NULL);
 
@@ -73,13 +75,25 @@
 		gtk_list_store_clear (GTK_LIST_STORE (model));
 	}
 	
-	if ((hp = gethostbyname (host)) == NULL) {
+	switch (ip_version = netinfo_get_ip_version (netinfo))
+	{
+	case -1:
 #ifdef DEBUG
 		g_print ("Error: Host unkown\n");
 #endif /* DEBUG */
-		g_return_if_fail (hp != NULL);
+		return;
+		/*g_return_if_fail (hp != NULL);*/
+		break;
+	case IPV4:
+		pf = PF_INET;
+		break;
+	case IPV6:
+		pf = PF_INET6;
+		break;
 	}
 
+	hp = gethostbyname2 (host, pf);
+
 	if (pipe (pfd) == -1) {
 		perror ("pipe failed");
 		return;
@@ -96,7 +110,7 @@
 		/* child */
 		close (pfd[0]);
 		for (i = start_port; i <= end_port; i++) {
-			if ((sock = socket (PF_INET, SOCK_STREAM, 0)) == -1) {
+			if ((sock = socket (pf, SOCK_STREAM, 0)) == -1) {
 #ifdef DEBUG			
 				g_print ("Unable to create socket\n");
 #endif /* DEBUG */
@@ -105,12 +119,20 @@
 
 			channel = g_io_channel_unix_new (sock);
 
-			addr.sin_family = PF_INET;
-			addr.sin_addr.s_addr = htonl (INADDR_ANY);
-			addr.sin_port = htons (i);
-			bcopy (hp->h_addr, &addr.sin_addr, hp->h_length);
-			
-			if (connect (sock, (struct sockaddr *) &addr, sizeof (addr)) == 0) {
+			if (ip_version == IPV4) {
+				addr.sin_family = PF_INET;
+				bcopy (hp->h_addr, &addr.sin_addr, hp->h_length);
+				addr.sin_port = htons (i);
+			}
+			else {
+				addr6.sin6_family = PF_INET6;
+				addr6.sin6_flowinfo = 0;
+				bcopy (hp->h_addr, &addr6.sin6_addr, hp->h_length);
+				addr6.sin6_port = htons(i);
+			}
+
+			if ((connect (sock, (struct sockaddr *) &addr, sizeof (addr)) == 0) ||
+			    (connect (sock, (struct sockaddr *) &addr6, sizeof (addr6)) == 0)) {
 				service = getservbyport (htons(i), "tcp");
 
 				if (service != NULL) {
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	2 Oct 2003 19:29:55 -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]