gnome-system-monitor r2419 - in trunk: . src



Author: bdejean
Date: Mon May 26 17:04:55 2008
New Revision: 2419
URL: http://svn.gnome.org/viewvc/gnome-system-monitor?rev=2419&view=rev

Log:
Add IPv6 and IDN support to open files dialog.
Patch by Mark McClelland <mark ovcam org>.
Closes #528409.


Modified:
   trunk/configure.in
   trunk/src/openfiles.cpp

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Mon May 26 17:04:55 2008
@@ -26,7 +26,7 @@
 GLIB_REQUIRED=2.16.0
 GCONF_REQUIRED=1.1.5
 LIBWNCK_REQUIRED=2.5.0
-LIBGTOP_REQUIRED=2.19.3
+LIBGTOP_REQUIRED=2.23.1
 GTK_REQUIRED=2.12.0
 GNOME_ICON_THEME_REQUIRED=2.15.3
 GTKMM_REQUIRED=2.8

Modified: trunk/src/openfiles.cpp
==============================================================================
--- trunk/src/openfiles.cpp	(original)
+++ trunk/src/openfiles.cpp	Mon May 26 17:04:55 2008
@@ -33,8 +33,10 @@
 		return _("file");
 	case GLIBTOP_FILE_TYPE_PIPE:
 		return _("pipe");
+	case GLIBTOP_FILE_TYPE_INET6SOCKET:
+		return _("IPv6 network connection");
 	case GLIBTOP_FILE_TYPE_INETSOCKET:
-		return _("network connection");
+		return _("IPv4 network connection");
 	case GLIBTOP_FILE_TYPE_LOCALSOCKET:
 		return _("local socket");
 	default:
@@ -45,26 +47,34 @@
 
 
 static char *
-friendlier_hostname(const char *dotted_quad, int port)
+friendlier_hostname(const char *addr_str, int port)
 {
-	struct in_addr addr4;
-	struct hostent *host;
+	struct addrinfo hints = { };
+	struct addrinfo *res = NULL;
+	char hostname[NI_MAXHOST];
+	char service[NI_MAXSERV];
+	char port_str[6];
 
-	if(inet_pton(AF_INET, dotted_quad, &addr4) <= 0)
-		goto failsafe;
+	if (!addr_str[0]) return g_strdup("");
+
+	snprintf(port_str, sizeof port_str, "%d", port);
 
-	// cast needed because first argument may be const char*
-	// or const void*
-	host = gethostbyaddr(reinterpret_cast<const char*>(&addr4), sizeof addr4, AF_INET);
+	hints.ai_family = AF_UNSPEC;
+	hints.ai_socktype = SOCK_STREAM;
+
+	if (getaddrinfo(addr_str, port_str, &hints, &res))
+		goto failsafe;
 
-	if(!host)
+	if (getnameinfo(res->ai_addr, res->ai_addrlen, hostname,
+			sizeof hostname, service, sizeof service, NI_IDN))
 		goto failsafe;
 
-	return g_strdup_printf("%s:%d", host->h_name, port);
+	if (res) freeaddrinfo(res);
+	return g_strdup_printf("%s, TCP port %d (%s)", hostname, port, service);
 
  failsafe:
-	if(!dotted_quad[0]) return g_strdup("");
-	return g_strdup_printf("%s:%d", dotted_quad, port);
+	if (res) freeaddrinfo(res);
+	return g_strdup_printf("%s, TCP port %d", addr_str, port);
 }
 
 
@@ -85,6 +95,7 @@
 		object = g_strdup(openfiles->info.file.name);
 		break;
 
+	case GLIBTOP_FILE_TYPE_INET6SOCKET:
 	case GLIBTOP_FILE_TYPE_INETSOCKET:
 		object = friendlier_hostname(openfiles->info.sock.dest_host,
 					     openfiles->info.sock.dest_port);



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