JBoss Native SVN: r1023 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-12 14:10:32 -0400 (Wed, 12 Sep 2007)
New Revision: 1023
Modified:
trunk/sight/native/os/linux/netadapter.c
trunk/sight/native/os/linux/network.c
trunk/sight/native/os/linux/tcpstat.c
trunk/sight/native/os/linux/udpstat.c
trunk/sight/native/os/linux/volume.c
Log:
Fix formating
Modified: trunk/sight/native/os/linux/netadapter.c
===================================================================
--- trunk/sight/native/os/linux/netadapter.c 2007-09-12 17:57:27 UTC (rev 1022)
+++ trunk/sight/native/os/linux/netadapter.c 2007-09-12 18:10:32 UTC (rev 1023)
@@ -189,7 +189,7 @@
for (i = 0; i < IFHWADDRLEN; i++) {
if (buf[i]) {
j = 1;
- break;
+ break;
}
}
if (!j)
@@ -212,7 +212,7 @@
memset(&ifi, 0, sizeof(struct ifreq));
strcpy(ifi.ifr_name, name);
- if (!ioctl(sd, SIOCGIFINDEX, (char *)&ifi))
+ if (!ioctl(sd, SIOCGIFINDEX, (char *)&ifi))
id->index = ifi.ifr_ifindex;
else
id->index = -1;
@@ -229,7 +229,7 @@
}
if ((id->flags & IFF_BROADCAST) &&
- !ioctl(sd, SIOCGIFBRDADDR, (char *)&ifi)) {
+ !ioctl(sd, SIOCGIFBRDADDR, (char *)&ifi)) {
sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
inet_ntop(AF_INET, &sa->sin_addr, id->badr, 64);
}
@@ -267,7 +267,7 @@
goto cleanup;
}
- ifc.ifc_buf = NULL;
+ ifc.ifc_buf = NULL;
if (ioctl(e->sd, SIOCGIFCONF, (char *)&ifc) < 0) {
throwAprException(_E, apr_get_os_error());
goto cleanup;
@@ -290,7 +290,7 @@
sa = (struct sockaddr_in *)&ifr->ifr_addr;
inet_ntop(AF_INET, &sa->sin_addr, las, 64);
ce = cache_add(e->ifc, ifr->ifr_name);
- if (!(id = (net_ifc_data_t *)ce->data)) {
+ if (!(id = (net_ifc_data_t *)ce->data)) {
if (!(id = (net_ifc_data_t *)sight_calloc(_E,
sizeof(net_ifc_data_t),
THROW_FMARK))) {
@@ -307,7 +307,7 @@
}
}
-
+
free(ifc.ifc_buf);
/* Add missing interfaces from /proc/net/dev */
if ((i4a = sight_arr_rload(PROC_NET_DEV)) != NULL) {
@@ -328,7 +328,7 @@
do_ifrec(id, e->sd, i4a->arr.ca[i]);
id->type = AF_INET;
ce->data = id;
- }
+ }
}
sight_arr_free(i4a);
}
@@ -375,7 +375,7 @@
}
else {
strcpy(id->ip6a, las);
- }
+ }
}
sight_arr_free(i6a);
}
@@ -419,7 +419,7 @@
/* TODO: Figure out the Description */
SET_IFIELD_S(0001, thiz, e->ifc->list[e->idx]->key);
SET_IFIELD_S(0002, thiz, e->ifc->list[e->idx]->key);
-
+
if (id->maca[0]) {
addr = sight_new_netaddr_class(_E, _O);
if (!addr || (*_E)->ExceptionCheck(_E))
@@ -442,7 +442,7 @@
/* Set adapter status */
if (id->flags & IFF_UP) {
CALL_METHOD1(0001, thiz, SIGHT_IFO_UP);
- }
+ }
else {
CALL_METHOD1(0001, thiz, SIGHT_IFO_DOWN);
}
@@ -466,7 +466,7 @@
if (id->mask[0])
sight_netaddr_set_mask(_E, addr, id->mask);
(*_E)->SetObjectArrayElement(_E, aarr, idx++, addr);
- (*_E)->DeleteLocalRef(_E, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
}
if (id->ip6a[0]) {
addr = sight_new_netaddr_class(_E, _O);
@@ -475,14 +475,14 @@
sight_netaddr_set_addr(_E, addr, id->ip6a);
sight_netaddr_set_family(_E, addr, AF_INET6);
(*_E)->SetObjectArrayElement(_E, aarr, idx++, addr);
- (*_E)->DeleteLocalRef(_E, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
}
SET_IFIELD_O(0006, thiz, aarr);
(*_E)->DeleteLocalRef(_E, aarr);
}
SET_IFIELD_I(0009, thiz, id->mtu);
-cleanup:
+cleanup:
e->idx++;
}
Modified: trunk/sight/native/os/linux/network.c
===================================================================
--- trunk/sight/native/os/linux/network.c 2007-09-12 17:57:27 UTC (rev 1022)
+++ trunk/sight/native/os/linux/network.c 2007-09-12 18:10:32 UTC (rev 1023)
@@ -85,7 +85,7 @@
char *pd;
jsize len = 0, idx = 0;
UNREFERENCED_O;
-
+
if (gethostname(buf, SIGHT_SBUFFER_LEN)) {
throwAprException(_E, apr_get_os_error());
return;
@@ -109,7 +109,7 @@
if (strstr(tdns->arr.ca[i], "nameserver")) {
len++;
}
- }
+ }
if (len) {
jobject addr;
jobjectArray aaddr;
@@ -129,10 +129,10 @@
(*_E)->SetObjectArrayElement(_E, aaddr, idx++, addr);
(*_E)->DeleteLocalRef(_E, addr);
}
- }
+ }
SET_IFIELD_O(0002, thiz, aaddr);
(*_E)->DeleteLocalRef(_E, aaddr);
- }
+ }
}
cleanup:
if (tdns)
Modified: trunk/sight/native/os/linux/tcpstat.c
===================================================================
--- trunk/sight/native/os/linux/tcpstat.c 2007-09-12 17:57:27 UTC (rev 1022)
+++ trunk/sight/native/os/linux/tcpstat.c 2007-09-12 18:10:32 UTC (rev 1023)
@@ -174,7 +174,7 @@
0,
0,
0,
- 0
+ 0
};
/* Initialize volume enumeration */
@@ -195,6 +195,7 @@
if (iftype == 1) {
if (!(tnet = sight_arr_rload(PROC_NET_FS "sockstat"))) {
throwAprException(_E, apr_get_os_error());
+ return;
}
for (i = 0; i < tnet->siz; i++) {
if (memcmp(tnet->arr.ca[i], "TCP: inuse ", 11) == 0) {
@@ -206,6 +207,7 @@
else if (iftype == 2) {
if (!(tnet = sight_arr_rload(PROC_NET_FS "sockstat6"))) {
throwAprException(_E, apr_get_os_error());
+ return;
}
for (i = 0; i < tnet->siz; i++) {
if (memcmp(tnet->arr.ca[i], "TCP6: inuse ", 12) == 0) {
@@ -222,6 +224,7 @@
if (!(tnet = sight_arr_rload(PROC_NET_FS "snmp"))) {
throwAprException(_E, apr_get_os_error());
+ return;
}
/* Get the information corresponding to the second entry Tcp: */
@@ -347,13 +350,13 @@
&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);
+ al = sscanf(las, "%X", &in4.s_addr);
if (al == 1)
inet_ntop(AF_INET, &in4, las, 64);
else
Modified: trunk/sight/native/os/linux/udpstat.c
===================================================================
--- trunk/sight/native/os/linux/udpstat.c 2007-09-12 17:57:27 UTC (rev 1022)
+++ trunk/sight/native/os/linux/udpstat.c 2007-09-12 18:10:32 UTC (rev 1023)
@@ -139,6 +139,7 @@
if (!(tnet = sight_arr_rload("/proc/net/snmp"))) {
throwAprException(_E, apr_get_os_error());
+ return;
}
/* Get the information corresponding to the second entry Tcp: */
@@ -254,13 +255,13 @@
&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);
+ al = sscanf(las, "%X", &in4.s_addr);
if (al == 1)
inet_ntop(AF_INET, &in4, las, 64);
else
@@ -309,7 +310,7 @@
sight_udpconn_set_cts(_E, conn, apr_time_as_msec(ctime));
}
sight_udpconn_set_pid(_E, conn, pid);
-
+
switch (state) {
case TCP_ESTABLISHED:
sight_tcpconn_set_state(_E, conn, 2);
Modified: trunk/sight/native/os/linux/volume.c
===================================================================
--- trunk/sight/native/os/linux/volume.c 2007-09-12 17:57:27 UTC (rev 1022)
+++ trunk/sight/native/os/linux/volume.c 2007-09-12 18:10:32 UTC (rev 1023)
@@ -207,9 +207,9 @@
int flags = 0;
int dtype = sight_get_fs_type(ent.mnt_type);
SET_IFIELD_S(0000, thiz, ent.mnt_fsname);
- SET_IFIELD_S(0002, thiz, ent.mnt_dir);
+ SET_IFIELD_S(0002, thiz, ent.mnt_dir);
CALL_METHOD1(0000, thiz, dtype);
-
+
if (!statvfs(ent.mnt_dir, &sv)) {
SET_IFIELD_I(0004, thiz, sv.f_bsize);
SET_IFIELD_J(0005, thiz, sv.f_frsize * sv.f_bavail);
@@ -221,30 +221,30 @@
if (hasmntopt(&ent, MNTOPT_RO))
flags |= SIGHT_READ_ONLY_VOLUME;
if (hasmntopt(&ent, MNTOPT_SUID))
- flags |= SIGHT_SUID_VOLUME;
+ flags |= SIGHT_SUID_VOLUME;
CALL_METHOD1(0001, thiz, flags);
switch (dtype) {
case SIGHT_FS_UNKNOWN:
- CALL_METHOD1(0002, thiz, SIGHT_DRIVE_UNKNOWN);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_UNKNOWN);
break;
case SIGHT_FS_ISO9660:
- CALL_METHOD1(0002, thiz, SIGHT_DRIVE_CDROM);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_CDROM);
break;
case SIGHT_FS_DEV:
case SIGHT_FS_PROC:
case SIGHT_FS_SYSFS:
case SIGHT_FS_TMPFS:
- CALL_METHOD1(0002, thiz, SIGHT_DRIVE_RAMDISK);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_RAMDISK);
break;
case SIGHT_FS_NFS:
case SIGHT_FS_RPC:
- CALL_METHOD1(0002, thiz, SIGHT_DRIVE_REMOTE);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_REMOTE);
break;
case SIGHT_FS_USBFS:
- CALL_METHOD1(0002, thiz, SIGHT_DRIVE_REMOVABLE);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_REMOVABLE);
break;
default:
- CALL_METHOD1(0002, thiz, SIGHT_DRIVE_FIXED);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_FIXED);
break;
}
17 years, 4 months
JBoss Native SVN: r1022 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-12 13:57:27 -0400 (Wed, 12 Sep 2007)
New Revision: 1022
Modified:
trunk/sight/native/os/linux/netadapter.c
Log:
Implement Linux NetworkAdapter - stage 3
Modified: trunk/sight/native/os/linux/netadapter.c
===================================================================
--- trunk/sight/native/os/linux/netadapter.c 2007-09-12 15:15:56 UTC (rev 1021)
+++ trunk/sight/native/os/linux/netadapter.c 2007-09-12 17:57:27 UTC (rev 1022)
@@ -149,11 +149,16 @@
int type;
int index;
int flags;
- char ip4a[128];
- char ip6a[128];
+ int mtu;
+ char ip4a[64];
+ char ip6a[64];
char maca[64];
char mask[64];
char badr[64];
+ char p4ds[64];
+ char s4ds[64];
+ char p6ds[64];
+ char s6ds[64];
} net_ifc_data_t;
typedef struct net_adapter_enum_t {
@@ -199,6 +204,40 @@
*sp++ = '\0';
}
+static void do_ifrec(net_ifc_data_t *id, int sd, const char *name)
+{
+ struct ifreq ifi;
+ struct sockaddr_in *sa;
+
+ memset(&ifi, 0, sizeof(struct ifreq));
+ strcpy(ifi.ifr_name, name);
+
+ if (!ioctl(sd, SIOCGIFINDEX, (char *)&ifi))
+ id->index = ifi.ifr_ifindex;
+ else
+ id->index = -1;
+
+ if (!ioctl(sd, SIOCGIFFLAGS, (char *)&ifi))
+ id->flags = ifi.ifr_flags;
+ /* Can we have IPV4 without MAC address ? */
+ if (!ioctl(sd, SIOCGIFHWADDR, (char *)&ifi))
+ make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
+
+ if (!ioctl(sd, SIOCGIFNETMASK, (char *)&ifi)) {
+ sa = (struct sockaddr_in *)&ifi.ifr_netmask;
+ inet_ntop(AF_INET, &sa->sin_addr, id->mask, 64);
+ }
+
+ if ((id->flags & IFF_BROADCAST) &&
+ !ioctl(sd, SIOCGIFBRDADDR, (char *)&ifi)) {
+ sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
+ inet_ntop(AF_INET, &sa->sin_addr, id->badr, 64);
+ }
+ if (!ioctl(sd, SIOCGIFMTU, (char *)&ifi))
+ id->mtu = ifi.ifr_mtu;
+}
+
+
SIGHT_EXPORT_DECLARE(jlong, NetworkAdapter, enum0)(SIGHT_STDARGS,
jlong pool)
{
@@ -247,54 +286,19 @@
cache_entry_t *ce;
char las[128] = "";
struct sockaddr_in *sa;
- printf("IPV4: %10s\n", ifr->ifr_name);
sa = (struct sockaddr_in *)&ifr->ifr_addr;
inet_ntop(AF_INET, &sa->sin_addr, las, 64);
ce = cache_add(e->ifc, ifr->ifr_name);
if (!(id = (net_ifc_data_t *)ce->data)) {
- struct ifreq ifi;
if (!(id = (net_ifc_data_t *)sight_calloc(_E,
sizeof(net_ifc_data_t),
THROW_FMARK))) {
free(ifc.ifc_buf);
goto cleanup;
}
- memset(&ifi, 0, sizeof(struct ifreq));
- strcpy(ifi.ifr_name, ifr->ifr_name);
-
- if (ioctl(e->sd, SIOCGIFINDEX, (char *)&ifi) < 0) {
- throwAprException(_E, apr_get_os_error());
- free(ifc.ifc_buf);
- free(id);
- goto cleanup;
- }
- id->index = ifi.ifr_ifindex;
-
- if (ioctl(e->sd, SIOCGIFFLAGS, (char *)&ifi) < 0) {
- throwAprException(_E, apr_get_os_error());
- free(ifc.ifc_buf);
- free(id);
- goto cleanup;
- }
- id->flags = ifi.ifr_flags;
+ do_ifrec(id, e->sd, ifr->ifr_name);
strcpy(id->ip4a, las);
-
- if (ioctl(e->sd, SIOCGIFHWADDR, (char *)&ifi) >= 0) {
- /* Can we have IPV4 without MAC address ? */
- make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
- }
-
- if (ioctl(e->sd, SIOCGIFNETMASK, (char *)&ifi) >= 0) {
- sa = (struct sockaddr_in *)&ifi.ifr_netmask;
- inet_ntop(AF_INET, &sa->sin_addr, id->mask, 64);
- }
-
- if ((id->flags & IFF_BROADCAST) &&
- ioctl(e->sd, SIOCGIFBRDADDR, (char *)&ifi) >= 0) {
- sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
- inet_ntop(AF_INET, &sa->sin_addr, id->badr, 64);
- }
id->type = AF_INET;
ce->data = id;
}
@@ -315,39 +319,14 @@
*pname = '\0';
ce = cache_add(e->ifc, i4a->arr.ca[i]);
if (!(id = (net_ifc_data_t *)ce->data)) {
- struct ifreq ifi;
- struct sockaddr_in *sa;
-
if (!(id = (net_ifc_data_t *)sight_calloc(_E,
sizeof(net_ifc_data_t),
THROW_FMARK))) {
sight_arr_free(i4a);
goto cleanup;
}
- strcpy(ifi.ifr_name, i4a->arr.ca[i]);
+ do_ifrec(id, e->sd, i4a->arr.ca[i]);
id->type = AF_INET;
- if (ioctl(e->sd, SIOCGIFINDEX, (char *)&ifi) >= 0)
- id->index = ifi.ifr_ifindex;
- else
- id->index = -1;
- if (ioctl(e->sd, SIOCGIFFLAGS, (char *)&ifi) >= 0)
- id->flags = ifi.ifr_flags;
-
- if (ioctl(e->sd, SIOCGIFHWADDR, (char *)&ifi) >= 0) {
- /* Can we have IPV4 without MAC address ? */
- make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
- }
-
- if (ioctl(e->sd, SIOCGIFNETMASK, (char *)&ifi) >= 0) {
- sa = (struct sockaddr_in *)&ifi.ifr_netmask;
- inet_ntop(AF_INET, &sa->sin_addr, id->mask, 64);
- }
-
- if ((id->flags & IFF_BROADCAST) &&
- ioctl(e->sd, SIOCGIFBRDADDR, (char *)&ifi) >= 0) {
- sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
- inet_ntop(AF_INET, &sa->sin_addr, id->badr, 64);
- }
ce->data = id;
}
}
@@ -365,6 +344,8 @@
al = sscanf(i6a->arr.ca[i],
"%32s %02x %02x %02x %02x %16s",
ias, &ifidx, &plen, &scope, &dads, ifi.ifr_name);
+ if (al != 6)
+ continue;
sight_hex2bin(ias, in6.s6_addr, 16);
sight_inet_ntop6(in6.s6_addr, las, 64);
ce = cache_add(e->ifc, ifi.ifr_name);
@@ -381,10 +362,12 @@
goto cleanup;
}
strcpy(id->ip6a, las);
- if (ioctl(e->sd, SIOCGIFHWADDR, (char *)&ifi) >= 0) {
+ if (!ioctl(e->sd, SIOCGIFHWADDR, (char *)&ifi)) {
make_mac(ifi.ifr_hwaddr.sa_data, las);
strcpy(id->maca, las);
}
+ if (!ioctl(e->sd, SIOCGIFMTU, (char *)&ifi))
+ id->mtu = ifi.ifr_mtu;
id->type = AF_INET6;
id->index = ifidx;
id->flags = IFF_UP;
@@ -434,8 +417,9 @@
id = (net_ifc_data_t *)e->ifc->list[e->idx]->data;
SET_IFIELD_S(0000, thiz, e->ifc->list[e->idx]->key);
/* TODO: Figure out the Description */
+ SET_IFIELD_S(0001, thiz, e->ifc->list[e->idx]->key);
SET_IFIELD_S(0002, thiz, e->ifc->list[e->idx]->key);
-
+
if (id->maca[0]) {
addr = sight_new_netaddr_class(_E, _O);
if (!addr || (*_E)->ExceptionCheck(_E))
@@ -496,6 +480,7 @@
SET_IFIELD_O(0006, thiz, aarr);
(*_E)->DeleteLocalRef(_E, aarr);
}
+ SET_IFIELD_I(0009, thiz, id->mtu);
cleanup:
e->idx++;
17 years, 4 months
JBoss Native SVN: r1021 - in trunk/sight/native: os/linux and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-12 11:15:56 -0400 (Wed, 12 Sep 2007)
New Revision: 1021
Modified:
trunk/sight/native/include/sight_types.h
trunk/sight/native/os/linux/netadapter.c
Log:
Implement Linux NetworkAdapter - stage 2
Modified: trunk/sight/native/include/sight_types.h
===================================================================
--- trunk/sight/native/include/sight_types.h 2007-09-11 17:18:14 UTC (rev 1020)
+++ trunk/sight/native/include/sight_types.h 2007-09-12 15:15:56 UTC (rev 1021)
@@ -216,7 +216,10 @@
#define SIGHT_TCP_TIME_WAIT 11
#define SIGHT_TCP_DELETE_TCB 12
+#define SIGHT_IFO_UP 1
+#define SIGHT_IFO_DOWN 2
+
#ifdef __cplusplus
}
#endif
Modified: trunk/sight/native/os/linux/netadapter.c
===================================================================
--- trunk/sight/native/os/linux/netadapter.c 2007-09-11 17:18:14 UTC (rev 1020)
+++ trunk/sight/native/os/linux/netadapter.c 2007-09-12 15:15:56 UTC (rev 1021)
@@ -143,9 +143,17 @@
}
#define PROC_INET6_FILE "/proc/net/if_inet6"
+#define PROC_NET_DEV "/proc/net/dev"
typedef struct net_ifc_data_t {
int type;
+ int index;
+ int flags;
+ char ip4a[128];
+ char ip6a[128];
+ char maca[64];
+ char mask[64];
+ char badr[64];
} net_ifc_data_t;
typedef struct net_adapter_enum_t {
@@ -159,19 +167,48 @@
{
net_ifc_data_t *d = (net_ifc_data_t *)data;
if (d) {
-
free(d);
}
}
+static char *hex_base = "0123456789abcdefx";
+
+static void make_mac(void *data, char *dest)
+{
+ int i, j = 0;
+ unsigned char buf[IFHWADDRLEN];
+ char *sp = dest;
+
+ memcpy(buf, data, IFHWADDRLEN);
+ *dest = '\0';
+ for (i = 0; i < IFHWADDRLEN; i++) {
+ if (buf[i]) {
+ j = 1;
+ break;
+ }
+ }
+ if (!j)
+ return;
+ for (i = 0; i < IFHWADDRLEN - 1; i++) {
+ *sp++ = hex_base[buf[i] >> 4];
+ *sp++ = hex_base[buf[i] & 0x0f];
+ *sp++ = ':';
+ }
+ *sp++ = hex_base[buf[i] >> 4];
+ *sp++ = hex_base[buf[i] & 0x0f];
+ *sp++ = '\0';
+}
+
SIGHT_EXPORT_DECLARE(jlong, NetworkAdapter, enum0)(SIGHT_STDARGS,
jlong pool)
{
net_adapter_enum_t *e;
- int i;
+ int i, j;
struct ifconf ifc;
struct ifreq *ifr;
sight_arr_t *i6a;
+ sight_arr_t *i4a;
+ net_ifc_data_t *id;
UNREFERENCED_O;
UNREFERENCED(pool);
@@ -190,6 +227,7 @@
throwAprException(_E, apr_get_os_error());
goto cleanup;
}
+
ifc.ifc_buf = NULL;
if (ioctl(e->sd, SIOCGIFCONF, (char *)&ifc) < 0) {
throwAprException(_E, apr_get_os_error());
@@ -207,47 +245,154 @@
ifr = ifc.ifc_req;
for (i = 0; i < ifc.ifc_len; i += sizeof(struct ifreq), ifr++) {
cache_entry_t *ce;
+ char las[128] = "";
+ struct sockaddr_in *sa;
+ printf("IPV4: %10s\n", ifr->ifr_name);
+
+ sa = (struct sockaddr_in *)&ifr->ifr_addr;
+ inet_ntop(AF_INET, &sa->sin_addr, las, 64);
ce = cache_add(e->ifc, ifr->ifr_name);
- if (!ce->data) {
- net_ifc_data_t *id;
+ if (!(id = (net_ifc_data_t *)ce->data)) {
+ struct ifreq ifi;
if (!(id = (net_ifc_data_t *)sight_calloc(_E,
sizeof(net_ifc_data_t),
THROW_FMARK))) {
free(ifc.ifc_buf);
goto cleanup;
}
+ memset(&ifi, 0, sizeof(struct ifreq));
+ strcpy(ifi.ifr_name, ifr->ifr_name);
+
+ if (ioctl(e->sd, SIOCGIFINDEX, (char *)&ifi) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ free(ifc.ifc_buf);
+ free(id);
+ goto cleanup;
+ }
+ id->index = ifi.ifr_ifindex;
+
+ if (ioctl(e->sd, SIOCGIFFLAGS, (char *)&ifi) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ free(ifc.ifc_buf);
+ free(id);
+ goto cleanup;
+ }
+ id->flags = ifi.ifr_flags;
+ strcpy(id->ip4a, las);
+
+ if (ioctl(e->sd, SIOCGIFHWADDR, (char *)&ifi) >= 0) {
+ /* Can we have IPV4 without MAC address ? */
+ make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
+ }
+
+ if (ioctl(e->sd, SIOCGIFNETMASK, (char *)&ifi) >= 0) {
+ sa = (struct sockaddr_in *)&ifi.ifr_netmask;
+ inet_ntop(AF_INET, &sa->sin_addr, id->mask, 64);
+ }
+
+ if ((id->flags & IFF_BROADCAST) &&
+ ioctl(e->sd, SIOCGIFBRDADDR, (char *)&ifi) >= 0) {
+ sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
+ inet_ntop(AF_INET, &sa->sin_addr, id->badr, 64);
+ }
id->type = AF_INET;
ce->data = id;
}
+ else {
+ strcpy(id->ip4a, las);
+ }
+
}
free(ifc.ifc_buf);
+ /* Add missing interfaces from /proc/net/dev */
+ if ((i4a = sight_arr_rload(PROC_NET_DEV)) != NULL) {
+ for (i = 2; i < i4a->siz; i++) {
+ cache_entry_t *ce;
+ char *pname;
+ if (!(pname = strchr(i4a->arr.ca[i], ':')))
+ continue;
+ *pname = '\0';
+ ce = cache_add(e->ifc, i4a->arr.ca[i]);
+ if (!(id = (net_ifc_data_t *)ce->data)) {
+ struct ifreq ifi;
+ struct sockaddr_in *sa;
+
+ if (!(id = (net_ifc_data_t *)sight_calloc(_E,
+ sizeof(net_ifc_data_t),
+ THROW_FMARK))) {
+ sight_arr_free(i4a);
+ goto cleanup;
+ }
+ strcpy(ifi.ifr_name, i4a->arr.ca[i]);
+ id->type = AF_INET;
+ if (ioctl(e->sd, SIOCGIFINDEX, (char *)&ifi) >= 0)
+ id->index = ifi.ifr_ifindex;
+ else
+ id->index = -1;
+ if (ioctl(e->sd, SIOCGIFFLAGS, (char *)&ifi) >= 0)
+ id->flags = ifi.ifr_flags;
+
+ if (ioctl(e->sd, SIOCGIFHWADDR, (char *)&ifi) >= 0) {
+ /* Can we have IPV4 without MAC address ? */
+ make_mac(ifi.ifr_hwaddr.sa_data, id->maca);
+ }
+
+ if (ioctl(e->sd, SIOCGIFNETMASK, (char *)&ifi) >= 0) {
+ sa = (struct sockaddr_in *)&ifi.ifr_netmask;
+ inet_ntop(AF_INET, &sa->sin_addr, id->mask, 64);
+ }
+
+ if ((id->flags & IFF_BROADCAST) &&
+ ioctl(e->sd, SIOCGIFBRDADDR, (char *)&ifi) >= 0) {
+ sa = (struct sockaddr_in *)&ifi.ifr_broadaddr;
+ inet_ntop(AF_INET, &sa->sin_addr, id->badr, 64);
+ }
+ ce->data = id;
+ }
+ }
+ sight_arr_free(i4a);
+ }
/* Now add IPV6 entries */
if ((i6a = sight_arr_rload(PROC_INET6_FILE)) != NULL) {
for (i = 0; i < i6a->siz; i++) {
cache_entry_t *ce;
+ struct ifreq ifi;
int al, plen, scope, dads, ifidx;
- char name[20];
+ char ias[64];
+ char las[128] = "";
struct in6_addr in6;
-
al = sscanf(i6a->arr.ca[i],
- "%08X%08X%08X%08X %02x %02x %02x %02x %20s",
- &in6.s6_addr32[0], &in6.s6_addr32[1],
- &in6.s6_addr32[2], &in6.s6_addr32[3],
- &ifidx, &plen, &scope, &dads, &name);
-
- ce = cache_add(e->ifc, name);
- if (!ce->data) {
- net_ifc_data_t *id;
+ "%32s %02x %02x %02x %02x %16s",
+ ias, &ifidx, &plen, &scope, &dads, ifi.ifr_name);
+ sight_hex2bin(ias, in6.s6_addr, 16);
+ sight_inet_ntop6(in6.s6_addr, las, 64);
+ ce = cache_add(e->ifc, ifi.ifr_name);
+ if (plen) {
+ char buf[32];
+ sprintf(buf, "/%d", plen);
+ strcat(las, buf);
+ }
+ if (!(id = (net_ifc_data_t *)ce->data)) {
if (!(id = (net_ifc_data_t *)sight_calloc(_E,
sizeof(net_ifc_data_t),
THROW_FMARK))) {
sight_arr_free(i6a);
goto cleanup;
}
- id->type = AF_INET6;
- ce->data = id;
- }
+ strcpy(id->ip6a, las);
+ if (ioctl(e->sd, SIOCGIFHWADDR, (char *)&ifi) >= 0) {
+ make_mac(ifi.ifr_hwaddr.sa_data, las);
+ strcpy(id->maca, las);
+ }
+ id->type = AF_INET6;
+ id->index = ifidx;
+ id->flags = IFF_UP;
+ ce->data = id;
+ }
+ else {
+ strcpy(id->ip6a, las);
+ }
}
sight_arr_free(i6a);
}
@@ -279,6 +424,9 @@
{
net_adapter_enum_t *e = J2P(handle, net_adapter_enum_t *);
net_ifc_data_t *id;
+ jobject addr;
+ jobjectArray aarr;
+ jint len, idx;
UNREFERENCED_O;
if (!e || e->idx > e->ifc->siz)
@@ -287,6 +435,69 @@
SET_IFIELD_S(0000, thiz, e->ifc->list[e->idx]->key);
/* TODO: Figure out the Description */
SET_IFIELD_S(0002, thiz, e->ifc->list[e->idx]->key);
+
+ if (id->maca[0]) {
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E))
+ return;
+ sight_netaddr_set_addr(_E, addr, id->maca);
+ sight_netaddr_set_family(_E, addr, AF_HARDWARE);
+ SET_IFIELD_O(0003, thiz, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ /* Set adapter type */
+ if (id->flags & IFF_LOOPBACK) {
+ CALL_METHOD1(0000, thiz, IF_TYPE_SOFTWARE_LOOPBACK);
+ }
+ else if (id->flags & IFF_POINTOPOINT) {
+ CALL_METHOD1(0000, thiz, IF_TYPE_PPP);
+ }
+ else {
+ CALL_METHOD1(0000, thiz, IF_TYPE_ETHERNET_CSMACD);
+ }
+ /* Set adapter status */
+ if (id->flags & IFF_UP) {
+ CALL_METHOD1(0001, thiz, SIGHT_IFO_UP);
+ }
+ else {
+ CALL_METHOD1(0001, thiz, SIGHT_IFO_DOWN);
+ }
+ /* Set IP addresses */
+ len = 0;
+ if (id->ip4a[0])
+ len++;
+ if (id->ip6a[0])
+ len++;
+ if (len) {
+ idx = 0;
+ aarr = sight_new_netaddr_array(_E, _O, len);
+ if (!aarr || (*_E)->ExceptionCheck(_E))
+ goto cleanup;
+ if (id->ip4a[0]) {
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E))
+ return;
+ sight_netaddr_set_addr(_E, addr, id->ip4a);
+ sight_netaddr_set_family(_E, addr, AF_INET);
+ if (id->mask[0])
+ sight_netaddr_set_mask(_E, addr, id->mask);
+ (*_E)->SetObjectArrayElement(_E, aarr, idx++, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ if (id->ip6a[0]) {
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E))
+ return;
+ sight_netaddr_set_addr(_E, addr, id->ip6a);
+ sight_netaddr_set_family(_E, addr, AF_INET6);
+ (*_E)->SetObjectArrayElement(_E, aarr, idx++, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ SET_IFIELD_O(0006, thiz, aarr);
+ (*_E)->DeleteLocalRef(_E, aarr);
+ }
+
+cleanup:
e->idx++;
}
17 years, 4 months
JBoss Native SVN: r1020 - in trunk/sight/native: share and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-11 13:18:14 -0400 (Tue, 11 Sep 2007)
New Revision: 1020
Modified:
trunk/sight/native/os/linux/netadapter.c
trunk/sight/native/share/cache.c
Log:
Implement Linux NetworkAdapter - stage 1
Modified: trunk/sight/native/os/linux/netadapter.c
===================================================================
--- trunk/sight/native/os/linux/netadapter.c 2007-09-11 14:32:36 UTC (rev 1019)
+++ trunk/sight/native/os/linux/netadapter.c 2007-09-11 17:18:14 UTC (rev 1020)
@@ -30,6 +30,11 @@
#include "sight_types.h"
#include "sight_private.h"
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <sys/ioctl.h>
+
+
/*
* Network adapter implementation
*/
@@ -137,33 +142,163 @@
sight_unload_class(_E, &_clazzn);
}
+#define PROC_INET6_FILE "/proc/net/if_inet6"
+
+typedef struct net_ifc_data_t {
+ int type;
+} net_ifc_data_t;
+
+typedef struct net_adapter_enum_t {
+ int sd;
+ int idx;
+ cache_table_t *ifc;
+} net_adapter_enum_t;
+
+
+static void c_destroy(const char *key, void *data)
+{
+ net_ifc_data_t *d = (net_ifc_data_t *)data;
+ if (d) {
+
+ free(d);
+ }
+}
+
SIGHT_EXPORT_DECLARE(jlong, NetworkAdapter, enum0)(SIGHT_STDARGS,
jlong pool)
{
- UNREFERENCED_STDARGS;
+ net_adapter_enum_t *e;
+ int i;
+ struct ifconf ifc;
+ struct ifreq *ifr;
+ sight_arr_t *i6a;
+
+ UNREFERENCED_O;
UNREFERENCED(pool);
+ if (!(e = (net_adapter_enum_t *)sight_calloc(_E,
+ sizeof(net_adapter_enum_t),
+ THROW_FMARK))) {
+ return 0;
+ }
+ if (!(e->ifc = cache_new(16))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ free(e);
+ return 0;
+ }
+ if ((e->sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+ ifc.ifc_buf = NULL;
+ if (ioctl(e->sd, SIOCGIFCONF, (char *)&ifc) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+ if (!(ifc.ifc_buf = sight_calloc(_E, ifc.ifc_len, THROW_FMARK))) {
+ goto cleanup;
+ }
+ if (ioctl(e->sd, SIOCGIFCONF, (char *)&ifc) < 0) {
+ throwAprException(_E, apr_get_os_error());
+ free(ifc.ifc_buf);
+ goto cleanup;
+ }
+ /* Add interfaces to the cache */
+ ifr = ifc.ifc_req;
+ for (i = 0; i < ifc.ifc_len; i += sizeof(struct ifreq), ifr++) {
+ cache_entry_t *ce;
+ ce = cache_add(e->ifc, ifr->ifr_name);
+ if (!ce->data) {
+ net_ifc_data_t *id;
+ if (!(id = (net_ifc_data_t *)sight_calloc(_E,
+ sizeof(net_ifc_data_t),
+ THROW_FMARK))) {
+ free(ifc.ifc_buf);
+ goto cleanup;
+ }
+ id->type = AF_INET;
+ ce->data = id;
+ }
+ }
+
+ free(ifc.ifc_buf);
+ /* Now add IPV6 entries */
+ if ((i6a = sight_arr_rload(PROC_INET6_FILE)) != NULL) {
+ for (i = 0; i < i6a->siz; i++) {
+ cache_entry_t *ce;
+ int al, plen, scope, dads, ifidx;
+ char name[20];
+ struct in6_addr in6;
+
+ al = sscanf(i6a->arr.ca[i],
+ "%08X%08X%08X%08X %02x %02x %02x %02x %20s",
+ &in6.s6_addr32[0], &in6.s6_addr32[1],
+ &in6.s6_addr32[2], &in6.s6_addr32[3],
+ &ifidx, &plen, &scope, &dads, &name);
+
+ ce = cache_add(e->ifc, name);
+ if (!ce->data) {
+ net_ifc_data_t *id;
+ if (!(id = (net_ifc_data_t *)sight_calloc(_E,
+ sizeof(net_ifc_data_t),
+ THROW_FMARK))) {
+ sight_arr_free(i6a);
+ goto cleanup;
+ }
+ id->type = AF_INET6;
+ ce->data = id;
+ }
+ }
+ sight_arr_free(i6a);
+ }
+ return P2J(e);
+
+cleanup:
+ if (e->sd >= 0)
+ close(e->sd);
+ cache_free(e->ifc, c_destroy);
+ free(e);
return 0;
}
SIGHT_EXPORT_DECLARE(jint, NetworkAdapter, enum1)(SIGHT_STDARGS,
jlong handle)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(handle);
- return 0;
+ net_adapter_enum_t *e = J2P(handle, net_adapter_enum_t *);
+
+ UNREFERENCED_O;
+ if (!e)
+ return 0;
+ else
+ return e->ifc->siz;
}
SIGHT_EXPORT_DECLARE(void, NetworkAdapter, enum2)(SIGHT_STDARGS,
jobject thiz,
jlong handle)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(handle);
+ net_adapter_enum_t *e = J2P(handle, net_adapter_enum_t *);
+ net_ifc_data_t *id;
+
+ UNREFERENCED_O;
+ if (!e || e->idx > e->ifc->siz)
+ return;
+ id = (net_ifc_data_t *)e->ifc->list[e->idx]->data;
+ SET_IFIELD_S(0000, thiz, e->ifc->list[e->idx]->key);
+ /* TODO: Figure out the Description */
+ SET_IFIELD_S(0002, thiz, e->ifc->list[e->idx]->key);
+ e->idx++;
}
SIGHT_EXPORT_DECLARE(void, NetworkAdapter, enum3)(SIGHT_STDARGS,
jlong handle)
{
+ net_adapter_enum_t *e = J2P(handle, net_adapter_enum_t *);
+
UNREFERENCED_STDARGS;
- UNREFERENCED(handle);
+ if (e) {
+ close(e->sd);
+ cache_free(e->ifc, c_destroy);
+ free(e);
+ }
}
Modified: trunk/sight/native/share/cache.c
===================================================================
--- trunk/sight/native/share/cache.c 2007-09-11 14:32:36 UTC (rev 1019)
+++ trunk/sight/native/share/cache.c 2007-09-11 17:18:14 UTC (rev 1020)
@@ -41,7 +41,7 @@
cache_table_t *cache_new(size_t init)
{
- cache_table_t *t = (cache_table_t *)malloc(sizeof(cache_table_t));
+ cache_table_t *t = (cache_table_t *)calloc(1, sizeof(cache_table_t));
if (!t)
return NULL;
t->siz = 0;
17 years, 4 months
JBoss Native SVN: r1019 - trunk/sight/native/os/posix.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-11 10:32:36 -0400 (Tue, 11 Sep 2007)
New Revision: 1019
Modified:
trunk/sight/native/os/posix/user.c
Log:
Implement Posix who
Modified: trunk/sight/native/os/posix/user.c
===================================================================
--- trunk/sight/native/os/posix/user.c 2007-09-11 06:50:09 UTC (rev 1018)
+++ trunk/sight/native/os/posix/user.c 2007-09-11 14:32:36 UTC (rev 1019)
@@ -35,6 +35,20 @@
#include "sight_types.h"
#include "sight_private.h"
+#if defined(_sun)
+#include <utmpx.h>
+#define SIGHT_UTMP_FILE _UTMPX_FILE
+#define u_time ut_tv.tv_sec
+#else
+#include <utmp.h>
+#ifdef UTMP_FILE
+#define SIGHT_UTMP_FILE UTMP_FILE
+#else
+#define SIGHT_UTMP_FILE _PATH_UTMP
+#endif
+#endif
+
+
static const char etc_usr[] = "/etc/passwd";
/*
@@ -236,7 +250,100 @@
SIGHT_EXPORT_DECLARE(jobjectArray, User, who0)(SIGHT_STDARGS)
{
+ FILE *fu;
+#if defined(_sun)
+ struct futmpx su;
+#else
+ struct utmp su;
+#endif
+ jsize i, j, nusers = 0;
+ jobjectArray users = NULL;
+ cache_table_t *tuc;
+ cache_entry_t *e;
+ sight_arr_t *tusr = NULL;
- UNREFERENCED_STDARGS;
- return NULL;
+
+ UNREFERENCED_O;
+ if (!(tuc = cache_new(16))) {
+ return NULL;
+ }
+ if (!(tusr = sight_arr_cload(etc_usr, "#"))) {
+ goto cleanup;
+ }
+ if (!(fu = fopen(SIGHT_UTMP_FILE, "r"))) {
+ goto cleanup;
+ }
+ /* Read the user sessions */
+ while (fread(&su, sizeof(su), 1, fu)) {
+ if (!*su.ut_name)
+ continue;
+#ifdef USER_PROCESS
+ if (su.ut_type != USER_PROCESS)
+ continue;
+#endif
+ e = cache_add(tuc, su.ut_name);
+ }
+ fclose(fu);
+ if ((nusers = tuc->siz) > 0)
+ users = (*_E)->NewObjectArray(_E, nusers, _clazzn.a, NULL);
+ if (!users) {
+ goto cleanup;
+ }
+ for (j = 0; j < nusers; j++) {
+ jobject u;
+ posix_user_t *nu;
+ if (!(nu = (posix_user_t *)sight_malloc(_E,
+ sizeof(posix_user_t),
+ THROW_FMARK))) {
+ users = NULL;
+ goto cleanup;
+ }
+ nu->uid = -1;
+ nu->gid = -1;
+ if (!(u = new_user_class(_E, _O, P2J(nu)))) {
+ free(nu);
+ users = NULL;
+ goto cleanup;
+ }
+
+ for (i = 0; i < tusr->siz; i++) {
+ int uid;
+ char *uname;
+ char *token;
+ char *titer;
+
+ /* 1. UserName */
+ uname = sight_strtok_c(tusr->arr.ca[i], ':', &titer);
+ if (strcmp(uname, tuc->list[j]->key)) {
+ continue;
+ }
+ else {
+ /* 2. Password */
+ token = sight_strtok_c(NULL, ':', &titer);
+ /* 3. UID */
+ token = sight_strtok_c(NULL, ':', &titer);
+ nu->uid = sight_strtoi32(token);
+ SET_IFIELD_S(0000, u, uname);
+ SET_IFIELD_J(0003, u, (jlong) nu->uid);
+ /* 4. GID */
+ token = sight_strtok_c(NULL, ':', &titer);
+ nu->gid = sight_strtoi32(token);
+ /* 5. FullName */
+ token = sight_strtok_c(NULL, ':', &titer);
+ SET_IFIELD_N(0001, u, token);
+ /* 6. Home */
+ token = sight_strtok_c(NULL, ':', &titer);
+ SET_IFIELD_N(0004, u, token);
+ break;
+ }
+ }
+ (*_E)->SetObjectArrayElement(_E, users, j, u);
+ (*_E)->DeleteLocalRef(_E, u);
+ }
+
+cleanup:
+ if (tusr)
+ sight_arr_free(tusr);
+ cache_free(tuc, NULL);
+ return users;
}
17 years, 4 months
JBoss Native SVN: r1018 - in trunk/sight/native/os: solaris and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-11 02:50:09 -0400 (Tue, 11 Sep 2007)
New Revision: 1018
Modified:
trunk/sight/native/os/linux/network.c
trunk/sight/native/os/solaris/network.c
trunk/sight/native/os/stubs/network.c
Log:
Implement Network for Linux
Modified: trunk/sight/native/os/linux/network.c
===================================================================
--- trunk/sight/native/os/linux/network.c 2007-09-10 16:41:08 UTC (rev 1017)
+++ trunk/sight/native/os/linux/network.c 2007-09-11 06:50:09 UTC (rev 1018)
@@ -74,19 +74,68 @@
sight_unload_class(_E, &_clazzn);
}
-/* From netaddr.c */
-extern jobject sight_new_netaddr_class1(SIGHT_STDARGS, jstring name, jboolean ipv6);
-extern jobject sight_new_netaddr_class2(SIGHT_STDARGS, jstring name, jboolean ipv6,
- jlong v1, jlong v2, jlong v3);
-extern jobjectArray sight_new_netaddr_array(SIGHT_STDARGS, jsize len);
-
SIGHT_EXPORT_DECLARE(void, Network, info0)(SIGHT_STDARGS,
jobject thiz,
jlong pool)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(thiz);
- UNREFERENCED(pool);
+ int i;
+ sight_arr_t *tdns;
+ char buf[SIGHT_SBUFFER_SIZ];
+ char *pd;
+ jsize len = 0, idx = 0;
+ UNREFERENCED_O;
+
+ if (gethostname(buf, SIGHT_SBUFFER_LEN)) {
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
+ if ((pd = strchr(buf, '.'))) {
+ *pd++ = '\0';
+ SET_IFIELD_S(0000, thiz, buf);
+ SET_IFIELD_S(0001, thiz, pd);
+ }
+ else {
+ /* Use domainname if hostname misses dot */
+ SET_IFIELD_S(0000, thiz, buf);
+ if (getdomainname(buf, SIGHT_SBUFFER_LEN)) {
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
+ SET_IFIELD_S(0001, thiz, buf);
+ }
+ if ((tdns = sight_arr_rload("/etc/resolv.conf"))) {
+ for (i = 0; i < tdns->siz; i++) {
+ if (strstr(tdns->arr.ca[i], "nameserver")) {
+ len++;
+ }
+ }
+ if (len) {
+ jobject addr;
+ jobjectArray aaddr;
+ aaddr = sight_new_netaddr_array(_E, _O, len);
+ if (!aaddr || (*_E)->ExceptionCheck(_E)) {
+ goto cleanup;
+ }
+ for (i = 0; i < tdns->siz; i++) {
+ if ((pd = strstr(tdns->arr.ca[i], "nameserver"))) {
+ pd += 10;
+ addr = sight_new_netaddr_class(_E, _O);
+ if (!addr || (*_E)->ExceptionCheck(_E)) {
+ goto cleanup;
+ }
+ sight_netaddr_set_addr(_E, addr, sight_trim(pd));
+ sight_netaddr_set_family(_E, addr, AF_INET);
+ (*_E)->SetObjectArrayElement(_E, aaddr, idx++, addr);
+ (*_E)->DeleteLocalRef(_E, addr);
+ }
+ }
+ SET_IFIELD_O(0002, thiz, aaddr);
+ (*_E)->DeleteLocalRef(_E, aaddr);
+ }
+ }
+cleanup:
+ if (tdns)
+ sight_arr_free(tdns);
}
Modified: trunk/sight/native/os/solaris/network.c
===================================================================
--- trunk/sight/native/os/solaris/network.c 2007-09-10 16:41:08 UTC (rev 1017)
+++ trunk/sight/native/os/solaris/network.c 2007-09-11 06:50:09 UTC (rev 1018)
@@ -74,12 +74,6 @@
sight_unload_class(_E, &_clazzn);
}
-/* From netaddr.c */
-extern jobject sight_new_netaddr_class1(SIGHT_STDARGS, jstring name, jboolean ipv6);
-extern jobject sight_new_netaddr_class2(SIGHT_STDARGS, jstring name, jboolean ipv6,
- jlong v1, jlong v2, jlong v3);
-extern jobjectArray sight_new_netaddr_array(SIGHT_STDARGS, jsize len);
-
SIGHT_EXPORT_DECLARE(void, Network, info0)(SIGHT_STDARGS,
jobject thiz,
jlong pool)
Modified: trunk/sight/native/os/stubs/network.c
===================================================================
--- trunk/sight/native/os/stubs/network.c 2007-09-10 16:41:08 UTC (rev 1017)
+++ trunk/sight/native/os/stubs/network.c 2007-09-11 06:50:09 UTC (rev 1018)
@@ -74,12 +74,6 @@
sight_unload_class(_E, &_clazzn);
}
-/* From netaddr.c */
-extern jobject sight_new_netaddr_class1(SIGHT_STDARGS, jstring name, jboolean ipv6);
-extern jobject sight_new_netaddr_class2(SIGHT_STDARGS, jstring name, jboolean ipv6,
- jlong v1, jlong v2, jlong v3);
-extern jobjectArray sight_new_netaddr_array(SIGHT_STDARGS, jsize len);
-
SIGHT_EXPORT_DECLARE(void, Network, info0)(SIGHT_STDARGS,
jobject thiz,
jlong pool)
17 years, 4 months
JBoss Native SVN: r1017 - trunk/sight/examples/org/jboss/sight.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 12:41:08 -0400 (Mon, 10 Sep 2007)
New Revision: 1017
Modified:
trunk/sight/examples/org/jboss/sight/ListProcesses.java
Log:
Opps. This was unintentional
Modified: trunk/sight/examples/org/jboss/sight/ListProcesses.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListProcesses.java 2007-09-10 16:37:51 UTC (rev 1016)
+++ trunk/sight/examples/org/jboss/sight/ListProcesses.java 2007-09-10 16:41:08 UTC (rev 1017)
@@ -38,7 +38,6 @@
public ListProcesses()
{
- Process x = null;
try {
for (Process p : Process.getProcesses()) {
User u = new User(p.UserId);
@@ -48,18 +47,7 @@
" User(" + u.Name + ") Group(" +
g.Name +")" + "\t " +
p.CurrentWorkingDirectory);
- if (p.Id == 380)
- x = p;
}
- Thread.sleep(10000);
- if (x != null) {
- int i = x.refresh();
- System.out.println("Process\t[" + x.Id + "] \t" +
- x.State + " : " + " " + i + " " + x.BaseName +
- "\t " +
- x.CurrentWorkingDirectory);
- }
-
} catch (Exception e) {
e.printStackTrace();
}
17 years, 4 months
JBoss Native SVN: r1016 - in trunk/sight: java/org/jboss/sight and 1 other directories.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 12:37:51 -0400 (Mon, 10 Sep 2007)
New Revision: 1016
Modified:
trunk/sight/examples/org/jboss/sight/ListProcesses.java
trunk/sight/java/org/jboss/sight/Process.java
trunk/sight/native/os/windows/process.c
Log:
Fix Process.refresh
Modified: trunk/sight/examples/org/jboss/sight/ListProcesses.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListProcesses.java 2007-09-10 12:49:34 UTC (rev 1015)
+++ trunk/sight/examples/org/jboss/sight/ListProcesses.java 2007-09-10 16:37:51 UTC (rev 1016)
@@ -38,6 +38,7 @@
public ListProcesses()
{
+ Process x = null;
try {
for (Process p : Process.getProcesses()) {
User u = new User(p.UserId);
@@ -47,7 +48,17 @@
" User(" + u.Name + ") Group(" +
g.Name +")" + "\t " +
p.CurrentWorkingDirectory);
+ if (p.Id == 380)
+ x = p;
}
+ Thread.sleep(10000);
+ if (x != null) {
+ int i = x.refresh();
+ System.out.println("Process\t[" + x.Id + "] \t" +
+ x.State + " : " + " " + i + " " + x.BaseName +
+ "\t " +
+ x.CurrentWorkingDirectory);
+ }
} catch (Exception e) {
e.printStackTrace();
Modified: trunk/sight/java/org/jboss/sight/Process.java
===================================================================
--- trunk/sight/java/org/jboss/sight/Process.java 2007-09-10 12:49:34 UTC (rev 1015)
+++ trunk/sight/java/org/jboss/sight/Process.java 2007-09-10 16:37:51 UTC (rev 1016)
@@ -159,6 +159,7 @@
if (allocated) {
// Only allocated processes can be refreshed.
clear();
+ State = ProcessState.DEAD;
return alloc0(this, INSTANCE, Id);
}
else
Modified: trunk/sight/native/os/windows/process.c
===================================================================
--- trunk/sight/native/os/windows/process.c 2007-09-10 12:49:34 UTC (rev 1015)
+++ trunk/sight/native/os/windows/process.c 2007-09-10 16:37:51 UTC (rev 1016)
@@ -387,6 +387,10 @@
no->clean = proc_cleanup;
#endif
if (!find_pe32(pid, &pe32)) {
+ /* System pids have low values */
+ if (pid > 10)
+ return APR_ENOENT;
+ // Check if this is needed at all.
lstrcpyW(pe32.szExeFile, L"Unknown");
}
else {
17 years, 4 months
JBoss Native SVN: r1015 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-10 08:49:34 -0400 (Mon, 10 Sep 2007)
New Revision: 1015
Modified:
trunk/sight/native/os/windows/netadapter.c
Log:
Mark ant IPV6 as net%d
Modified: trunk/sight/native/os/windows/netadapter.c
===================================================================
--- trunk/sight/native/os/windows/netadapter.c 2007-09-10 12:42:43 UTC (rev 1014)
+++ trunk/sight/native/os/windows/netadapter.c 2007-09-10 12:49:34 UTC (rev 1015)
@@ -370,6 +370,10 @@
sprintf(buf, "tun%d", e->devCounters[6]++);
SET_IFIELD_S(0000, thiz, buf);
}
+ else if (!e->pCurrent->IfIndex) {
+ sprintf(buf, "net%d", e->devCounters[5]++);
+ SET_IFIELD_S(0000, thiz, buf);
+ }
else
SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
}
17 years, 4 months
JBoss Native SVN: r1014 - 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 08:42:43 -0400 (Mon, 10 Sep 2007)
New Revision: 1014
Modified:
trunk/sight/examples/org/jboss/sight/ListAdapters.java
trunk/sight/native/os/windows/netadapter.c
Log:
Create pseduo interface names like in JDK
Modified: trunk/sight/examples/org/jboss/sight/ListAdapters.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListAdapters.java 2007-09-10 10:31:21 UTC (rev 1013)
+++ trunk/sight/examples/org/jboss/sight/ListAdapters.java 2007-09-10 12:42:43 UTC (rev 1014)
@@ -50,6 +50,7 @@
System.out.println("Adapters");
for (NetworkAdapter a : NetworkAdapter.getAdapters()) {
System.out.println("Adapter: " + a.FriendlyName);
+ System.out.println(" " + a.Name);
System.out.println(" " + a.Description);
System.out.println(" " + a.Type);
System.out.println(" " + a.OperationalStatus);
Modified: trunk/sight/native/os/windows/netadapter.c
===================================================================
--- trunk/sight/native/os/windows/netadapter.c 2007-09-10 10:31:21 UTC (rev 1013)
+++ trunk/sight/native/os/windows/netadapter.c 2007-09-10 12:42:43 UTC (rev 1014)
@@ -145,8 +145,71 @@
PIP_ADAPTER_ADDRESSES pCurrent;
PIP_ADAPTER_INFO pInfo;
PIP_ADAPTER_INFO pCurInfo;
+ int devCounters[8];
+ PMIB_IFTABLE pTable;
} net_adapter_enum_t;
+static int if_enum(SIGHT_STDARGS, net_adapter_enum_t *e)
+{
+ DWORD i, rc;
+ DWORD dwSize;
+
+ dwSize = sizeof(MIB_IFTABLE);
+ if (!(e->pTable = sight_calloc(_E, dwSize, THROW_FMARK)))
+ return errno;
+
+ rc = GetIfTable(e->pTable, &dwSize, TRUE);
+ if (rc == ERROR_INSUFFICIENT_BUFFER || rc == ERROR_BUFFER_OVERFLOW) {
+ free(e->pTable);
+ if (!(e->pTable = sight_calloc(_E, dwSize, THROW_FMARK)))
+ return errno;
+ rc = GetIfTable(e->pTable, &dwSize, TRUE);
+ }
+ for (i = 0; i < e->pTable->dwNumEntries; i++) {
+ switch (e->pTable->table[i].dwType) {
+ case MIB_IF_TYPE_ETHERNET:
+ swprintf(e->pTable->table[i].wszName, L"eth%d", e->devCounters[0]++);
+ break;
+ case MIB_IF_TYPE_TOKENRING:
+ swprintf(e->pTable->table[i].wszName, L"tr%d", e->devCounters[1]++);
+ break;
+ case MIB_IF_TYPE_FDDI:
+ swprintf(e->pTable->table[i].wszName, L"fddi%d", e->devCounters[2]++);
+ break;
+ case MIB_IF_TYPE_LOOPBACK:
+ /* There should only be only IPv4 loopback address */
+ if (e->devCounters[3]++ == 0)
+ lstrcpyW(e->pTable->table[i].wszName, L"lo");
+ else
+ continue;
+ break;
+ case MIB_IF_TYPE_PPP:
+ swprintf(e->pTable->table[i].wszName, L"ppp%d", e->devCounters[3]++);
+ break;
+ case MIB_IF_TYPE_SLIP:
+ swprintf(e->pTable->table[i].wszName, L"sl%d", e->devCounters[4]++);
+ break;
+ default:
+ swprintf(e->pTable->table[i].wszName, L"net%d", e->devCounters[5]++);
+ break;
+ }
+ }
+ return rc;
+}
+
+static int if_name(net_adapter_enum_t *e, PIP_ADAPTER_ADDRESSES a, LPWSTR dst)
+{
+ DWORD i;
+
+ for (i = 0; i < e->pTable->dwNumEntries; i++) {
+ if (e->pTable->table[i].dwIndex == a->IfIndex) {
+ lstrcpyW(dst, e->pTable->table[i].wszName);
+ return 1;
+ }
+ }
+ return 0;
+}
+
static jlong xp_enum0(SIGHT_STDARGS, jlong pool)
{
DWORD rc;
@@ -187,12 +250,14 @@
throwAprException(_E, APR_FROM_OS_ERROR(rc));
goto cleanup;
}
+ if (if_enum(_E, _O, e) != ERROR_SUCCESS)
+ goto cleanup;
e->pCurrent = e->pAddresses;
return P2J(e);
cleanup:
if (e) {
- if (e->pAddresses)
- free(e->pAddresses);
+ SIGHT_FREE(e->pAddresses);
+ SIGHT_FREE(e->pTable);
free(e);
}
return 0;
@@ -231,13 +296,16 @@
throwAprException(_E, APR_FROM_OS_ERROR(rc));
goto cleanup;
}
+ if (if_enum(_E, _O, e) != ERROR_SUCCESS)
+ goto cleanup;
+
e->pCurInfo = e->pInfo;
e->isInfo = 1;
return P2J(e);
cleanup:
if (e) {
- if (e->pInfo)
- free(e->pInfo);
+ SIGHT_FREE(e->pInfo);
+ SIGHT_FREE(e->pTable);
free(e);
}
return 0;
@@ -288,13 +356,23 @@
PIP_ADAPTER_DNS_SERVER_ADDRESS da;
jsize len, idx, i;
char buf[MAX_PATH] = {0};
+ WCHAR nname[32];
char *sp;
DWORD blen;
UNREFERENCED_O;
if (!e || !e->pCurrent)
return;
- SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
+ if (if_name(e, e->pCurrent, nname))
+ SET_IFIELD_W(0000, thiz, nname);
+ else {
+ if (e->pCurrent->IfType == IF_TYPE_TUNNEL) {
+ sprintf(buf, "tun%d", e->devCounters[6]++);
+ SET_IFIELD_S(0000, thiz, buf);
+ }
+ else
+ SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
+ }
SET_IFIELD_W(0001, thiz, e->pCurrent->Description);
SET_IFIELD_W(0002, thiz, e->pCurrent->FriendlyName);
CALL_METHOD1(0000, thiz, e->pCurrent->IfType);
@@ -480,13 +558,17 @@
PIP_ADDR_STRING ua;
PIP_ADDR_STRING da;
char buf[MAX_PATH];
+ WCHAR nname[32];
char *sp;
jsize len, idx, i;
UNREFERENCED_O;
if (!e || !e->pCurInfo)
return;
- SET_IFIELD_S(0000, thiz, e->pCurInfo->AdapterName);
+ if (if_name(e, e->pCurrent, nname))
+ SET_IFIELD_W(0000, thiz, nname);
+ else
+ SET_IFIELD_S(0000, thiz, e->pCurrent->AdapterName);
SET_IFIELD_S(0001, thiz, e->pCurInfo->Description);
SET_IFIELD_S(0002, thiz, e->pCurInfo->AdapterName);
CALL_METHOD1(0000, thiz, e->pCurInfo->Type);
@@ -652,10 +734,9 @@
UNREFERENCED_STDARGS;
if (e) {
- if (e->pAddresses)
- free(e->pAddresses);
- if (e->pInfo)
- free(e->pInfo);
+ SIGHT_FREE(e->pAddresses);
+ SIGHT_FREE(e->pInfo);
+ SIGHT_FREE(e->pTable);
free(e);
}
}
17 years, 4 months