JBoss Native SVN: r1013 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 06:31:21 -0400 (Mon, 10 Sep 2007)
New Revision: 1013
Modified:
trunk/sight/native/os/linux/volume.c
Log:
Mark RPC filesystem as REMOTE
Modified: trunk/sight/native/os/linux/volume.c
===================================================================
--- trunk/sight/native/os/linux/volume.c 2007-09-10 10:25:15 UTC (rev 1012)
+++ trunk/sight/native/os/linux/volume.c 2007-09-10 10:31:21 UTC (rev 1013)
@@ -237,6 +237,7 @@
CALL_METHOD1(0002, thiz, SIGHT_DRIVE_RAMDISK);
break;
case SIGHT_FS_NFS:
+ case SIGHT_FS_RPC:
CALL_METHOD1(0002, thiz, SIGHT_DRIVE_REMOTE);
break;
case SIGHT_FS_USBFS:
17 years, 4 months
JBoss Native SVN: r1012 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 06:25:15 -0400 (Mon, 10 Sep 2007)
New Revision: 1012
Modified:
trunk/sight/native/share/jnu.c
Log:
Is sunrpc NFS in all cases?
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-10 10:19:47 UTC (rev 1011)
+++ trunk/sight/native/share/jnu.c 2007-09-10 10:25:15 UTC (rev 1012)
@@ -477,6 +477,8 @@
return SIGHT_FS_SFS;
if (memcmp(p, "YSFS", 4) == 0)
return SIGHT_FS_SYSFS;
+ if (memcmp(p, "UNRPC", 5) == 0)
+ return SIGHT_FS_NFS;
else
return SIGHT_FS_UNKNOWN;
break;
17 years, 4 months
JBoss Native SVN: r1011 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 06:19:47 -0400 (Mon, 10 Sep 2007)
New Revision: 1011
Modified:
trunk/sight/native/os/linux/common.c
Log:
Use lstat to figure out the creation time
Modified: trunk/sight/native/os/linux/common.c
===================================================================
--- trunk/sight/native/os/linux/common.c 2007-09-10 09:43:56 UTC (rev 1010)
+++ trunk/sight/native/os/linux/common.c 2007-09-10 10:19:47 UTC (rev 1011)
@@ -86,6 +86,8 @@
if (sb->st_ino == inode) {
/* Wow, we found it */
*pid = (pid_t)strtoul(pent->d_name, NULL, 10);
+ /* Get file times */
+ lstat(fname, sb);
rv = 0;
break;
}
17 years, 4 months
JBoss Native SVN: r1010 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 05:43:56 -0400 (Mon, 10 Sep 2007)
New Revision: 1010
Modified:
trunk/sight/native/os/linux/common.c
trunk/sight/native/os/linux/tcpstat.c
trunk/sight/native/os/linux/udpstat.c
Log:
Figure out the pid of the sockets
Modified: trunk/sight/native/os/linux/common.c
===================================================================
--- trunk/sight/native/os/linux/common.c 2007-09-10 08:13:56 UTC (rev 1009)
+++ trunk/sight/native/os/linux/common.c 2007-09-10 09:43:56 UTC (rev 1010)
@@ -70,6 +70,8 @@
continue;
while (!readdir_r(fd, &fbuf, &fent)) {
char fname[64];
+ if (!fent)
+ break;
if (!apr_isdigit(*fent->d_name)) {
/* Skip non numeric files */
continue;
Modified: trunk/sight/native/os/linux/tcpstat.c
===================================================================
--- trunk/sight/native/os/linux/tcpstat.c 2007-09-10 08:13:56 UTC (rev 1009)
+++ trunk/sight/native/os/linux/tcpstat.c 2007-09-10 09:43:56 UTC (rev 1010)
@@ -32,6 +32,8 @@
#define SIGHT_WANT_LATE_DLL
#include "sight_private.h"
+extern int sight_stat_by_inode(ino_t, uid_t, struct stat *, pid_t *);
+
/*
* TCP statistics implementation
*/
@@ -330,8 +332,8 @@
unsigned long rxq, txq, timelen, retr, inode;
int num, d, uid, timer_run, timeout;
char more[512];
+ struct stat sb;
-
tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
if (!e || !e->tnet)
@@ -388,9 +390,11 @@
/* TODO: See what's the actual value of timelen */
tmo = timelen;
sight_tcpconn_set_tmo(_E, conn, tmo);
- /* TODO: Search for create timestamp and pid by browsing
- * the /proc/pid/fd for matching inode
- */
+ if (!sight_stat_by_inode(inode, uid, &sb, &pid)) {
+ apr_time_t ctime;
+ apr_time_ansi_put(&ctime, sb.st_ctime);
+ sight_tcpconn_set_cts(_E, conn, apr_time_as_msec(ctime));
+ }
sight_tcpconn_set_pid(_E, conn, pid);
sight_tcpconn_set_state(_E, conn, tcp2sstate[state & 0xFF]);
Modified: trunk/sight/native/os/linux/udpstat.c
===================================================================
--- trunk/sight/native/os/linux/udpstat.c 2007-09-10 08:13:56 UTC (rev 1009)
+++ trunk/sight/native/os/linux/udpstat.c 2007-09-10 09:43:56 UTC (rev 1010)
@@ -32,6 +32,8 @@
#define SIGHT_WANT_LATE_DLL
#include "sight_private.h"
+extern int sight_stat_by_inode(ino_t, uid_t, struct stat *, pid_t *);
+
/*
* UDP statistics implementation
*/
@@ -237,6 +239,7 @@
int num, d, uid, timer_run, timeout;
char more[512];
int laddr = 0;
+ struct stat sb;
udpconn_enum_t *e = J2P(handle, udpconn_enum_t *);
@@ -300,9 +303,11 @@
/* TODO: See what's the actual value of timelen */
tmo = timelen;
sight_udpconn_set_tmo(_E, conn, tmo);
- /* TODO: Search for create timestamp and pid by browsing
- * the /proc/pid/fd for matching inode
- */
+ if (!sight_stat_by_inode(inode, uid, &sb, &pid)) {
+ apr_time_t ctime;
+ apr_time_ansi_put(&ctime, sb.st_ctime);
+ sight_udpconn_set_cts(_E, conn, apr_time_as_msec(ctime));
+ }
sight_udpconn_set_pid(_E, conn, pid);
switch (state) {
17 years, 4 months
JBoss Native SVN: r1009 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 04:13:56 -0400 (Mon, 10 Sep 2007)
New Revision: 1009
Modified:
trunk/sight/native/os/linux/common.c
Log:
Fix few typos
Modified: trunk/sight/native/os/linux/common.c
===================================================================
--- trunk/sight/native/os/linux/common.c 2007-09-10 08:08:55 UTC (rev 1008)
+++ trunk/sight/native/os/linux/common.c 2007-09-10 08:13:56 UTC (rev 1009)
@@ -42,7 +42,7 @@
struct dirent *pent, pbuf;
int rv = ENOENT;
- if (!(pd = opendir(PROC_FS_BASE))
+ if (!(pd = opendir(PROC_FS_BASE)))
return errno;
while (!readdir_r(pd, &pbuf, &pent)) {
@@ -50,7 +50,7 @@
struct dirent *fent, fbuf;
char pname[64];
- if (!ent)
+ if (!pent)
break;
if (!apr_isdigit(*pent->d_name)) {
/* Skip non pid directories */
@@ -66,7 +66,7 @@
continue;
}
strcat(pname, "/fd");
- if (!(fd = opendir(pname))
+ if (!(fd = opendir(pname)))
continue;
while (!readdir_r(fd, &fbuf, &fent)) {
char fname[64];
@@ -77,7 +77,7 @@
strcpy(fname, pname);
strcat(fname, "/");
- strcat(fname, fent->dname);
+ strcat(fname, fent->d_name);
if (stat(fname, sb) < 0)
continue;
17 years, 4 months
JBoss Native SVN: r1008 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 04:08:55 -0400 (Mon, 10 Sep 2007)
New Revision: 1008
Added:
trunk/sight/native/os/linux/common.c
Log:
Added common linux code
Added: trunk/sight/native/os/linux/common.c
===================================================================
--- trunk/sight/native/os/linux/common.c (rev 0)
+++ trunk/sight/native/os/linux/common.c 2007-09-10 08:08:55 UTC (rev 1008)
@@ -0,0 +1,97 @@
+/*
+ * SIGHT - System information gathering hybrid tool
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Mladen Turk
+ *
+ */
+
+#include "sight.h"
+#include "sight_local.h"
+#include "sight_types.h"
+#include "sight_private.h"
+#include <unistd.h>
+
+/* Common posix code */
+
+#define PROC_FS_BASE "/proc"
+#define PROC_FS_DIR "/proc/"
+
+int sight_stat_by_inode(ino_t inode, uid_t uid, struct stat *sb, pid_t *pid)
+{
+ DIR *pd;
+ struct dirent *pent, pbuf;
+ int rv = ENOENT;
+
+ if (!(pd = opendir(PROC_FS_BASE))
+ return errno;
+
+ while (!readdir_r(pd, &pbuf, &pent)) {
+ DIR *fd;
+ struct dirent *fent, fbuf;
+ char pname[64];
+
+ if (!ent)
+ break;
+ if (!apr_isdigit(*pent->d_name)) {
+ /* Skip non pid directories */
+ continue;
+ }
+ strcpy(pname, PROC_FS_DIR);
+ strcat(pname, pent->d_name);
+ if (uid >= 0) {
+ struct stat us;
+ if (stat(pname, &us) < 0)
+ continue;
+ if (us.st_uid != uid)
+ continue;
+ }
+ strcat(pname, "/fd");
+ if (!(fd = opendir(pname))
+ continue;
+ while (!readdir_r(fd, &fbuf, &fent)) {
+ char fname[64];
+ if (!apr_isdigit(*fent->d_name)) {
+ /* Skip non numeric files */
+ continue;
+ }
+
+ strcpy(fname, pname);
+ strcat(fname, "/");
+ strcat(fname, fent->dname);
+
+ if (stat(fname, sb) < 0)
+ continue;
+ if (sb->st_ino == inode) {
+ /* Wow, we found it */
+ *pid = (pid_t)strtoul(pent->d_name, NULL, 10);
+ rv = 0;
+ break;
+ }
+ }
+ closedir(fd);
+ if (!rv)
+ break;
+ }
+ closedir(pd);
+ return rv;
+}
Property changes on: trunk/sight/native/os/linux/common.c
___________________________________________________________________
Name: svn:eol-style
+ native
17 years, 4 months
JBoss Native SVN: r1007 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 03:21:38 -0400 (Mon, 10 Sep 2007)
New Revision: 1007
Modified:
trunk/sight/native/os/linux/udpstat.c
Log:
Smarter UDP connection state detection
Modified: trunk/sight/native/os/linux/udpstat.c
===================================================================
--- trunk/sight/native/os/linux/udpstat.c 2007-09-10 07:16:42 UTC (rev 1006)
+++ trunk/sight/native/os/linux/udpstat.c 2007-09-10 07:21:38 UTC (rev 1007)
@@ -236,8 +236,8 @@
unsigned long rxq, txq, timelen, retr, inode;
int num, d, uid, timer_run, timeout;
char more[512];
+ int laddr = 0;
-
udpconn_enum_t *e = J2P(handle, udpconn_enum_t *);
if (!e || !e->tnet)
@@ -268,6 +268,8 @@
inet_ntop(AF_INET, &in4, ras, 64);
else
ras[0] = '\0';
+ if (in4.s_addr == 0 && rp == 0);
+ laddr = 1;
}
else {
/* IPV6 entries */
@@ -290,6 +292,10 @@
sight_inet_ntop6(in6.s6_addr, ras, 64);
else
ras[0] = '\0';
+ if (in6.s6_addr32[0] == 0 && in6.s6_addr32[1] == 0 &&
+ in6.s6_addr32[2] == 0 && in6.s6_addr32[3] == 0 &&
+ rp == 0)
+ laddr = 1;
}
/* TODO: See what's the actual value of timelen */
tmo = timelen;
@@ -301,10 +307,13 @@
switch (state) {
case TCP_ESTABLISHED:
- sight_tcpconn_set_state(_E, conn, 1);
+ sight_tcpconn_set_state(_E, conn, 2);
break;
+ case TCP_CLOSE:
+ sight_tcpconn_set_state(_E, conn, 3);
+ break;
default:
- sight_tcpconn_set_state(_E, conn, 0);
+ sight_tcpconn_set_state(_E, conn, laddr);
break;
}
17 years, 4 months
JBoss Native SVN: r1006 - in trunk/sight: native/os/windows and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 03:16:42 -0400 (Mon, 10 Sep 2007)
New Revision: 1006
Modified:
trunk/sight/java/org/jboss/sight/UdpState.java
trunk/sight/native/os/windows/udpstat.c
Log:
Fix UDP stats
Modified: trunk/sight/java/org/jboss/sight/UdpState.java
===================================================================
--- trunk/sight/java/org/jboss/sight/UdpState.java 2007-09-10 07:08:59 UTC (rev 1005)
+++ trunk/sight/java/org/jboss/sight/UdpState.java 2007-09-10 07:16:42 UTC (rev 1006)
@@ -33,7 +33,8 @@
UNKNOWN( 0),
LISTENING( 1),
- ESTABLISHED( 2);
+ ESTABLISHED( 2),
+ CLOSED( 3);
private int value;
private UdpState(int v)
Modified: trunk/sight/native/os/windows/udpstat.c
===================================================================
--- trunk/sight/native/os/windows/udpstat.c 2007-09-10 07:08:59 UTC (rev 1005)
+++ trunk/sight/native/os/windows/udpstat.c 2007-09-10 07:16:42 UTC (rev 1006)
@@ -320,11 +320,12 @@
}
sight_udpconn_set_pid(_E, conn, pid);
sight_udpconn_set_cts(_E, conn, cts);
+ sight_udpconn_set_state(_E, conn, 0);
la = sight_new_netaddr_class(_E, _O);
sight_netaddr_set_addr(_E, la, las);
sight_netaddr_set_port(_E, la, lp);
- sight_tcpconn_set_local(_E, conn, la);
+ sight_udpconn_set_local(_E, conn, la);
(*_E)->DeleteLocalRef(_E, la);
}
17 years, 4 months
JBoss Native SVN: r1005 - in trunk/sight/native: os/windows and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 03:08:59 -0400 (Mon, 10 Sep 2007)
New Revision: 1005
Modified:
trunk/sight/native/include/sight_version.h
trunk/sight/native/os/windows/libsight.rc
Log:
Increment version aready used for build
Modified: trunk/sight/native/include/sight_version.h
===================================================================
--- trunk/sight/native/include/sight_version.h 2007-09-10 07:04:48 UTC (rev 1004)
+++ trunk/sight/native/include/sight_version.h 2007-09-10 07:08:59 UTC (rev 1005)
@@ -72,7 +72,7 @@
#define SIGHT_MINOR_VERSION 0
/** patch level */
-#define SIGHT_PATCH_VERSION 0
+#define SIGHT_PATCH_VERSION 1
/**
* This symbol is defined for internal, "development" copies of SIGHT.
Modified: trunk/sight/native/os/windows/libsight.rc
===================================================================
--- trunk/sight/native/os/windows/libsight.rc 2007-09-10 07:04:48 UTC (rev 1004)
+++ trunk/sight/native/os/windows/libsight.rc 2007-09-10 07:08:59 UTC (rev 1005)
@@ -39,8 +39,8 @@
#define STR_COMPANY "Red Hat�, Inc."
#define STR_TRADEMARK "� Red Hat Inc."
#define STR_PRODUCT "System information gathering hybrid tool"
-#define STR_VERISON "1.0.0.0"
-#define CSV_VERISON 1,0,0,0
+#define STR_VERISON "1.0.1.0"
+#define CSV_VERISON 1,0,1,0
#define PRIVATE_BUILD 0
#define PRERELEASE_BUILD 0
17 years, 4 months
JBoss Native SVN: r1004 - in trunk/sight/native: include/arch/unix and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 03:04:48 -0400 (Mon, 10 Sep 2007)
New Revision: 1004
Modified:
trunk/sight/native/configure.in
trunk/sight/native/include/arch/unix/sight_private.h
trunk/sight/native/os/linux/tcpstat.c
trunk/sight/native/os/linux/udpstat.c
Log:
Added UDP connection lister implementation
Modified: trunk/sight/native/configure.in
===================================================================
--- trunk/sight/native/configure.in 2007-09-10 06:44:23 UTC (rev 1003)
+++ trunk/sight/native/configure.in 2007-09-10 07:04:48 UTC (rev 1004)
@@ -262,6 +262,7 @@
AC_SUBST(INCLUDE_RULES)
AC_SUBST(INCLUDE_OUTPUTS)
+AC_CHECK_HEADERS([netinet/tcp.h])
dnl ----------------------------- Checking for missing POSIX thread functions
AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
Modified: trunk/sight/native/include/arch/unix/sight_private.h
===================================================================
--- trunk/sight/native/include/arch/unix/sight_private.h 2007-09-10 06:44:23 UTC (rev 1003)
+++ trunk/sight/native/include/arch/unix/sight_private.h 2007-09-10 07:04:48 UTC (rev 1004)
@@ -32,7 +32,30 @@
#include "apr.h"
#include "apr_general.h"
#include <jni.h>
+#include "sight_platform.h"
+#if HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#else
+
+/* These enums are defined in netinet/tcp.h */
+typedef enum {
+ TCP_ESTABLISHED = 1,
+ TCP_SYN_SENT,
+ TCP_SYN_RECV,
+ TCP_FIN_WAIT1,
+ TCP_FIN_WAIT2,
+ TCP_TIME_WAIT,
+ TCP_CLOSE,
+ TCP_CLOSE_WAIT,
+ TCP_LAST_ACK,
+ TCP_LISTEN,
+ TCP_CLOSING /* now a valid state */
+} sight_tcp_state_e;
+
+#endif
+
+
#define SIGHT_PLATFORM_CLASS_PATH SIGHT_CLASS_PATH "platform/unix/"
#define SIGHT_PLATFORM_DECLARE(RT, CL, FN) \
Modified: trunk/sight/native/os/linux/tcpstat.c
===================================================================
--- trunk/sight/native/os/linux/tcpstat.c 2007-09-10 06:44:23 UTC (rev 1003)
+++ trunk/sight/native/os/linux/tcpstat.c 2007-09-10 07:04:48 UTC (rev 1004)
@@ -156,21 +156,6 @@
#define PROC_NET_FS "/proc/net/"
static const char *eiftype = "Unsupported NetworkAddressFamily type";
-/* These enums are used by IPX too. :-( */
-typedef enum {
- TCP_ESTABLISHED = 1,
- TCP_SYN_SENT,
- TCP_SYN_RECV,
- TCP_FIN_WAIT1,
- TCP_FIN_WAIT2,
- TCP_TIME_WAIT,
- TCP_CLOSE,
- TCP_CLOSE_WAIT,
- TCP_LAST_ACK,
- TCP_LISTEN,
- TCP_CLOSING /* now a valid state */
-} sight_tcp_state_e;
-
static int tcp2sstate[] = {
0,
SIGHT_TCP_ESTABLISHED,
@@ -341,7 +326,7 @@
char ras[128] = "";
char ssi[32] = "";
struct in_addr ial, iar;
- jint cts = 0;
+ jint tmo = 0;
unsigned long rxq, txq, timelen, retr, inode;
int num, d, uid, timer_run, timeout;
char more[512];
Modified: trunk/sight/native/os/linux/udpstat.c
===================================================================
--- trunk/sight/native/os/linux/udpstat.c 2007-09-10 06:44:23 UTC (rev 1003)
+++ trunk/sight/native/os/linux/udpstat.c 2007-09-10 07:04:48 UTC (rev 1004)
@@ -91,6 +91,7 @@
sight_unload_class(_E, &_clazzn);
}
+#define PROC_NET_FS "/proc/net/"
static const char *eiftype = "Unsupported NetworkAddressFamily type";
/* Initialize volume enumeration */
@@ -99,69 +100,123 @@
jint iftype,
jlong pool)
{
- sight_arr_t *tgrp;
int i;
+ sight_arr_t *tnet;
int InDatagrams, NoPorts, InErrors, OutDatagrams, RcvbufErrors, SndbufErrors;
+ int NumCons = 0;
UNREFERENCED_O;
- if (!(tgrp = sight_arr_rload("/proc/net/snmp"))) {
+ if (iftype == 1) {
+ if (!(tnet = sight_arr_rload(PROC_NET_FS "sockstat"))) {
+ throwAprException(_E, apr_get_os_error());
+ }
+ for (i = 0; i < tnet->siz; i++) {
+ if (memcmp(tnet->arr.ca[i], "UDP: inuse ", 11) == 0) {
+ NumCons = atoi(tnet->arr.ca[i] + 11);
+ break;
+ }
+ }
+ }
+ else if (iftype == 2) {
+ if (!(tnet = sight_arr_rload(PROC_NET_FS "sockstat6"))) {
+ throwAprException(_E, apr_get_os_error());
+ }
+ for (i = 0; i < tnet->siz; i++) {
+ if (memcmp(tnet->arr.ca[i], "UDP6: inuse ", 12) == 0) {
+ NumCons = atoi(tnet->arr.ca[i] + 12);
+ break;
+ }
+ }
+ }
+ else {
+ throwOSException(_E, eiftype);
+ return;
+ }
+ sight_arr_free(tnet);
+
+ if (!(tnet = sight_arr_rload("/proc/net/snmp"))) {
throwAprException(_E, apr_get_os_error());
}
/* Get the information corresponding to the second entry Tcp: */
- for (i = 0; i < tgrp->siz; i++) {
- if (memcmp(tgrp->arr.ca[i], "Udp:", 4) == 0) {
- if (memcmp(tgrp->arr.ca[i], "Udp: InDatagrams", 16) != 0) {
- sscanf(tgrp->arr.ca[i], "Udp: %d %d %d %d %d %d",
+ for (i = 0; i < tnet->siz; i++) {
+ if (memcmp(tnet->arr.ca[i], "Udp:", 4) == 0) {
+ if (memcmp(tnet->arr.ca[i], "Udp: InDatagrams", 16) != 0) {
+ sscanf(tnet->arr.ca[i], "Udp: %d %d %d %d %d %d",
&InDatagrams, &NoPorts, &InErrors, &OutDatagrams,
&RcvbufErrors, &SndbufErrors);
break;
}
}
}
- sight_arr_free(tgrp);
+ sight_arr_free(tnet);
SET_IFIELD_I(0000, thiz, InDatagrams);
SET_IFIELD_I(0001, thiz, NoPorts);
SET_IFIELD_I(0002, thiz, InErrors);
SET_IFIELD_I(0003, thiz, OutDatagrams);
- /* XXX: We can't get Number of entries in UDP listener table that way.
- SET_IFIELD_I(0004, thiz, s.dwNumAddrs);
- */
+ SET_IFIELD_I(0004, thiz, NumCons);
}
+typedef struct udpconn_enum_t {
+ int type;
+ int idx;
+ sight_arr_t *tnet;
+} udpconn_enum_t;
+
+
SIGHT_EXPORT_DECLARE(jlong, UdpStatistics, enum0)(SIGHT_STDARGS,
jint iftype,
jlong pool)
{
- apr_status_t rc = APR_ENOTIMPL;
+ udpconn_enum_t *e;
+
UNREFERENCED_O;
-
+ if (iftype < 1 || iftype > 2) {
+ throwOSException(_E, eiftype);
+ return 0;
+ }
+ if (!(e = (udpconn_enum_t *)calloc(1, sizeof(udpconn_enum_t)))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ return 0;
+ }
+ e->type = iftype;
if (iftype == 1) {
- /* AF_INET */
- rc = 0;
+ if (!(e->tnet = sight_arr_rload(PROC_NET_FS "udp"))) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
}
- else if (iftype == 2) {
- /* AF_INET6 */
- rc = 0;
- }
else {
- throwOSException(_E, eiftype);
+ if (!(e->tnet = sight_arr_rload(PROC_NET_FS "udp6"))) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
}
- if (rc) {
- throwAprException(_E, APR_FROM_OS_ERROR(rc));
- return;
- }
+
+ return P2J(e);
+cleanup:
+ sight_arr_free(e->tnet);
+ free(e);
+ return 0;
}
/* Get the number of entries */
SIGHT_EXPORT_DECLARE(jint, UdpStatistics, enum1)(SIGHT_STDARGS,
jlong handle)
{
+ udpconn_enum_t *e = J2P(handle, udpconn_enum_t *);
+
UNREFERENCED_STDARGS;
- return 0;
+ if (e && e->tnet) {
+ e->idx = 1;
+ return e->tnet->siz - 1; /* Skip description field */
+ }
+ else
+ return 0;
}
SIGHT_EXPORT_DECLARE(void, UdpStatistics, enum2)(SIGHT_STDARGS,
@@ -169,12 +224,115 @@
jint index,
jlong handle)
{
+ jint pid = -1;
+ jint state = 0;
+ jint lp = 0, rp = 0;
+ jobject la, ra;
+ char las[128] = "";
+ char ras[128] = "";
+ char ssi[32] = "";
+ struct in_addr ial, iar;
+ jint tmo = 0;
+ unsigned long rxq, txq, timelen, retr, inode;
+ int num, d, uid, timer_run, timeout;
+ char more[512];
+
+ udpconn_enum_t *e = J2P(handle, udpconn_enum_t *);
+
+ if (!e || !e->tnet)
+ return;
+ if (e->idx > e->tnet->siz) {
+ /* TODO: Throw overflow */
+ return;
+ }
+ num = sscanf(e->tnet->arr.ca[e->idx],
+ "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s",
+ &d, las, &lp, ras, &rp, &state,
+ &txq, &rxq, &timer_run, &timelen, &retr,
+ &uid, &timeout, &inode, more);
+
+ if (e->type == 1) {
+ /* IPV4 entries */
+ int al;
+ struct in_addr in4;
+
+ al = sscanf(las, "%X", &in4.s_addr);
+ if (al == 1)
+ inet_ntop(AF_INET, &in4, las, 64);
+ else
+ las[0] = '\0';
+
+ al = sscanf(ras, "%X", &in4.s_addr);
+ if (al == 1)
+ inet_ntop(AF_INET, &in4, ras, 64);
+ else
+ ras[0] = '\0';
+ }
+ else {
+ /* IPV6 entries */
+ int al;
+ struct in6_addr in6;
+
+ al = sscanf(las, "%08X%08X%08X%08X",
+ &in6.s6_addr32[0], &in6.s6_addr32[1],
+ &in6.s6_addr32[2], &in6.s6_addr32[3]);
+
+ if (al == 4)
+ sight_inet_ntop6(in6.s6_addr, las, 64);
+ else
+ las[0] = '\0';
+ al = sscanf(ras, "%08X%08X%08X%08X",
+ &in6.s6_addr32[0], &in6.s6_addr32[1],
+ &in6.s6_addr32[2], &in6.s6_addr32[3]);
+
+ if (al == 4)
+ sight_inet_ntop6(in6.s6_addr, ras, 64);
+ else
+ ras[0] = '\0';
+ }
+ /* TODO: See what's the actual value of timelen */
+ tmo = timelen;
+ sight_udpconn_set_tmo(_E, conn, tmo);
+ /* TODO: Search for create timestamp and pid by browsing
+ * the /proc/pid/fd for matching inode
+ */
+ sight_udpconn_set_pid(_E, conn, pid);
+
+ switch (state) {
+ case TCP_ESTABLISHED:
+ sight_tcpconn_set_state(_E, conn, 1);
+ break;
+ default:
+ sight_tcpconn_set_state(_E, conn, 0);
+ break;
+ }
+
+ la = sight_new_netaddr_class(_E, _O);
+ sight_netaddr_set_addr(_E, la, las);
+ sight_netaddr_set_port(_E, la, lp);
+ sight_udpconn_set_local(_E, conn, la);
+ (*_E)->DeleteLocalRef(_E, la);
+
+ ra = sight_new_netaddr_class(_E, _O);
+ sight_netaddr_set_addr(_E, ra, ras);
+ sight_netaddr_set_port(_E, ra, rp);
+ sight_udpconn_set_remote(_E, conn, ra);
+ (*_E)->DeleteLocalRef(_E, ra);
+ /* Increment the index counter */
+ e->idx++;
+
}
-/* Close TCP conn enumeration */
+/* Close UDP conn enumeration */
SIGHT_EXPORT_DECLARE(void, UdpStatistics, enum3)(SIGHT_STDARGS,
jlong handle)
{
+ udpconn_enum_t *e = J2P(handle, udpconn_enum_t *);
+
UNREFERENCED_STDARGS;
+ if (e) {
+ sight_arr_free(e->tnet);
+ free(e);
+ }
}
17 years, 4 months