libgtop r2738 - in trunk: . examples include/glibtop sysdeps/linux



Author: bdejean
Date: Mon Apr 21 18:59:20 2008
New Revision: 2738
URL: http://svn.gnome.org/viewvc/libgtop?rev=2738&view=rev

Log:
Updated glibtop_get_proc_open_files API so that it also list IPv6 TCP sockets.
Patch by Mark McClelland <mark ovcam org>.
Closes #528175.

WTH do we not care about udp ?

Updated libtool versioning: API addition does not change the ABI, so only
increased revision. gnome-2.22 is 8.1.1 so trunk is now 8.2.1.


Modified:
   trunk/configure.in
   trunk/examples/openfiles.c
   trunk/include/glibtop/procopenfiles.h
   trunk/sysdeps/linux/procopenfiles.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Mon Apr 21 18:59:20 2008
@@ -3,7 +3,7 @@
 dnl
 
 m4_define([libgtop_major_version], [2])
-m4_define([libgtop_minor_version], [22])
+m4_define([libgtop_minor_version], [23])
 m4_define([libgtop_micro_version], [1])
 m4_define([libgtop_version], [libgtop_major_version.libgtop_minor_version.libgtop_micro_version])
 
@@ -12,7 +12,7 @@
 
 dnl  increment any time the source changes; set to
 dnl  0 if you increment CURRENT
-m4_define([libgtop_revision], [1])
+m4_define([libgtop_revision], [2])
 
 dnl  increment if any interfaces have been added; set to 0
 dnl  if any interfaces have been removed. removal has

Modified: trunk/examples/openfiles.c
==============================================================================
--- trunk/examples/openfiles.c	(original)
+++ trunk/examples/openfiles.c	Mon Apr 21 18:59:20 2008
@@ -37,9 +37,16 @@
 		  printf("socket %s:%d\n", files[i].info.sock.dest_host, files[i].info.sock.dest_port);
 		  break;
 
+	  case GLIBTOP_FILE_TYPE_INET6SOCKET:
+		  printf("socket [%s]:%d\n", files[i].info.sock.dest_host, files[i].info.sock.dest_port);
+		  break;
+
 	  case GLIBTOP_FILE_TYPE_LOCALSOCKET:
 		  printf("localsocket %s\n", files[i].info.localsock.name);
 		  break;
+
+	  default:
+		  printf("unknown type\n");
 	  }
   }
 

Modified: trunk/include/glibtop/procopenfiles.h
==============================================================================
--- trunk/include/glibtop/procopenfiles.h	(original)
+++ trunk/include/glibtop/procopenfiles.h	Mon Apr 21 18:59:20 2008
@@ -53,7 +53,8 @@
 	GLIBTOP_FILE_TYPE_FILE		= 1,
 	GLIBTOP_FILE_TYPE_PIPE		= 2,
 	GLIBTOP_FILE_TYPE_INETSOCKET	= 4,
-	GLIBTOP_FILE_TYPE_LOCALSOCKET	= 8
+	GLIBTOP_FILE_TYPE_LOCALSOCKET	= 8,
+	GLIBTOP_FILE_TYPE_INET6SOCKET	= 16
 };
 
 typedef struct _glibtop_open_files_entry glibtop_open_files_entry;
@@ -65,7 +66,8 @@
 	int fd;
 	guint16 type; /* An "enum glibtop_file_type" value. */
 	union {
-		/* When type == GLIBTOP_FILE_TYPE_INETSOCKET */
+		/* When type == GLIBTOP_FILE_TYPE_INETSOCKET or
+		 * when type == GLIBTOP_FILE_TYPE_INET6SOCKET */
 		struct {
 			char dest_host[GLIBTOP_OPEN_DEST_HOST_LEN+1];
 			int dest_port;

Modified: trunk/sysdeps/linux/procopenfiles.c
==============================================================================
--- trunk/sysdeps/linux/procopenfiles.c	(original)
+++ trunk/sysdeps/linux/procopenfiles.c	Mon Apr 21 18:59:20 2008
@@ -97,6 +97,48 @@
 
 
 
+struct Inet6SocketEntry
+{
+	char host[GLIBTOP_OPEN_DEST_HOST_LEN + 1];
+	int port;
+};
+
+
+static void
+inet6_socket_parser(GHashTable *dict, const char* line)
+{
+	struct Inet6SocketEntry *se;
+	int sock;
+	struct in6_addr addr;
+
+	se = g_malloc0(sizeof *se);
+
+	if(sscanf(line, "%*d: %*s %8x%8x%8x%8x:%4x %*x %*x:%*x %*x:%*x %*d %*d %*d %d",
+		  &addr.s6_addr32[0], &addr.s6_addr32[1], &addr.s6_addr32[2],
+		  &addr.s6_addr32[3], &se->port, &sock) != 6)
+		goto error;
+
+	if(!inet_ntop(AF_INET6, &addr, se->host, sizeof se->host))
+		goto error;
+
+	g_hash_table_insert(dict, GINT_TO_POINTER(sock), se);
+	return;
+
+ error:
+	g_free(se);
+}
+
+
+static inline GHashTable *
+get_all_inet6_sockets()
+{
+	return get_all("/proc/net/tcp6", inet6_socket_parser);
+}
+
+
+
+
+
 struct InetSocketEntry
 {
 	char host[GLIBTOP_OPEN_DEST_HOST_LEN + 1];
@@ -178,7 +220,7 @@
 {
 	char fn [BUFSIZ];
 	GArray *entries;
-	GHashTable *inet_sockets = NULL, *local_sockets = NULL;
+	GHashTable *inet6_sockets = NULL, *inet_sockets = NULL, *local_sockets = NULL;
 	struct dirent *direntry;
 	DIR *dir;
 
@@ -209,14 +251,27 @@
 		if(g_str_has_prefix(tgt, "socket:["))
 		{
 			int sockfd;
+			struct Inet6SocketEntry *i6se;
 			struct InetSocketEntry *ise;
 			struct LocalSocketEntry *lse;
 
+			if(!inet6_sockets) inet6_sockets = get_all_inet6_sockets();
 			if(!inet_sockets) inet_sockets = get_all_inet_sockets();
 			if(!local_sockets) local_sockets = get_all_local_sockets();
 
 			sockfd = atoi(tgt + 8);
 
+			i6se = g_hash_table_lookup(inet6_sockets,
+						 GINT_TO_POINTER(sockfd));
+
+			if(i6se) {
+				entry.type = GLIBTOP_FILE_TYPE_INET6SOCKET;
+				entry.info.sock.dest_port = i6se->port;
+				g_strlcpy(entry.info.sock.dest_host, i6se->host,
+					  sizeof entry.info.sock.dest_host);
+				goto found;
+			}
+
 			ise = g_hash_table_lookup(inet_sockets,
 						 GINT_TO_POINTER(sockfd));
 
@@ -257,6 +312,7 @@
 	closedir (dir);
 
 	if(inet_sockets) g_hash_table_destroy(inet_sockets);
+	if(inet6_sockets) g_hash_table_destroy(inet6_sockets);
 	if(local_sockets) g_hash_table_destroy(local_sockets);
 
 	buf->flags = _glibtop_sysdeps_proc_open_files;



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