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)