[gnome-network]More IPv6 support



I continue with the IPv6 support in gnome-network, now I have attached
to this mail a patch for the gnome-remote-shell :-)

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 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-remote-shell.c.diff
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-network/network-utilities/ChangeLog,v
retrieving revision 1.20
diff -u -u -r1.20 ChangeLog
--- ChangeLog	3 Oct 2003 12:33:59 -0000	1.20
+++ ChangeLog	3 Oct 2003 17:09:32 -0000
@@ -1,3 +1,8 @@
+2003-10-03  Carlos Garcia Campos <carlosgc gnome org>
+
+	* gnome-remote-shell.c (check_network_status, validate_host,
+	  get_ip_version): added IPv6 support
+
 2003-09-03  Emil Soleyman-Zomalan <emil nishra com>
 
 	* gnome-remote-shell.c: made it work correctly with any gnome-terminal
Index: gnome-remote-shell.c
===================================================================
RCS file: /cvs/gnome/gnome-network/network-utilities/gnome-remote-shell.c,v
retrieving revision 1.17
diff -u -u -r1.17 gnome-remote-shell.c
--- gnome-remote-shell.c	3 Oct 2003 12:33:59 -0000	1.17
+++ gnome-remote-shell.c	3 Oct 2003 17:09:32 -0000
@@ -39,6 +39,11 @@
 #define SSH_PORT 22
 #define TELNET_PORT 23
 
+enum {
+	IPV4,
+	IPV6
+};
+
 static GConfClient *conf_client;
 static GtkWidget *dialog;
 static GtkWidget *ssh_method;
@@ -56,6 +61,7 @@
 void	port_default_toggled_cb (GtkToggleButton *button, gpointer user_data);
 void	radio_button_toggled_cb (GtkToggleButton *button, gpointer user_data);
 
+static gint     get_ip_version (const gchar *ip_address);
 static gboolean check_network_status (const gchar *host, gint port);
 static void	activate_shell (void);
 static void	set_spin_from_config (GtkWidget *spin, const gchar *key, gint default_value);
@@ -113,37 +119,94 @@
 	}
 }
 
+static gint
+get_ip_version (const gchar *ip_address)
+{
+	struct hostent *host;
+
+	g_return_val_if_fail (ip_address != NULL, -1);
+
+	if (strlen (ip_address) > 0) {
+		host = gethostbyname2 (ip_address, PF_INET6);
+		if (host == NULL) {
+			host = gethostbyname2 (ip_address, AF_INET);
+			if (host == NULL)
+				return -1;
+			else
+				return IPV4;
+
+			return -1;
+		}
+		else
+			return IPV6;
+	}
+
+	return -1;
+}
+
 static gboolean
 check_network_status (const gchar *host, gint port)
 {
 	struct sockaddr_in *addr;
+	struct sockaddr_in6 *addr6;
 	struct hostent *hostname;
 	gint sd;
 	gchar *msgerror;
 
-	hostname = gethostbyname (host);
-
-	addr = (struct sockaddr_in *) g_malloc (sizeof (struct sockaddr_in));
+	switch (get_ip_version (host))
+	{
+	case IPV4:
+		hostname = gethostbyname2 (host, AF_INET);
 
-	sd = socket (AF_INET, SOCK_STREAM, 0);
-	addr->sin_family = AF_INET;
-	addr->sin_port = g_htons (port);
-	addr->sin_addr = *(struct in_addr *) hostname->h_addr;
+		addr = (struct sockaddr_in *) g_malloc (sizeof (struct sockaddr_in));
+		
+		sd = socket (AF_INET, SOCK_STREAM, 0);
+		addr->sin_family = AF_INET;
+		addr->sin_port = g_htons (port);
+		addr->sin_addr = *(struct in_addr *) hostname->h_addr;
+		
+		errno = 0;
+		if (connect (sd, (struct sockaddr *) addr, sizeof (struct sockaddr_in)) != 0) {
+			msgerror = (gchar *) strerror (errno);
+			msgerror = g_locale_to_utf8 (msgerror, strlen (msgerror), NULL, NULL, NULL);
+			gnome_error_dialog_parented (_(msgerror), GTK_WINDOW (dialog));
+			g_free (addr);
+			
+			return FALSE;
+		}
+		shutdown (sd, 2);
 
-	errno = 0;
-	if (connect (sd, (struct sockaddr *) addr, sizeof (struct sockaddr_in)) != 0)
-	{
-		msgerror = (gchar *) strerror (errno);
-		msgerror = g_locale_to_utf8 (msgerror, strlen (msgerror), NULL, NULL, NULL);
-		gnome_error_dialog_parented (_(msgerror), GTK_WINDOW (dialog));
 		g_free (addr);
 
-		return FALSE;
-	}
-	shutdown (sd, 2);
+		break;
+	case IPV6:
+		hostname = gethostbyname2 (host, PF_INET6);
+
+		addr6 = (struct sockaddr_in6 *) g_malloc (sizeof (struct sockaddr_in6));
+
+		sd = socket (PF_INET6, SOCK_STREAM, 0);
+		addr6->sin6_family = PF_INET6;
+		addr6->sin6_port = g_htons (port);
+		addr6->sin6_addr = *(struct in6_addr *) hostname->h_addr;
+
+		errno = 0;
+		if (connect (sd, (struct sockaddr *) addr6, sizeof (struct sockaddr_in6)) != 0) {
+			msgerror = (gchar *) strerror (errno);
+			msgerror = g_locale_to_utf8 (msgerror, strlen (msgerror), NULL, NULL, NULL);
+			gnome_error_dialog_parented (_(msgerror), GTK_WINDOW (dialog));
+			g_free (addr6);
+
+			return FALSE;
+		}
+		shutdown (sd, 2);
 
-	g_free (addr);
+		g_free (addr6);
 
+		break;
+	case -1:
+		return FALSE;
+	}
+	
 	return TRUE;
 }
 
@@ -181,7 +244,7 @@
 		return;
 	}
 					   
-	if (validate_host(host) == FALSE)
+	if (validate_host (host) == FALSE)
 		return;
 
 	if (check_network_status (host, port) == FALSE)
@@ -350,10 +413,14 @@
 {
 	struct hostent *hostname;
 
-	hostname = gethostbyname(host);
+	hostname = gethostbyname2 (host, PF_INET6);
 	if (hostname == NULL) {
-		gnome_error_dialog_parented (_("The host cannot be found."), GTK_WINDOW (dialog));
-		return FALSE;
+		hostname = gethostbyname2 (host, AF_INET);
+		if (hostname == NULL) {
+			gnome_error_dialog_parented (_("The host cannot be found."),
+						     GTK_WINDOW (dialog));
+			return FALSE;
+		}
 	}
 	
 	return TRUE;

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]