diff options
author | Benoît Dejean <bdejean@src.gnome.org> | 2008-04-21 18:59:20 +0000 |
---|---|---|
committer | Benoît Dejean <bdejean@src.gnome.org> | 2008-04-21 18:59:20 +0000 |
commit | c1b95643a8dc076b0d695fb9261e575ec6a5fa30 (patch) | |
tree | 28f41988017b9ffc889d559eed4cac0500bebe16 | |
parent | be8a3714818ff6826a2722d4ed85ff0765ecaa3f (diff) | |
download | libgtop-c1b95643a8dc076b0d695fb9261e575ec6a5fa30.tar.gz |
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.
svn path=/trunk/; revision=2738
-rw-r--r-- | configure.in | 4 | ||||
-rw-r--r-- | examples/openfiles.c | 7 | ||||
-rw-r--r-- | include/glibtop/procopenfiles.h | 6 | ||||
-rw-r--r-- | sysdeps/linux/procopenfiles.c | 58 |
4 files changed, 70 insertions, 5 deletions
diff --git a/configure.in b/configure.in index 63f2ed7f..0447600c 100644 --- a/configure.in +++ b/configure.in @@ -3,7 +3,7 @@ dnl Configure script for the Gnome library 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 @@ m4_define([libgtop_current], [8]) 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 diff --git a/examples/openfiles.c b/examples/openfiles.c index 9811fe0e..aa6e1bee 100644 --- a/examples/openfiles.c +++ b/examples/openfiles.c @@ -37,9 +37,16 @@ static void show_open_files(pid_t pid) 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"); } } diff --git a/include/glibtop/procopenfiles.h b/include/glibtop/procopenfiles.h index 3509737a..b86c2eee 100644 --- a/include/glibtop/procopenfiles.h +++ b/include/glibtop/procopenfiles.h @@ -53,7 +53,8 @@ enum glibtop_file_type { 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 @@ struct _glibtop_open_files_entry 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; diff --git a/sysdeps/linux/procopenfiles.c b/sysdeps/linux/procopenfiles.c index 6aa37c4c..c05bdb69 100644 --- a/sysdeps/linux/procopenfiles.c +++ b/sysdeps/linux/procopenfiles.c @@ -97,6 +97,48 @@ get_all(const char *filename, LineParser parser) +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 @@ glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pi { 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 @@ glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pi 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 @@ glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pi 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; |