Author: jfrederic.clere(a)jboss.com
Date: 2007-10-17 10:17:14 -0400 (Wed, 17 Oct 2007)
New Revision: 1123
Modified:
trunk/sight/native/os/solaris/udpstat.c
Log:
Add the logic for udp entries.
Modified: trunk/sight/native/os/solaris/udpstat.c
===================================================================
--- trunk/sight/native/os/solaris/udpstat.c 2007-10-17 14:08:40 UTC (rev 1122)
+++ trunk/sight/native/os/solaris/udpstat.c 2007-10-17 14:17:14 UTC (rev 1123)
@@ -107,11 +107,19 @@
static const char *eiftype = "Unsupported NetworkAddressFamily type";
-/* Initialize volume enumeration */
-SIGHT_EXPORT_DECLARE(void, UdpStatistics, info0)(SIGHT_STDARGS,
- jobject thiz,
- jint iftype,
- jlong pool)
+extern apr_pool_t *sight_temp_pool;
+
+typedef struct tcpconn_enum_t {
+ int type;
+ int idx;
+ int numcons;
+ void *conn; /* mib2_tcp6ConnEntry_t / mib2_tcpConnEntry_t */
+ void *stat; /* mib2_tcp_t */
+ apr_pool_t *pool;
+} tcpconn_enum_t;
+
+/* Read the mib2 object and fill the structures */
+static void read_mib2(JNIEnv *_E, tcpconn_enum_t *e)
{
apr_status_t rc = APR_ENOTIMPL;
int sd;
@@ -119,17 +127,23 @@
int flags;
int i, j, getcode;
struct strbuf ctlbuf, databuf;
+
struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf;
struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf;
struct T_error_ack *tea = (struct T_error_ack *)buf;
+
struct opthdr *req;
- mib_item_t *last_item = NULL;
+ int numcons = 0;
- UNREFERENCED_O;
-
- if ((sd = open("/dev/udp", O_RDWR)) < 0) {
+ if ((sd = open("/dev/arp", O_RDWR)) < 0) {
throwAprException(_E, apr_get_os_error());
+ return;
}
+ if (ioctl(sd, I_PUSH, "udp") <0) {
+ close(sd);
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
tor->PRIM_type = T_SVR4_OPTMGMT_REQ;
tor->OPT_offset = sizeof (struct T_optmgmt_req);
@@ -146,76 +160,137 @@
if (putmsg(sd, &ctlbuf, (struct strbuf *)0, flags) == -1) {
close(sd);
throwAprException(_E, apr_get_os_error());
+ return;
}
- req = (struct opthdr *)&toa[1];
- ctlbuf.maxlen = sizeof (buf);
- flags = 0;
- if (getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags) == -1) {
- close(sd);
- throwAprException(_E, apr_get_os_error());
- }
+ for(;;) {
+ req = (struct opthdr *)&toa[1];
+ ctlbuf.buf = (char *) buf;
+ ctlbuf.maxlen = sizeof (buf);
+ flags = 0;
+ if (getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags) == -1) {
+ close(sd);
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
+ if (toa->PRIM_type == T_OPTMGMT_ACK &&
+ toa->MGMT_flags == T_SUCCESS &&
+ req->len == 0)
+ break; /* done */
- last_item = (mib_item_t *)malloc(sizeof (mib_item_t));;
- last_item->next_item = NULL;
- last_item->group = req->level;
- last_item->mib_id = req->name;
- last_item->length = req->len;
- last_item->valp = malloc((int)req->len);
+ /* read the data */
+ databuf.maxlen = req->len;
+ databuf.buf = malloc((int)req->len);
+ databuf.len = 0;
+ flags = 0;
+ if (getmsg(sd, (struct strbuf *)0, &databuf, &flags) == -1) {
+ close(sd);
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
- databuf.maxlen = last_item->length;
- databuf.buf = (char *)last_item->valp;
- databuf.len = 0;
- flags = 0;
- if (getmsg(sd, (struct strbuf *)0, &databuf, &flags) == -1) {
- close(sd);
- throwAprException(_E, apr_get_os_error());
+ /* Process the TPC statics */
+ if ((req->level == MIB2_UDP && req->name == 0 && e->type
== 1) ||
+ (req->level == MIB2_UDP6 && req->name == 0 &&
e->type == 2)) {
+ e->stat = (void *) databuf.buf;
+ } else if (req->level == MIB2_UDP && req->name == MIB2_UDP_ENTRY
&& e->type == 1) {
+ /* Process the UDP statics */
+ mib2_udpEntry *tcp = (mib2_udpEntry *)databuf.buf;
+ char *end;
+ int numcons = 0;
+ end = (char*) tcp + databuf.len;
+ while ((char*) tcp < end) {
+ numcons++;
+ tcp++;
+ }
+ e->conn = (void *) databuf.buf;
+ e->numcons = numcons;
+ } else if (req->level == MIB2_UDP6 && req->name == MIB2_UDP6_ENTRY
&& e->type == 2) {
+ /* Process the UDP6 statics */
+ mib2_udp6Entry *tcp = (mib2_udp6Entry *)databuf.buf;
+ char *end;
+ int numcons = 0;
+ end = (char*) tcp + databuf.len;
+ while ((char*) tcp < end) {
+ numcons++;
+ tcp++;
+ }
+ e->conn = (void *) databuf.buf;
+ e->numcons = numcons;
+ } /* else {
+ printf("Missing logic info0: level %d name %d\n", req->level,
req->name);
+ } */
}
close(sd);
+}
- for (; last_item; last_item = last_item->next_item) {
- if (last_item->group == MIB2_UDP) {
- mib2_udp_t *udp = (mib2_udp_t *)last_item->valp;
- SET_IFIELD_I(0000, thiz, udp->udpInDatagrams);
- /* XXX: SET_IFIELD_I(0001, thiz, NoPorts); */
- SET_IFIELD_I(0002, thiz, udp->udpInErrors);
- SET_IFIELD_I(0003, thiz, udp->udpOutDatagrams);
- /* XXX: SET_IFIELD_I(0004, thiz, s.dwNumAddrs); */
+/* Initialize volume enumeration */
+SIGHT_EXPORT_DECLARE(void, UdpStatistics, info0)(SIGHT_STDARGS,
+ jobject thiz,
+ jint iftype,
+ jlong pool)
+{
+ tcpconn_enum_t *e;
+ if (!(e = (tcpconn_enum_t *)sight_calloc(_E,
+ sizeof(tcpconn_enum_t),
+ THROW_FMARK))) {
+ return;
+ }
+ e->type = iftype;
+ read_mib2(_E, e);
- }
+ if (e->stat != NULL) {
+ mib2_udp_t *udp = (mib2_udp_t *)e->stat;
+ SET_IFIELD_I(0000, thiz, udp->udpInDatagrams);
+ /* XXX: SET_IFIELD_I(0001, thiz, NoPorts); */
+ SET_IFIELD_I(0002, thiz, udp->udpInErrors);
+ SET_IFIELD_I(0003, thiz, udp->udpOutDatagrams);
+
}
+ SET_IFIELD_I(0004, thiz, e->numcons);
}
SIGHT_EXPORT_DECLARE(jlong, UdpStatistics, enum0)(SIGHT_STDARGS,
jint iftype,
jlong pool)
{
- apr_status_t rc = APR_ENOTIMPL;
+ tcpconn_enum_t *e;
+ apr_status_t rc;
+
UNREFERENCED_O;
- if (iftype == 1) {
- /* AF_INET */
- rc = 0;
+ if (iftype < 1 || iftype > 2) {
+ throwOSException(_E, eiftype);
+ return 0;
}
- else if (iftype == 2) {
- /* AF_INET6 */
- rc = 0;
+ if (!(e = (tcpconn_enum_t *)sight_calloc(_E,
+ sizeof(tcpconn_enum_t),
+ THROW_FMARK))) {
+ return 0;
}
- else {
- throwOSException(_E, eiftype);
+
+ if ((rc = sight_pool_create(&e->pool, NULL, sight_temp_pool, 0)) !=
APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ return 0;
}
- if (rc) {
- throwAprException(_E, APR_FROM_OS_ERROR(rc));
- return;
- }
+ e->type = iftype;
+ read_mib2(_E, e);
+
+ return P2J(e);
}
/* Get the number of entries */
SIGHT_EXPORT_DECLARE(jint, UdpStatistics, enum1)(SIGHT_STDARGS,
jlong handle)
{
+ tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
UNREFERENCED_STDARGS;
- return 0;
+ if (e) {
+ e->idx = 1;
+ return e->numcons;
+ } else {
+ return 0;
+ }
}
SIGHT_EXPORT_DECLARE(void, UdpStatistics, enum2)(SIGHT_STDARGS,
@@ -223,7 +298,58 @@
jint index,
jlong handle)
{
+ tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
+ char las[128] = "";
+ char ras[128] = "";
+ jobject la, ra;
+ jint lp = 0, rp = 0;
+ jint st;
+ if (!e)
+ return;
+ if (e->idx > e->numcons) {
+ return;
+ }
+ if (e->type == 1) {
+ mib2_udpEntry *tcp = (mib2_udpEntry *) e->conn;
+ int i;
+ for (i=1; i<e->idx; i++)
+ tcp++;
+ inet_ntop(AF_INET, &tcp->udpLocalAddress, las, 64);
+ inet_ntop(AF_INET, &tcp->udpEntryInfo.ue_RemoteAddress, ras, 64);
+ lp = tcp->udpLocalPort;
+ rp = tcp->udpEntryInfo.ue_RemotePort;
+ st = tcp->udpEntryInfo.ue_state;
+ } else {
+ mib2_udp6Entry_t *tcp = (mib2_udp6Entry_t *) e->conn;
+ int i;
+ for (i=1; i<e->idx; i++)
+ tcp++;
+ sight_inet_ntop6(tcp->udp6LocalAddress.s6_addr, las, 64);
+ sight_inet_ntop6(tcp->udp6EntryInfo.ue_RemoteAddress.s6_addr, ras, 64);
+ lp = tcp->udp6LocalPort;
+ rp = tcp->udp6EntryInfo.ue_RemotePort;
+ st = tcp->udp6EntryInfo.ue_state;
+ }
+ sight_tcpconn_set_tmo(_E, conn, 0);
+ sight_tcpconn_set_cts(_E, conn, 0);
+ sight_tcpconn_set_pid(_E, conn, 0);
+
+ sight_tcpconn_set_state(_E, conn, st);
+
+ 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);
+ (*_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_tcpconn_set_remote(_E, conn, ra);
+ (*_E)->DeleteLocalRef(_E, ra);
+
+ e->idx++;
}
/* Close TCP conn enumeration */