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
This commit is contained in:
@@ -3,7 +3,7 @@ dnl Configure script for the Gnome library
|
|||||||
dnl
|
dnl
|
||||||
|
|
||||||
m4_define([libgtop_major_version], [2])
|
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_micro_version], [1])
|
||||||
m4_define([libgtop_version], [libgtop_major_version.libgtop_minor_version.libgtop_micro_version])
|
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 increment any time the source changes; set to
|
||||||
dnl 0 if you increment CURRENT
|
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 increment if any interfaces have been added; set to 0
|
||||||
dnl if any interfaces have been removed. removal has
|
dnl if any interfaces have been removed. removal has
|
||||||
|
@@ -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);
|
printf("socket %s:%d\n", files[i].info.sock.dest_host, files[i].info.sock.dest_port);
|
||||||
break;
|
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:
|
case GLIBTOP_FILE_TYPE_LOCALSOCKET:
|
||||||
printf("localsocket %s\n", files[i].info.localsock.name);
|
printf("localsocket %s\n", files[i].info.localsock.name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("unknown type\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,7 +53,8 @@ enum glibtop_file_type {
|
|||||||
GLIBTOP_FILE_TYPE_FILE = 1,
|
GLIBTOP_FILE_TYPE_FILE = 1,
|
||||||
GLIBTOP_FILE_TYPE_PIPE = 2,
|
GLIBTOP_FILE_TYPE_PIPE = 2,
|
||||||
GLIBTOP_FILE_TYPE_INETSOCKET = 4,
|
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;
|
typedef struct _glibtop_open_files_entry glibtop_open_files_entry;
|
||||||
@@ -65,7 +66,8 @@ struct _glibtop_open_files_entry
|
|||||||
int fd;
|
int fd;
|
||||||
guint16 type; /* An "enum glibtop_file_type" value. */
|
guint16 type; /* An "enum glibtop_file_type" value. */
|
||||||
union {
|
union {
|
||||||
/* When type == GLIBTOP_FILE_TYPE_INETSOCKET */
|
/* When type == GLIBTOP_FILE_TYPE_INETSOCKET or
|
||||||
|
* when type == GLIBTOP_FILE_TYPE_INET6SOCKET */
|
||||||
struct {
|
struct {
|
||||||
char dest_host[GLIBTOP_OPEN_DEST_HOST_LEN+1];
|
char dest_host[GLIBTOP_OPEN_DEST_HOST_LEN+1];
|
||||||
int dest_port;
|
int dest_port;
|
||||||
|
@@ -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
|
struct InetSocketEntry
|
||||||
{
|
{
|
||||||
char host[GLIBTOP_OPEN_DEST_HOST_LEN + 1];
|
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];
|
char fn [BUFSIZ];
|
||||||
GArray *entries;
|
GArray *entries;
|
||||||
GHashTable *inet_sockets = NULL, *local_sockets = NULL;
|
GHashTable *inet6_sockets = NULL, *inet_sockets = NULL, *local_sockets = NULL;
|
||||||
struct dirent *direntry;
|
struct dirent *direntry;
|
||||||
DIR *dir;
|
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:["))
|
if(g_str_has_prefix(tgt, "socket:["))
|
||||||
{
|
{
|
||||||
int sockfd;
|
int sockfd;
|
||||||
|
struct Inet6SocketEntry *i6se;
|
||||||
struct InetSocketEntry *ise;
|
struct InetSocketEntry *ise;
|
||||||
struct LocalSocketEntry *lse;
|
struct LocalSocketEntry *lse;
|
||||||
|
|
||||||
|
if(!inet6_sockets) inet6_sockets = get_all_inet6_sockets();
|
||||||
if(!inet_sockets) inet_sockets = get_all_inet_sockets();
|
if(!inet_sockets) inet_sockets = get_all_inet_sockets();
|
||||||
if(!local_sockets) local_sockets = get_all_local_sockets();
|
if(!local_sockets) local_sockets = get_all_local_sockets();
|
||||||
|
|
||||||
sockfd = atoi(tgt + 8);
|
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,
|
ise = g_hash_table_lookup(inet_sockets,
|
||||||
GINT_TO_POINTER(sockfd));
|
GINT_TO_POINTER(sockfd));
|
||||||
|
|
||||||
@@ -257,6 +312,7 @@ glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pi
|
|||||||
closedir (dir);
|
closedir (dir);
|
||||||
|
|
||||||
if(inet_sockets) g_hash_table_destroy(inet_sockets);
|
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);
|
if(local_sockets) g_hash_table_destroy(local_sockets);
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_open_files;
|
buf->flags = _glibtop_sysdeps_proc_open_files;
|
||||||
|
Reference in New Issue
Block a user